forked from rDrama/rDrama
add !everyone
parent
fdda74a008
commit
308bb03125
|
@ -4,6 +4,8 @@ from sys import stdout
|
||||||
import gevent
|
import gevent
|
||||||
from flask import g
|
from flask import g
|
||||||
from pywebpush import webpush
|
from pywebpush import webpush
|
||||||
|
import time
|
||||||
|
from sqlalchemy.sql import text
|
||||||
|
|
||||||
from files.classes import Comment, Notification, PushSubscription, Group
|
from files.classes import Comment, Notification, PushSubscription, Group
|
||||||
|
|
||||||
|
@ -128,18 +130,28 @@ def NOTIFY_USERS(text, v):
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
notify_users = set()
|
notify_users = set()
|
||||||
|
|
||||||
for word, id in NOTIFIED_USERS.items():
|
|
||||||
if word in text:
|
|
||||||
notify_users.add(id)
|
|
||||||
|
|
||||||
if FEATURES['PING_GROUPS']:
|
if FEATURES['PING_GROUPS']:
|
||||||
billed = set()
|
billed = set()
|
||||||
|
everyone = False
|
||||||
for i in group_mention_regex.finditer(text):
|
for i in group_mention_regex.finditer(text):
|
||||||
group = g.db.get(Group, i.group(2))
|
if i.group(2) == 'everyone' and not v.shadowbanned:
|
||||||
if group:
|
everyone = True
|
||||||
if v.id not in group.member_ids:
|
break
|
||||||
billed.update(group.member_ids)
|
else:
|
||||||
notify_users.update(group.member_ids)
|
group = g.db.get(Group, i.group(2))
|
||||||
|
if group:
|
||||||
|
if v.id not in group.member_ids:
|
||||||
|
billed.update(group.member_ids)
|
||||||
|
notify_users.update(group.member_ids)
|
||||||
|
|
||||||
|
if everyone:
|
||||||
|
cost = g.db.query(User).count() * 5
|
||||||
|
if cost > v.coins:
|
||||||
|
abort(403, f"You need {cost} coins for this!")
|
||||||
|
g.db.query(User).update({ User.coins: User.coins + 5 })
|
||||||
|
v.coins -= cost
|
||||||
|
g.db.add(v)
|
||||||
|
return 'everyone'
|
||||||
|
|
||||||
if billed:
|
if billed:
|
||||||
cost = len(billed) * 5
|
cost = len(billed) * 5
|
||||||
|
@ -149,6 +161,9 @@ def NOTIFY_USERS(text, v):
|
||||||
v.coins -= cost
|
v.coins -= cost
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
|
for word, id in NOTIFIED_USERS.items():
|
||||||
|
if word in text:
|
||||||
|
notify_users.add(id)
|
||||||
|
|
||||||
names = set(m.group(2) for m in mention_regex.finditer(text))
|
names = set(m.group(2) for m in mention_regex.finditer(text))
|
||||||
user_ids = get_users(names, ids_only=True, graceful=True)
|
user_ids = get_users(names, ids_only=True, graceful=True)
|
||||||
|
@ -200,3 +215,12 @@ def _push_notif_thread(subscriptions, title, body, url):
|
||||||
vapid_claims={"sub": f"mailto:{EMAIL}"}
|
vapid_claims={"sub": f"mailto:{EMAIL}"}
|
||||||
)
|
)
|
||||||
except: continue
|
except: continue
|
||||||
|
|
||||||
|
def alert_everyone(cid):
|
||||||
|
cid = int(cid)
|
||||||
|
t = int(time.time())
|
||||||
|
_everyone_query = text(f"""
|
||||||
|
insert into notifications
|
||||||
|
select id, {cid}, false, {t} from users
|
||||||
|
on conflict do nothing;""")
|
||||||
|
g.db.execute(_everyone_query)
|
||||||
|
|
|
@ -309,32 +309,35 @@ def comment(v:User):
|
||||||
if not v.shadowbanned:
|
if not v.shadowbanned:
|
||||||
notify_users = NOTIFY_USERS(body, v)
|
notify_users = NOTIFY_USERS(body, v)
|
||||||
|
|
||||||
push_notif(notify_users, f'New mention of you by @{c.author_name}', c.body, c)
|
if notify_users == 'everyone':
|
||||||
|
alert_everyone(c.id)
|
||||||
|
else:
|
||||||
|
push_notif(notify_users, f'New mention of you by @{c.author_name}', c.body, c)
|
||||||
|
|
||||||
if c.level == 1 and posting_to_submission:
|
if c.level == 1 and posting_to_submission:
|
||||||
subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.submission_id == post_target.id, Subscription.user_id != v.id).all()]
|
subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.submission_id == post_target.id, Subscription.user_id != v.id).all()]
|
||||||
|
|
||||||
notify_users.update(subscriber_ids)
|
notify_users.update(subscriber_ids)
|
||||||
|
|
||||||
push_notif(subscriber_ids, f'New comment in subscribed thread by @{c.author_name}', c.body, c)
|
push_notif(subscriber_ids, f'New comment in subscribed thread by @{c.author_name}', c.body, c)
|
||||||
|
|
||||||
if parent_user.id != v.id:
|
if parent_user.id != v.id:
|
||||||
notify_users.add(parent_user.id)
|
notify_users.add(parent_user.id)
|
||||||
|
|
||||||
for x in notify_users-bots:
|
for x in notify_users-bots:
|
||||||
n = Notification(comment_id=c.id, user_id=x)
|
n = Notification(comment_id=c.id, user_id=x)
|
||||||
g.db.add(n)
|
g.db.add(n)
|
||||||
|
|
||||||
if parent_user.id != v.id and not v.shadowbanned:
|
if parent_user.id != v.id and not v.shadowbanned:
|
||||||
if isinstance(parent, User):
|
if isinstance(parent, User):
|
||||||
title = f"New comment on your wall by @{c.author_name}"
|
title = f"New comment on your wall by @{c.author_name}"
|
||||||
else:
|
else:
|
||||||
title = f'New reply by @{c.author_name}'
|
title = f'New reply by @{c.author_name}'
|
||||||
|
|
||||||
if len(c.body) > PUSH_NOTIF_LIMIT: notifbody = c.body[:PUSH_NOTIF_LIMIT] + '...'
|
if len(c.body) > PUSH_NOTIF_LIMIT: notifbody = c.body[:PUSH_NOTIF_LIMIT] + '...'
|
||||||
else: notifbody = c.body
|
else: notifbody = c.body
|
||||||
|
|
||||||
push_notif({parent_user.id}, title, notifbody, c)
|
push_notif({parent_user.id}, title, notifbody, c)
|
||||||
|
|
||||||
vote = CommentVote(user_id=v.id,
|
vote = CommentVote(user_id=v.id,
|
||||||
comment_id=c.id,
|
comment_id=c.id,
|
||||||
|
@ -660,13 +663,16 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(body, v)
|
notify_users = NOTIFY_USERS(body, v)
|
||||||
|
|
||||||
for x in notify_users-bots:
|
if notify_users == 'everyone':
|
||||||
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
alert_everyone(c.id)
|
||||||
if not notif:
|
else:
|
||||||
n = Notification(comment_id=c.id, user_id=x)
|
for x in notify_users-bots:
|
||||||
g.db.add(n)
|
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
||||||
if not v.shadowbanned:
|
if not notif:
|
||||||
push_notif({x}, f'New mention of you by @{c.author_name}', c.body, c)
|
n = Notification(comment_id=c.id, user_id=x)
|
||||||
|
g.db.add(n)
|
||||||
|
if not v.shadowbanned:
|
||||||
|
push_notif({x}, f'New mention of you by @{c.author_name}', c.body, c)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
return {"body": c.body, "comment": c.realbody(v)}
|
return {"body": c.body, "comment": c.realbody(v)}
|
||||||
|
|
|
@ -50,8 +50,11 @@ def publish(pid, v):
|
||||||
|
|
||||||
if notify_users:
|
if notify_users:
|
||||||
cid, text = notif_comment2(p)
|
cid, text = notif_comment2(p)
|
||||||
for x in notify_users:
|
if notify_users == 'everyone':
|
||||||
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
||||||
|
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
@ -641,8 +644,11 @@ def submit_post(v:User, sub=None):
|
||||||
|
|
||||||
if notify_users:
|
if notify_users:
|
||||||
cid, text = notif_comment2(p)
|
cid, text = notif_comment2(p)
|
||||||
for x in notify_users:
|
if notify_users == 'everyone':
|
||||||
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
||||||
|
|
||||||
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{p.body}{p.title}'.lower() and sub != 'chudrama':
|
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in f'{p.body}{p.title}'.lower() and sub != 'chudrama':
|
||||||
p.is_banned = True
|
p.is_banned = True
|
||||||
|
@ -1026,8 +1032,11 @@ def edit_post(pid, v):
|
||||||
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v)
|
notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v)
|
||||||
if notify_users:
|
if notify_users:
|
||||||
cid, text = notif_comment2(p)
|
cid, text = notif_comment2(p)
|
||||||
for x in notify_users:
|
if notify_users == 'everyone':
|
||||||
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text, pushnotif_url=p.permalink)
|
||||||
|
|
||||||
if v.id == p.author_id:
|
if v.id == p.author_id:
|
||||||
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
|
if int(time.time()) - p.created_utc > 60 * 3: p.edited_utc = int(time.time())
|
||||||
|
|
|
@ -259,8 +259,11 @@ def settings_personal_post(v):
|
||||||
if notify_users:
|
if notify_users:
|
||||||
text = f"@{v.username} has added you to their friends list!"
|
text = f"@{v.username} has added you to their friends list!"
|
||||||
cid = notif_comment(text)
|
cid = notif_comment(text)
|
||||||
for x in notify_users:
|
if notify_users == 'everyone':
|
||||||
add_notif(cid, x, text)
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text)
|
||||||
|
|
||||||
v.friends = friends[:1000]
|
v.friends = friends[:1000]
|
||||||
v.friends_html=friends_html
|
v.friends_html=friends_html
|
||||||
|
@ -284,8 +287,11 @@ def settings_personal_post(v):
|
||||||
if notify_users:
|
if notify_users:
|
||||||
text = f"@{v.username} has added you to their enemies list!"
|
text = f"@{v.username} has added you to their enemies list!"
|
||||||
cid = notif_comment(text)
|
cid = notif_comment(text)
|
||||||
for x in notify_users:
|
if notify_users == 'everyone':
|
||||||
add_notif(cid, x, text)
|
alert_everyone(cid)
|
||||||
|
else:
|
||||||
|
for x in notify_users:
|
||||||
|
add_notif(cid, x, text)
|
||||||
|
|
||||||
v.enemies = enemies[:1000]
|
v.enemies = enemies[:1000]
|
||||||
v.enemies_html=enemies_html
|
v.enemies_html=enemies_html
|
||||||
|
|
Loading…
Reference in New Issue