diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 3a27780a6..27d37fdf4 100755 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -7,19 +7,14 @@ from .sanitize import * from .const import * -def send_notification(vid, user, text): - - if isinstance(user, int): - uid = user - else: - uid = user.id +def send_notification(uid, text): text = text.replace('r/', 'r\/').replace('u/', 'u\/') text_html = CustomRenderer().render(mistletoe.Document(text)) text_html = sanitize(text_html) - new_comment = Comment(author_id=vid, + new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT, parent_submission=None, distinguish_level=6, body=text, diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 94f489b55..7230fbe7b 100755 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -41,7 +41,7 @@ def check_ban_evade(v): if random.randint(0,30) < v.ban_evade: v.ban(reason="permaban evasion") - send_notification(NOTIFICATIONS_ACCOUNT, v, "Your account has been permanently suspended for the following reason:\n\n> permaban evasion") + send_notification(v.id, "Your account has been permanently suspended for the following reason:\n\n> permaban evasion") for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=v.id).all(): if post.is_banned: diff --git a/files/routes/admin.py b/files/routes/admin.py index e112260fd..3842fd83d 100755 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -179,7 +179,7 @@ def monthly(v): elif u.patron == 5 or u.patron == 8: procoins = 50000 u.procoins += procoins - send_notification(NOTIFICATIONS_ACCOUNT, u, f"You were given {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).") + send_notification(u.id, f"You were given {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).") g.db.add(u) g.db.commit() @@ -371,7 +371,7 @@ def badge_grant_post(v): \n\n![]({new_badge.path}) \n\n{new_badge.name} """ - send_notification(NOTIFICATIONS_ACCOUNT, user, text) + send_notification(user.id, text) g.db.commit() return redirect("/admin/badge_grant") @@ -600,8 +600,8 @@ def agendaposter(user_id, v): badge = user.has_badge(26) if badge: g.db.delete(badge) - if user.agendaposter: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been marked by an admin as an agendaposter ({note}).") - else: send_notification(NOTIFICATIONS_ACCOUNT, user, f"You have been unmarked by an admin as an agendaposter.") + if user.agendaposter: send_notification(user.id, f"You have been marked by an admin as an agendaposter ({note}).") + else: send_notification(user.id, f"You have been unmarked by an admin as an agendaposter.") g.db.commit() if user.agendaposter: return redirect(user.url) @@ -757,7 +757,7 @@ def ban_user(user_id, v): if x.admin_level > 0: break x.ban(admin=v, reason=reason) - send_notification(NOTIFICATIONS_ACCOUNT, user, text[:128]) + send_notification(user.id, text[:128]) if days == 0: duration = "permanent" elif days == 1: duration = "1 day" @@ -815,7 +815,7 @@ def unban_user(user_id, v): x.ban_evade = 0 g.db.add(x) - send_notification(NOTIFICATIONS_ACCOUNT, user, + send_notification(user.id, "Your account has been reinstated. Please carefully review and abide by the [rules](/post/2510) to ensure that you don't get suspended again.") ma=ModAction( diff --git a/files/routes/awards.py b/files/routes/awards.py index 2e197d470..53f2b261a 100755 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -469,7 +469,7 @@ def award_post(pid, v): note = request.values.get("note", "").strip() if note: msg += f"\n\n> {note}" - send_notification(NOTIFICATIONS_ACCOUNT, post.author, msg) + send_notification(post.author.id, msg) author = post.author if kind == "ban": @@ -477,26 +477,26 @@ def award_post(pid, v): if not author.is_suspended: author.ban(reason=f"1-Day ban award used by @{v.username} on /post/{post.id}", days=1) - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.") + send_notification(author.id, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.") elif author.unban_utc > 0: author.unban_utc += 24*60*60 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended for yet another day for {link}. Seriously man?") + send_notification(author.id, f"Your account has been suspended for yet another day for {link}. Seriously man?") elif kind == "unban": if not author.is_suspended or not author.unban_utc or time.time() > author.unban_utc: abort(403) if author.unban_utc - time.time() > 86400: author.unban_utc -= 86400 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your ban duration has been reduced by 1 day!") + send_notification(author.id, f"Your ban duration has been reduced by 1 day!") else: author.unban_utc = 0 author.is_banned = 0 author.ban_evade = 0 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"You have been unbanned!") + send_notification(author.id, f"You have been unbanned!") elif kind == "grass": author.is_banned = AUTOJANNY_ACCOUNT author.ban_reason = f"grass award used by @{v.username} on /post/{post.id}" link = f"[this post]({post.permalink})" - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass to get unbanned!") + send_notification(author.id, f"Your account has been suspended permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass to get unbanned!") elif kind == "pin": if post.stickied and post.stickied.startswith("t:"): t = int(post.stickied[2:]) + 3600 else: t = int(time.time()) + 3600 @@ -527,8 +527,10 @@ def award_post(pid, v): author.flairchanged = time.time() + 86400 elif kind == "pause": author.mute = True + send_notification(995, f"@{v.username} bought {kind} award!") elif kind == "unpausable": author.unmutable = True + send_notification(995, f"@{v.username} bought {kind} award!") post.author.received_award_count += 1 g.db.add(post.author) @@ -583,7 +585,7 @@ def award_comment(cid, v): note = request.values.get("note", "").strip() if note: msg += f"\n\n> {note}" - send_notification(NOTIFICATIONS_ACCOUNT, c.author, msg) + send_notification(c.author.id, msg) author = c.author if kind == "ban": @@ -591,26 +593,26 @@ def award_comment(cid, v): if not author.is_suspended: author.ban(reason=f"1-Day ban award used by @{v.username} on /comment/{c.id}", days=1) - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.") + send_notification(author.id, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.") elif author.unban_utc > 0: author.unban_utc += 24*60*60 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended for yet another day for {link}. Seriously man?") + send_notification(author.id, f"Your account has been suspended for yet another day for {link}. Seriously man?") elif kind == "unban": if not author.is_suspended or not author.unban_utc or time.time() > author.unban_utc: abort(403) if author.unban_utc - time.time() > 86400: author.unban_utc -= 86400 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your ban duration has been reduced by 1 day!") + send_notification(author.id, f"Your ban duration has been reduced by 1 day!") else: author.unban_utc = 0 author.is_banned = 0 author.ban_evade = 0 - send_notification(NOTIFICATIONS_ACCOUNT, author, f"You have been unbanned!") + send_notification(author.id, f"You have been unbanned!") elif kind == "grass": author.is_banned = AUTOJANNY_ACCOUNT author.ban_reason = f"grass award used by @{v.username} on /comment/{c.id}" link = f"[this comment]({c.permalink})" - send_notification(NOTIFICATIONS_ACCOUNT, author, f"Your account has been suspended permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass to get unbanned!") + send_notification(author.id, f"Your account has been suspended permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass to get unbanned!") elif kind == "pin": if c.is_pinned and c.is_pinned.startswith("t:"): t = int(c.is_pinned[2:]) + 3600 else: t = int(time.time()) + 3600 @@ -636,8 +638,12 @@ def award_comment(cid, v): author.customtitle = filter_title(new_name) if len(author.customtitle) > 1000: abort(403) author.flairchanged = time.time() + 86400 - elif kind == "pause": author.mute = True - elif kind == "unpausable": author.unmutable = True + elif kind == "pause": + author.mute = True + send_notification(995, f"@{v.username} bought {kind} award!") + elif kind == "unpausable": + author.unmutable = True + send_notification(995, f"@{v.username} bought {kind} award!") c.author.received_award_count += 1 g.db.add(c.author) @@ -696,7 +702,7 @@ def admin_userawards_post(v): for key, value in notify_awards.items(): text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n" - send_notification(NOTIFICATIONS_ACCOUNT, u, text) + send_notification(u.id, text) g.db.commit() diff --git a/files/routes/comments.py b/files/routes/comments.py index 13088db6b..a1c37f66d 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -225,7 +225,7 @@ def api_comment(v): if len(similar_comments) > threshold: text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!" - send_notification(NOTIFICATIONS_ACCOUNT, v, text) + send_notification(v.id, text) v.ban(reason="Spamming.", days=1) @@ -625,7 +625,7 @@ def edit_comment(cid, v): if len(similar_comments) > threshold: text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!" - send_notification(NOTIFICATIONS_ACCOUNT, v, text) + send_notification(v.id, text) v.ban(reason="Spamming.", days=1) diff --git a/files/routes/login.py b/files/routes/login.py index 78f01efbc..8bdbcda79 100755 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -342,7 +342,7 @@ def sign_up_post(v): if email: send_verification_email(new_user) - if "rama" in request.host: send_notification(NOTIFICATIONS_ACCOUNT, new_user, "Dude bussy lmao") + if "rama" in request.host: send_notification(new_user.id, "Dude bussy lmao") session["user_id"] = new_user.id session["session_id"] = token_hex(16) diff --git a/files/routes/oauth.py b/files/routes/oauth.py index 6ffcbf68e..78cccd832 100755 --- a/files/routes/oauth.py +++ b/files/routes/oauth.py @@ -120,7 +120,7 @@ def admin_app_approve(v, aid): g.db.add(new_auth) - send_notification(NOTIFICATIONS_ACCOUNT, user, f"Your application `{app.app_name}` has been approved. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next.") + send_notification(user.id, f"Your application `{app.app_name}` has been approved. Here's your access token: `{access_token}`\nPlease check the guide [here](/api) if you don't know what to do next.") g.db.commit() @@ -137,7 +137,7 @@ def admin_app_revoke(v, aid): if app.id: for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) - send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.") + send_notification(app.author.id, f"Your application `{app.app_name}` has been revoked.") g.db.delete(app) @@ -156,7 +156,7 @@ def admin_app_reject(v, aid): for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth) - send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.") + send_notification(app.author.id, f"Your application `{app.app_name}` has been rejected.") g.db.delete(app) diff --git a/files/routes/posts.py b/files/routes/posts.py index 7d1761c5f..654d3390a 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -63,7 +63,7 @@ def publish(pid, v): for follow in v.followers: user = get_account(follow.user_id) - send_notification(AUTOJANNY_ACCOUNT, user, f"@{v.username} has made a new post: [{post.title}](http://{site}{post.permalink})") + send_notification(user.id, f"@{v.username} has made a new post: [{post.title}](http://{site}{post.permalink})") g.db.commit() @@ -302,7 +302,7 @@ def edit_post(pid, v): message = f"@{v.username} has mentioned you: http://{site}{p.permalink}" for x in notify_users: existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x.id).first() - if not existing: send_notification(NOTIFICATIONS_ACCOUNT, x, message) + if not existing: send_notification(x.id, message) if title != p.title or body != p.body: @@ -589,7 +589,7 @@ def submit_post(v): if max(len(similar_urls), len(similar_posts)) >= threshold: text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!" - send_notification(NOTIFICATIONS_ACCOUNT, v, text) + send_notification(v.id, text) v.ban(reason="Spamming.", days=1) @@ -733,12 +733,12 @@ def submit_post(v): user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first() if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user) - for x in notify_users: send_notification(NOTIFICATIONS_ACCOUNT, x, f"@{v.username} has mentioned you: http://{site}{new_post.permalink}") + for x in notify_users: send_notification(x.id, f"@{v.username} has mentioned you: http://{site}{new_post.permalink}") if not new_post.private: for follow in v.followers: user = get_account(follow.user_id) - send_notification(AUTOJANNY_ACCOUNT, user, f"@{v.username} has made a new post: [{title}](http://{site}{new_post.permalink})") + send_notification(user.id, f"@{v.username} has made a new post: [{title}](http://{site}{new_post.permalink})") g.db.add(new_post) g.db.flush() diff --git a/files/routes/settings.py b/files/routes/settings.py index 9e0de5720..fb97cb32c 100755 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -311,7 +311,7 @@ def gumroad(v): elif v.patron == 5 or v.patron == 8: procoins = 50000 v.procoins += procoins - send_notification(NOTIFICATIONS_ACCOUNT, v, f"You were given {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).") + send_notification(v.id, f"You were given {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).") g.db.add(v) diff --git a/files/routes/users.py b/files/routes/users.py index 22421bbaf..df0ad875d 100755 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -31,7 +31,7 @@ def pay_rent(v): u = get_account(253) u.coins += 500 g.db.add(u) - send_notification(NOTIFICATIONS_ACCOUNT, u, f"@{v.username} has paid rent!") + send_notification(u.id, f"@{v.username} has paid rent!") g.db.commit() return {"message": "Rent paid!"} @@ -51,20 +51,20 @@ def steal(v): g.db.add(v) u.coins -= 700 g.db.add(u) - send_notification(NOTIFICATIONS_ACCOUNT, u, f"Some [grubby little rentoid](/@{v.username}) has absconded with 700 of your hard-earned dramacoins to fuel his Funko Pop addiction. Stop being so trusting.") - send_notification(NOTIFICATIONS_ACCOUNT, v, f"You have successfully shorted your heroic landlord 700 dramacoins in rent. You're slightly less materially poor, but somehow even moreso morally. Are you proud of yourself?") + send_notification(u.id, f"Some [grubby little rentoid](/@{v.username}) has absconded with 700 of your hard-earned dramacoins to fuel his Funko Pop addiction. Stop being so trusting.") + send_notification(v.id, f"You have successfully shorted your heroic landlord 700 dramacoins in rent. You're slightly less materially poor, but somehow even moreso morally. Are you proud of yourself?") g.db.commit() return {"message": "Attempt successful!"} else: if random.random() < 0.15: - send_notification(NOTIFICATIONS_ACCOUNT, u, f"You caught [this sniveling little renthog](/@{v.username}) trying to rob you. After beating him within an inch of his life, you sold his Nintendo Switch for 500 dramacoins and called the cops. He was sentenced to one (1) day in renthog prison.") - send_notification(NOTIFICATIONS_ACCOUNT, v, f"The ever-vigilant landchad has caught you trying to steal his hard-earned rent money. The police take you away and laugh as you impotently stutter A-ACAB :sob: You are fined 500 dramacoins and sentenced to one (1) day in renthog prison.") + send_notification(u.id, f"You caught [this sniveling little renthog](/@{v.username}) trying to rob you. After beating him within an inch of his life, you sold his Nintendo Switch for 500 dramacoins and called the cops. He was sentenced to one (1) day in renthog prison.") + send_notification(v.id, f"The ever-vigilant landchad has caught you trying to steal his hard-earned rent money. The police take you away and laugh as you impotently stutter A-ACAB :sob: You are fined 500 dramacoins and sentenced to one (1) day in renthog prison.") v.ban(days=1, reason="Jailed thief") v.fail_utc = int(time.time()) else: - send_notification(NOTIFICATIONS_ACCOUNT, u, f"You caught [this sniveling little renthog](/@{v.username}) trying to rob you. After beating him within an inch of his life, you showed mercy in exchange for a 500 dramacoin tip. This time.") - send_notification(NOTIFICATIONS_ACCOUNT, v, f"The ever-vigilant landchad has caught you trying to steal his hard-earned rent money. You were able to convince him to spare your life with a 500 dramacoin tip. This time.") + send_notification(u.id, f"You caught [this sniveling little renthog](/@{v.username}) trying to rob you. After beating him within an inch of his life, you showed mercy in exchange for a 500 dramacoin tip. This time.") + send_notification(v.id, f"The ever-vigilant landchad has caught you trying to steal his hard-earned rent money. You were able to convince him to spare your life with a 500 dramacoin tip. This time.") v.fail2_utc = int(time.time()) v.coins -= 500 g.db.add(v) @@ -98,7 +98,7 @@ def suicide(v, username): if v.admin_level == 0 and t - v.suicide_utc < 86400: return {"message": "You're on 1-day cooldown!"} user = get_user(username) suicide = f"Hi there,\n\nA [concerned user]({v.url}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators at r/SuicideWatch keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help." - send_notification(NOTIFICATIONS_ACCOUNT, user, suicide) + send_notification(user.id, suicide) v.suicide_utc = t g.db.add(v) g.db.commit() @@ -142,10 +142,10 @@ def transfer_coins(v, username): g.db.add(v) transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!" - send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message) + send_notification(receiver.id, transfer_message) log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})" - send_notification(NOTIFICATIONS_ACCOUNT, TAX_RECEIVER_ID, log_message) + send_notification(TAX_RECEIVER_ID.id, log_message) g.db.commit() diff --git a/files/routes/votes.py b/files/routes/votes.py index 9e21512e7..f404a7bde 100755 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -1,6 +1,5 @@ from files.helpers.wrappers import * from files.helpers.get import * -from files.helpers.const import NOTIFICATIONS_ACCOUNT from files.helpers.alerts import send_notification from files.classes import * from flask import * @@ -108,12 +107,12 @@ def api_vote_post(post_id, new, v): v.agendaposter_expires_utc = 0 v.agendaposter = False g.db.add(v) - send_notification(NOTIFICATIONS_ACCOUNT, v, "Your agendaposter theme has expired!") + send_notification(v.id, "Your agendaposter theme has expired!") if v.flairchanged and v.flairchanged < time.time(): v.flairchanged = None g.db.add(v) - send_notification(NOTIFICATIONS_ACCOUNT, v, "Your flair lock has expired. You can now change your flair!") + send_notification(v.id, "Your flair lock has expired. You can now change your flair!") try: g.db.flush()