master
Aevann1 2022-03-24 23:01:04 +02:00
parent 8d5fdf6c03
commit 7745adc475
2 changed files with 18 additions and 0 deletions

View File

@ -701,6 +701,8 @@ sub_regex = re.compile('(^|\s|<p>)\/?(h\/(\w|-){3,25})', flags=re.A)
youtube_regex = re.compile('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))</a>(?!</code>)', flags=re.A) youtube_regex = re.compile('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))</a>(?!</code>)', flags=re.A)
strikethrough_regex = re.compile('~{1,2}([^~]+)~{1,2}', flags=re.A) strikethrough_regex = re.compile('~{1,2}([^~]+)~{1,2}', flags=re.A)
mute_regex = re.compile("/mute @([a-z0-9_\-]{3,25}) ([0-9])+", flags=re.A)
emoji_regex = re.compile("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", flags=re.A) emoji_regex = re.compile("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", flags=re.A)
emoji_regex2 = re.compile('(?<!"):([!#A-Za-z0-9]{1,30}?):', flags=re.A) emoji_regex2 = re.compile('(?<!"):([!#A-Za-z0-9]{1,30}?):', flags=re.A)
emoji_regex3 = re.compile('(?<!#"):([!#A-Za-z0-9]{1,30}?):', flags=re.A) emoji_regex3 = re.compile('(?<!#"):([!#A-Za-z0-9]{1,30}?):', flags=re.A)

View File

@ -16,6 +16,7 @@ else:
typing = [] typing = []
online = [] online = []
muted = cache.get('muted') or {}
messages = cache.get('chat') or [] messages = cache.get('chat') or []
total = cache.get('total') or 0 total = cache.get('total') or 0
@ -37,6 +38,12 @@ def chatjs():
@auth_required @auth_required
def speak(data, v): def speak(data, v):
if v.is_banned: return '', 403 if v.is_banned: return '', 403
vname = v.username.lower()
if vname in muted:
if time.time() > muted[vname]: return '', 403
else: del muted[vname]
global messages, total global messages, total
text = data[:1000].strip() text = data[:1000].strip()
if not text: return '', 403 if not text: return '', 403
@ -55,6 +62,14 @@ def speak(data, v):
messages = messages[-50:] messages = messages[-50:]
total += 1 total += 1
emit('speak', data, broadcast=True) emit('speak', data, broadcast=True)
if v.admin_level > 1:
text = text.lower()
for i in mute_regex.finditer(text):
username = i.group(1)
duration = int(int(i.group(2)) * 60 + time.time())
muted[username] = duration
return '', 204 return '', 204
@socketio.on('connect') @socketio.on('connect')
@ -92,4 +107,5 @@ def typing_indicator(data, v):
def close_running_threads(): def close_running_threads():
cache.set('chat', messages) cache.set('chat', messages)
cache.set('total', total) cache.set('total', total)
cache.set('muted', muted)
atexit.register(close_running_threads) atexit.register(close_running_threads)