allow PCM chadmins to add or remove channels (#365)

* testing on devrama

* fix for devrama

* fix

* fix

* fix

* fix

* fix

* fix

* test

* fix

* test

* test

* commit
remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-09-22 23:40:32 +02:00 committed by GitHub
parent bf5abefc4c
commit 2ef91698f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 37 deletions

View File

@ -24,4 +24,5 @@ from .lottery import *
from .casino_game import *
from .hats import *
from .marsey import *
from .transactions import *
from .transactions import *
from .streamers import *

View File

@ -0,0 +1,13 @@
from files.helpers.const import SITE
if SITE == 'pcmemes.net':
from sqlalchemy import *
from files.__main__ import Base
class Streamer(Base):
__tablename__ = "streamers"
id = Column(String, primary_key=True)
def __repr__(self):
return f"<Streamer(id={self.id})>"

View File

@ -436,31 +436,8 @@ def donate(v):
return render_template(f'donate_{SITE_NAME}.html', v=v)
if SITE_NAME == 'PCM':
streamers = (
'UCJrqlqe8DBZsfdMu7gGrVRA',
'UCDDrY00FPYwLp9VqRhWiDgg',
'UCdBzv8yzRgvnxV1M95qOsNA',
'UCvRP7CKUHWTJamANqg8NCTQ',
'UCPtDuLhreIEcjJr7WWaNaUw',
'UCS8gM5S889oBPyN6K07ZC6A',
'UCUn24NHjc8asGiYet1P9h5Q',
'UCqdJpVkTPem_iKcoVqoZtAg',
'UCtcVe3ucfS-AZVcNc2GabPw',
'UCDk0PdOMRfknGhVE8R-S_DQ',
'UC0UFeYG5aSGZT2e8lOjQ7oA',
'UC1yC2i8t5ivhh5RsRpGWMlw',
'UCP_YnD-BO8ctnKgUW89Si6Q',
'UCoxFxZirbfLvy9tres71eSA',
'UClf1Wfw54YBjJNlX3NjSOPA',
'UC8X10knH1xD3PTeds8glyNw',
'UCgKTJAN-IrVyX-jIJ5INEhA',
'UCgjAbjJZgBCF3OVGkJV5kCw',
'UC7xWZT4HPMFYzFoijmH8POg',
'UCoBfUpZXvWjS995ZXCPxxVQ',
'UCoOh1fOZBN7uCc3qu-TTAJQ',
'UCo8wWQvRSoKL57vjv4vyXQw'
)
if SITE == 'pcmemes.net':
from files.classes.streamers import *
live_regex = re.compile('playerOverlayVideoDetailsRenderer":\{"title":\{"simpleText":"(.*?)"\},"subtitle":\{"runs":\[\{"text":"(.*?)"\},\{"text":""\},\{"text":"(.*?)"\}', flags=re.A)
live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A)
@ -470,6 +447,9 @@ if SITE_NAME == 'PCM':
def live_cached():
live = []
offline = []
db = db_session()
streamers = [x[0] for x in db.query(Streamer.id).all()]
db.close()
for x in streamers:
url = f'https://www.youtube.com/channel/{x}/live'
req = requests.get(url, cookies={'CONSENT': 'YES+1'}, proxies=proxies)
@ -479,12 +459,12 @@ if SITE_NAME == 'PCM':
y = live_regex.search(txt)
try:
count = int(y.group(3))
live.append((req.url, t.group(1), y.group(2), y.group(1), count))
live.append((x, req.url, t.group(1), y.group(2), y.group(1), count))
except:
offline.append((req.url.rstrip('/live'), t.group(1), y.group(2)))
offline.append((x, req.url.rstrip('/live'), t.group(1), y.group(2)))
else:
y = offline_regex.search(txt)
try: offline.append((req.url.rstrip('/live'), y.group(2), y.group(1)))
try: offline.append((x, req.url.rstrip('/live'), y.group(2), y.group(1)))
except: print(x)
live = sorted(live, key=lambda x: x[4], reverse=True)
@ -495,4 +475,32 @@ if SITE_NAME == 'PCM':
@app.get('/logged_out/live')
@auth_desired_with_logingate
def live(v):
return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1])
return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1])
@app.post('/live/add')
@admin_level_required(2)
def live_add(v):
id = request.values.get('id')
if not id: abort(400)
existing = g.db.get(Streamer, id)
if not existing:
streamer = Streamer(id=id)
g.db.add(streamer)
g.db.flush()
if v.id != KIPPY_ID:
send_repeatable_notification(KIPPY_ID, f"@{v.username} has added a [new YouTube channel](https://www.youtube.com/channel/{streamer.id})")
cache.delete_memoized(live_cached)
return redirect(f'/live')
@app.post('/live/remove')
@admin_level_required(2)
def live_remove(v):
id = request.values.get('id')
if not id: abort(400)
streamer = g.db.get(Streamer, id)
if streamer:
if v.id != KIPPY_ID:
send_repeatable_notification(KIPPY_ID, f"@{v.username} has removed a [YouTube channel](https://www.youtube.com/channel/{streamer.id})")
g.db.delete(streamer)
cache.delete_memoized(live_cached)
return redirect(f'/live')

View File

@ -13,17 +13,32 @@
border-radius: 4px;
}
</style>
<script>
function go_to(e, link) {
if (e.target.type != "submit")
window.open('{{link}}', '_blank');
}
</script>
<div class="px-2">
<h1 class="py-3"><i class="fas fa-circle mr-3" style="color:red"></i>Live</h1>
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<tbody>
{% for link, thumb, name, title, viewers in live %}
<tr onclick="window.open('{{link}}', '_blank')">
{% for id, link, thumb, name, title, viewers in live %}
<tr onclick="go_to(event,'{{link}}')">
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
<td>{{name}}</td>
<td>{{title}}</td>
<td>{{viewers}}</td>
{% if v and v.admin_level > 1 %}
<td>
<form action="/live/remove" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="id" value="{{id}}">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Remove Channel">
</form>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
@ -34,16 +49,34 @@
<div class="overflow-x-auto">
<table class="table table-striped mb-5">
<tbody>
{% for link, thumb, name in offline %}
<tr onclick="window.open('{{link}}', '_blank')">
{% for id, link, thumb, name in offline %}
<tr onclick="go_to(event,'{{link}}')">
<td width="48"><img class="thumb" src="{{thumb}}" alt="{{name}} thumbnail" referrerpolicy="no-referrer" width="48"></td>
<td>{{name}}</td>
<td></td>
<td></td>
{% if v and v.admin_level > 1 %}
<td>
<form action="/live/remove" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="id" value="{{id}}">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Remove Channel">
</form>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if v and v.admin_level > 1 %}
<form action="/live/add" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input class="form-control" style="display:inline;width:350px" autocomplete="off" type="text" name="id" class="form-control" placeholder="Enter channel id..">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Youtube Channel" style="margin-top:-5px">
</form>
<p class="mt-3">you can get the channel id using this site <a href="https://streamweasels.com/tools/youtube-channel-id-and-user-id-convertor" rel="nofollow noopener noreferrer" target="_blank">https://streamweasels.com/tools/youtube-channel-id-and-user-id-convertor</a></p>
{% endif %}
</div>
{% endblock %}

View File

@ -28,7 +28,7 @@
{% if v.mods(sub.name) %}
<form action="/h/{{sub}}/unexile/{{user.id}}" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Unexile">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Unexile">
</form>
{% endif %}
</td>

View File

@ -25,7 +25,7 @@
<form action="/h/{{sub}}/remove_mod" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="uid" value="{{user.id}}">
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="{% if v.id == user.id %}Resign{% else %}Remove Mod{% endif %}">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="{% if v.id == user.id %}Resign{% else %}Remove Mod{% endif %}">
</form>
{% endif %}
</td>
@ -38,7 +38,7 @@
<form action="/h/{{sub}}/add_mod" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input class="form-control" style="display:inline;width:250px" autocomplete="off" type="text" name="user" class="form-control" placeholder="Enter username..">
<input class="btn btn-primary" autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Mod">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" onclick="disable(this)" value="Add Mod">
</form>
{% endif %}