remotes/1693045480750635534/spooky-22
Aevann1 2021-12-20 22:03:59 +02:00
parent 714e818af7
commit 4135175d8a
16 changed files with 177 additions and 231 deletions

View File

@ -37,7 +37,6 @@ class Comment(Base):
is_bot = Column(Boolean, default=False)
is_pinned = Column(String)
sentto=Column(Integer, ForeignKey("users.id"))
notifiedto=Column(Integer)
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
oauth_app = relationship("OauthApp", viewonly=True)
upvotes = Column(Integer, default=1)
@ -98,7 +97,8 @@ class Comment(Base):
@property
@lazy
def age_string(self):
if not self.created_utc: return None
age = int(time.time()) - self.created_utc
if age < 60:
@ -416,12 +416,6 @@ class Notification(Base):
user_id = Column(Integer, ForeignKey("users.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
read = Column(Boolean, default=False)
followsender = Column(Integer)
unfollowsender = Column(Integer)
removefollowsender = Column(Integer)
blocksender = Column(Integer)
unblocksender = Column(Integer)
comment = relationship("Comment", viewonly=True)
user = relationship("User", viewonly=True)

View File

@ -6,107 +6,68 @@ from .markdown import *
from .sanitize import *
from .const import *
def send_repeatable_notification(uid, text, autojanny=False):
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
if autojanny: author_id = AUTOJANNY_ID
else: author_id = NOTIFICATIONS_ID
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
if existing:
existing2 = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=existing[0]).first()
if existing2:
text_html = sanitize(CustomRenderer().render(mistletoe.Document(text)))
new_comment = Comment(author_id=author_id,
parent_submission=None,
distinguish_level=6,
body=text,
body_html=text_html,
created_utc=0)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id, user_id=uid)
g.db.add(notif)
return
send_notification(uid, text, autojanny)
def send_notification(uid, text, autojanny=False):
cid = notif_comment(text, autojanny)
add_notif(cid, uid)
def notif_comment(text, autojanny=False):
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
if autojanny: author_id = AUTOJANNY_ID
else: author_id = NOTIFICATIONS_ID
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
if existing: cid = existing[0]
else:
author_id = NOTIFICATIONS_ID
if ' has gifted you ' not in text:
existing = g.db.query(Comment.id).filter(Comment.author_id == author_id, Comment.body_html == text_html, Comment.notifiedto == uid).first()
if existing: return
new_comment = Comment(author_id=author_id,
parent_submission=None,
distinguish_level=6,
body_html=text_html,
notifiedto=uid
)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id, user_id=uid)
g.db.add(notif)
def send_follow_notif(vid, user, text):
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=None,
distinguish_level=6,
body_html=text_html,
)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id,
user_id=user,
followsender=vid)
g.db.add(notif)
def send_unfollow_notif(vid, user, text):
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=None,
distinguish_level=6,
body_html=text_html,
)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id,
user_id=user,
unfollowsender=vid)
g.db.add(notif)
def send_block_notif(vid, user, text):
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=None,
distinguish_level=6,
body_html=text_html,
)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id,
user_id=user,
blocksender=vid)
g.db.add(notif)
def send_unblock_notif(vid, user, text):
text_html = CustomRenderer().render(mistletoe.Document(text))
text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=None,
distinguish_level=6,
body_html=text_html,
)
g.db.add(new_comment)
g.db.flush()
notif = Notification(comment_id=new_comment.id,
user_id=user,
unblocksender=vid)
g.db.add(notif)
text_html = sanitize(CustomRenderer().render(mistletoe.Document(text)))
new_comment = Comment(author_id=author_id,
parent_submission=None,
distinguish_level=6,
body=text,
body_html=text_html,
created_utc=0)
g.db.add(new_comment)
g.db.flush()
cid = new_comment.id
return cid
def add_notif(cid, uid):
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).first()
if not existing:
notif = Notification(comment_id=cid, user_id=uid)
g.db.add(notif)
def send_admin(vid, text):

View File

@ -1,5 +1,5 @@
from .get import *
from .alerts import send_notification
from .alerts import *
from files.helpers.const import *

View File

@ -16,10 +16,12 @@ from flask import *
from files.__main__ import app, cache, limiter
from .front import frontlist
from files.helpers.discord import add_role
from datetime import datetime
SITE_NAME = environ.get("SITE_NAME", "").strip()
if SITE_NAME == 'PCM': cc = "splash mountain"
else: cc = "country club"
month = datetime.now().strftime('%B')
@app.get("/distribute/<cid>")
@admin_level_required(3)
@ -30,16 +32,16 @@ def distribute(v, cid):
votes = g.db.query(CommentVote).filter_by(comment_id=cid)
autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).first()
coinsperperson = int(autobetter.coins / votes.count())
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post}]({post}) !")
for vote in votes:
u = vote.user
u.coins += coinsperperson
send_notification(u.id, f"You won {coinsperperson} coins betting on {post} !")
g.db.add(u)
add_notif(cid, u.id)
autobetter.coins = 0
g.db.add(autobetter)
g.db.commit()
return str(coinsperperson)
return f"Each winner has received {coinsperperson} coins!"
@app.get("/truescore")
@admin_level_required(2)
@ -199,16 +201,18 @@ def remove_meme_admin(v, username):
def monthly(v):
if 'pcm' in request.host or (SITE_NAME == 'Drama' and v.admin_level > 2) or ('rama' not in request.host and 'pcm' not in request.host):
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
for u in g.db.query(User).filter(User.patron > 0).all():
if u.patron == 1: procoins = 2500
elif u.patron == 2: procoins = 5000
elif u.patron == 3: procoins = 10000
elif u.patron == 4: procoins = 25000
elif u.patron == 5: procoins = 50000
u.procoins += procoins
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)
cid = notif_comment(f"You were given {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
add_notif(cid, u.id)
g.db.commit()
return {"message": "Monthly coins granted"}
@ -677,8 +681,8 @@ def agendaposter(user_id, v):
badge = user.has_badge(26)
if badge: g.db.delete(badge)
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.")
if user.agendaposter: send_repeatable_notification(user.id, f"You have been marked by an admin as an agendaposter ({note}).")
else: send_repeatable_notification(user.id, f"You have been unmarked by an admin as an agendaposter.")
g.db.commit()
if user.agendaposter: return redirect(user.url)
@ -839,7 +843,7 @@ def ban_user(user_id, v):
if message: text = f"Your account has been permanently suspended for the following reason:\n\n> {message}"
else: text = "Your account has been permanently suspended."
send_notification(user.id, text)
send_repeatable_notification(user.id, text)
if days == 0: duration = "permanent"
elif days == 1: duration = "1 day"
@ -893,7 +897,7 @@ def unban_user(user_id, v):
x.ban_evade = 0
g.db.add(x)
send_notification(user.id,
send_repeatable_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(
@ -1033,13 +1037,13 @@ def api_sticky_post(post_id, v):
if post.stickied:
if v.id != post.author_id:
message = f"@{v.username} has pinned your [post](/post/{post_id})!"
send_notification(post.author_id, message)
send_repeatable_notification(post.author_id, message)
g.db.commit()
return {"message": "Post pinned!"}
else:
if v.id != post.author_id:
message = f"@{v.username} has unpinned your [post](/post/{post_id})!"
send_notification(post.author_id, message)
send_repeatable_notification(post.author_id, message)
g.db.commit()
return {"message": "Post unpinned!"}

View File

@ -133,7 +133,7 @@ def buy(v, award):
g.db.flush()
if award == "lootbox":
send_notification(995, f"@{v.username} bought a lootbox!")
send_repeatable_notification(995, f"@{v.username} bought a lootbox!")
for i in [1,2,3,4,5]:
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
thing += 1
@ -212,7 +212,7 @@ def award_post(pid, v):
note = request.values.get("note", "").strip()
if note: msg += f"\n\n> {note}"
send_notification(post.author.id, msg)
send_repeatable_notification(post.author.id, msg)
author = post.author
if kind == "ban":
@ -220,26 +220,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(author.id, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.")
send_repeatable_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 += 86400
send_notification(author.id, f"Your account has been suspended for yet another day for {link}. Seriously man?")
send_repeatable_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(author.id, f"Your ban duration has been reduced by 1 day!")
send_repeatable_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(author.id, f"You have been unbanned!")
send_repeatable_notification(author.id, f"You have been unbanned!")
elif kind == "grass":
author.is_banned = AUTOJANNY_ID
author.ban_reason = f"grass award used by @{v.username} on /post/{post.id}"
link = f"[this post]({post.permalink})"
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!")
send_repeatable_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
@ -270,13 +270,13 @@ def award_post(pid, v):
author.flairchanged = time.time() + 86400
elif kind == "pause":
author.mute = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(68):
new_badge = Badge(badge_id=68, user_id=author.id)
g.db.add(new_badge)
elif kind == "unpausable":
author.unmutable = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(67):
new_badge = Badge(badge_id=67, user_id=author.id)
g.db.add(new_badge)
@ -288,7 +288,7 @@ def award_post(pid, v):
return {"error": "This user is the under the effect of a conflicting award: Bird Site award."}, 404
if author.longpost: author.longpost += 86400
else: author.longpost = time.time() + 86400
send_notification(IDIO_ID, f"@{v.username} used {kind} award on [{post.shortlink}]({post.shortlink})")
send_repeatable_notification(IDIO_ID, f"@{v.username} used {kind} award on [{post.shortlink}]({post.shortlink})")
elif kind == "bird":
if author.longpost:
return {"error": "This user is the under the effect of a conflicting award: Pizzashill award."}, 404
@ -296,32 +296,32 @@ def award_post(pid, v):
else: author.bird = time.time() + 86400
elif kind == "eye":
author.eye = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(83):
new_badge = Badge(badge_id=83, user_id=author.id)
g.db.add(new_badge)
elif kind == "alt":
author.alt = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(84):
new_badge = Badge(badge_id=84, user_id=author.id)
g.db.add(new_badge)
elif kind == "unblockable":
author.unblockable = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(87):
new_badge = Badge(badge_id=87, user_id=author.id)
g.db.add(new_badge)
for block in g.db.query(UserBlock).filter_by(target_id=author.id).all(): g.db.delete(block)
elif kind == "fish":
author.fish = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(90):
new_badge = Badge(badge_id=90, user_id=author.id)
g.db.add(new_badge)
elif kind == "grinch":
author.grinch = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(91):
new_badge = Badge(badge_id=91, user_id=author.id)
g.db.add(new_badge)
@ -383,7 +383,7 @@ def award_comment(cid, v):
note = request.values.get("note", "").strip()
if note: msg += f"\n\n> {note}"
send_notification(c.author.id, msg)
send_repeatable_notification(c.author.id, msg)
author = c.author
if kind == "ban":
@ -391,26 +391,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(author.id, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.")
send_repeatable_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 += 86400
send_notification(author.id, f"Your account has been suspended for yet another day for {link}. Seriously man?")
send_repeatable_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(author.id, f"Your ban duration has been reduced by 1 day!")
send_repeatable_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(author.id, f"You have been unbanned!")
send_repeatable_notification(author.id, f"You have been unbanned!")
elif kind == "grass":
author.is_banned = AUTOJANNY_ID
author.ban_reason = f"grass award used by @{v.username} on /comment/{c.id}"
link = f"[this comment]({c.permalink})"
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!")
send_repeatable_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
@ -438,13 +438,13 @@ def award_comment(cid, v):
author.flairchanged = time.time() + 86400
elif kind == "pause":
author.mute = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(68):
new_badge = Badge(badge_id=68, user_id=author.id)
g.db.add(new_badge)
elif kind == "unpausable":
author.unmutable = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(67):
new_badge = Badge(badge_id=67, user_id=author.id)
g.db.add(new_badge)
@ -456,7 +456,7 @@ def award_comment(cid, v):
return {"error": "This user is the under the effect of a conflicting award: Bird Site award."}, 404
if author.longpost: author.longpost += 86400
else: author.longpost = time.time() + 86400
send_notification(IDIO_ID, f"@{v.username} used {kind} award on [{c.shortlink}]({c.shortlink})")
send_repeatable_notification(IDIO_ID, f"@{v.username} used {kind} award on [{c.shortlink}]({c.shortlink})")
elif kind == "bird":
if author.longpost:
return {"error": "This user is the under the effect of a conflicting award: Pizzashill award."}, 404
@ -464,32 +464,32 @@ def award_comment(cid, v):
else: author.bird = time.time() + 86400
elif kind == "eye":
author.eye = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(83):
new_badge = Badge(badge_id=83, user_id=author.id)
g.db.add(new_badge)
elif kind == "alt":
author.alt = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(84):
new_badge = Badge(badge_id=84, user_id=author.id)
g.db.add(new_badge)
elif kind == "unblockable":
author.unblockable = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(87):
new_badge = Badge(badge_id=87, user_id=author.id)
g.db.add(new_badge)
for block in g.db.query(UserBlock).filter_by(target_id=author.id).all(): g.db.delete(block)
elif kind == "fish":
author.fish = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(90):
new_badge = Badge(badge_id=90, user_id=author.id)
g.db.add(new_badge)
elif kind == "grinch":
author.grinch = True
send_notification(CARP_ID, f"@{v.username} used {kind} award!")
send_repeatable_notification(CARP_ID, f"@{v.username} used {kind} award!")
if not author.has_badge(91):
new_badge = Badge(badge_id=91, user_id=author.id)
g.db.add(new_badge)
@ -555,7 +555,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(u.id, text)
send_repeatable_notification(u.id, text)
g.db.commit()

View File

@ -260,7 +260,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(v.id, text)
send_repeatable_notification(v.id, text)
v.ban(reason="Spamming.",
days=1)
@ -719,7 +719,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(v.id, text)
send_repeatable_notification(v.id, text)
v.ban(reason="Spamming.",
days=1)
@ -931,13 +931,13 @@ def toggle_pin_comment(cid, v):
if comment.is_pinned:
if v.id != comment.author_id:
message = f"@{v.username} has pinned your [comment]({comment.permalink})!"
send_notification(comment.author_id, message)
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
else:
if v.id != comment.author_id:
message = f"@{v.username} has unpinned your [comment]({comment.permalink})!"
send_notification(comment.author_id, message)
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}

View File

@ -161,7 +161,7 @@ def front_all(v):
if v.agendaposter_expires_utc and v.agendaposter_expires_utc < time.time():
v.agendaposter_expires_utc = 0
v.agendaposter = None
send_notification(v.id, "Your agendaposter theme has expired!")
send_repeatable_notification(v.id, "Your agendaposter theme has expired!")
g.db.add(v)
badge = v.has_badge(26)
if badge: g.db.delete(badge)
@ -169,25 +169,25 @@ def front_all(v):
if v.flairchanged and v.flairchanged < time.time():
v.flairchanged = None
send_notification(v.id, "Your flair lock has expired. You can now change your flair!")
send_repeatable_notification(v.id, "Your flair lock has expired. You can now change your flair!")
g.db.add(v)
g.db.commit()
if v.marseyawarded and v.marseyawarded < time.time():
v.marseyawarded = None
send_notification(v.id, "Your marsey award has expired!")
send_repeatable_notification(v.id, "Your marsey award has expired!")
g.db.add(v)
g.db.commit()
if v.longpost and v.longpost < time.time():
v.longpost = None
send_notification(v.id, "Your pizzashill award has expired!")
send_repeatable_notification(v.id, "Your pizzashill award has expired!")
g.db.add(v)
g.db.commit()
if v.bird and v.bird < time.time():
v.bird = None
send_notification(v.id, "Your bird site award has expired!")
send_repeatable_notification(v.id, "Your bird site award has expired!")
g.db.add(v)
g.db.commit()

View File

@ -313,22 +313,6 @@ def sign_up_post(v):
ref_id = int(request.values.get("referred_by", 0))
# if ref_id:
# ref_user = g.db.query(User).filter_by(id=ref_id).first()
# if ref_user:
# badge_types = g.db.query(BadgeDef).filter(BadgeDef.qualification_expr.isnot(None)).all()
# for badge in badge_types:
# if eval(badge.qualification_expr, {}, {'v': ref_user}):
# if not ref_user.has_badge(badge.id):
# new_badge = Badge(user_id=ref_user.id, badge_id=badge.id)
# g.db.add(new_badge)
# else:
# bad_badge = ref_user.has_badge(badge.id)
# if bad_badge: g.db.delete(bad_badge)
# g.db.add(ref_user)
id_1 = g.db.query(User.id).filter_by(id=7).count()
users_count = g.db.query(User.id).count()
if id_1 == 0 and users_count < 7: admin_level=3

View File

@ -123,7 +123,7 @@ def admin_app_approve(v, aid):
g.db.add(new_auth)
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.")
send_repeatable_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.")
ma = ModAction(
kind="approve_app",
@ -147,7 +147,7 @@ def admin_app_revoke(v, aid):
if app.id:
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
send_notification(app.author.id, f"Your application `{app.app_name}` has been revoked.")
send_repeatable_notification(app.author.id, f"Your application `{app.app_name}` has been revoked.")
g.db.delete(app)
@ -173,7 +173,7 @@ def admin_app_reject(v, aid):
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
send_notification(app.author.id, f"Your application `{app.app_name}` has been rejected.")
send_repeatable_notification(app.author.id, f"Your application `{app.app_name}` has been rejected.")
g.db.delete(app)

View File

@ -7,7 +7,7 @@ from files.helpers.sanitize import *
from files.helpers.filters import *
from files.helpers.markdown import *
from files.helpers.session import *
from files.helpers.alerts import send_notification, NOTIFY_USERS
from files.helpers.alerts import *
from files.helpers.discord import send_message
from files.helpers.const import *
from files.classes import *
@ -64,12 +64,17 @@ def publish(pid, v):
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: [{post.title}]({post.permalink})")
cid = notif_comment(f"@{v.username} has mentioned you: [{post.title}]({post.permalink})")
for x in notify_users:
add_notif(cid, x)
cid = notif_comment(f"@{v.username} has made a new post: [{post.title}]({post.permalink})", True)
for follow in v.followers:
user = get_account(follow.user_id)
if post.club and not user.club_allowed: continue
send_notification(user.id, f"@{v.username} has made a new post: [{post.title}]({post.permalink})", True)
if post.club and not user.paid_dues: continue
add_notif(cid, user.id)
cache.delete_memoized(frontlist)
@ -554,9 +559,10 @@ def edit_post(pid, v):
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
message = f"@{v.username} has mentioned you: [{p.title}]({p.permalink})"
cid = notif_comment(f"@{v.username} has mentioned you: [{p.title}]({p.permalink})")
for x in notify_users:
add_notif(cid, x)
for x in notify_users: send_notification(x, message)
if (title != p.title or body != p.body) and v.id == p.author_id:
@ -881,7 +887,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(v.id, text)
send_repeatable_notification(v.id, text)
v.ban(reason="Spamming.",
days=1)
@ -1068,12 +1074,15 @@ def submit_post(v):
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
for x in notify_users: send_notification(x, f"@{v.username} has mentioned you: [{title}]({new_post.permalink})")
cid = notif_comment(f"@{v.username} has mentioned you: [{title}]({new_post.permalink})")
for x in notify_users:
add_notif(cid, x)
cid = notif_comment(f"@{v.username} has made a new post: [{title}]({new_post.permalink})", True)
for follow in v.followers:
user = get_account(follow.user_id)
if new_post.club and not user.club_allowed: continue
send_notification(user.id, f"@{v.username} has made a new post: [{title}]({new_post.permalink})", True)
if new_post.club and not user.paid_dues: continue
add_notif(cid, user.id)
g.db.add(new_post)
g.db.flush()

View File

@ -252,9 +252,11 @@ def settings_profile_post(v):
username = mention["href"].split("@")[1]
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
cid = notif_comment(f"@{v.username} has added you to their friends list!")
for x in notify_users:
message = f"@{v.username} has added you to their friends list!"
send_notification(x, message)
add_notif(cid, x)
v.friends = friends[:500]
v.friends_html=friends_html
@ -297,10 +299,11 @@ def settings_profile_post(v):
username = mention["href"].split("@")[1]
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
cid = notif_comment(f"@{v.username} has added you to their enemies list!")
for x in notify_users:
message = f"@{v.username} has added you to their enemies list!"
send_notification(x, message)
add_notif(cid, x)
v.enemies = enemies[:500]
v.enemies_html=enemies_html
@ -365,9 +368,12 @@ def settings_profile_post(v):
username = mention["href"].split("@")[1]
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
cid = notif_comment(f"@{v.username} has added you to their friends list!")
for x in notify_users:
message = f"@{v.username} has added you to their friends list!"
send_notification(x, message)
add_notif(cid, x)
v.bio = bio[:1500]
v.bio_html=bio_html
@ -574,7 +580,7 @@ def gumroad(v):
elif v.patron == 5: procoins = 50000
v.procoins += procoins
send_notification(v.id, f"You were given {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).")
send_repeatable_notification(v.id, f"You have received {procoins} Marseybux! You can use them to buy awards in the [shop](/shop).")
if v.truecoins > 150 and v.patron > 0: v.cluballowed = True
if v.patron > 3 and v.verified == None: v.verified = "Verified"
@ -938,10 +944,7 @@ def settings_block_user(v):
)
g.db.add(new_block)
existing = g.db.query(Notification.id).filter_by(blocksender=v.id, user_id=user.id).first()
if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!")
send_notification(user.id, f"@{v.username} has blocked you!")
cache.delete_memoized(frontlist)
@ -964,8 +967,7 @@ def settings_unblock_user(v):
g.db.delete(x)
existing = g.db.query(Notification.id).filter_by(unblocksender=v.id, user_id=user.id).first()
if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!")
send_notification(user.id, f"@{v.username} has unblocked you!")
cache.delete_memoized(frontlist)

View File

@ -114,7 +114,7 @@ def pay_rent(v):
u = get_account(253)
u.coins += 500
g.db.add(u)
send_notification(u.id, f"@{v.username} has paid rent!")
send_repeatable_notification(u.id, f"@{v.username} has paid rent!")
g.db.commit()
return {"message": "Rent paid!"}
@ -135,20 +135,20 @@ def steal(v):
g.db.add(v)
u.coins -= 700
g.db.add(u)
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?")
send_repeatable_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_repeatable_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(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.")
send_repeatable_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_repeatable_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(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.")
send_repeatable_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_repeatable_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)
@ -187,7 +187,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(user.id, suicide)
send_repeatable_notification(user.id, suicide)
v.suicide_utc = t
g.db.add(v)
g.db.commit()
@ -224,26 +224,26 @@ def transfer_coins(v, username):
if 'rdrama.net' in request.host: tax_receiver.coins += tax/3
else: tax_receiver.coins += tax
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
send_notification(TAX_RECEIVER_ID, log_message)
send_repeatable_notification(TAX_RECEIVER_ID, log_message)
g.db.add(tax_receiver)
if 'rdrama.net' in request.host:
carp = g.db.query(User).filter_by(id=CARP_ID).first()
carp.coins += tax/3
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
send_notification(CARP_ID, log_message)
send_repeatable_notification(CARP_ID, log_message)
g.db.add(carp)
dad = g.db.query(User).filter_by(id=DAD_ID).first()
dad.coins += tax/3
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
send_notification(DAD_ID, log_message)
send_repeatable_notification(DAD_ID, log_message)
g.db.add(dad)
else: tax = 0
receiver.coins += amount-tax
v.coins -= amount
send_notification(receiver.id, f"🤑 [@{v.username}]({v.url}) has gifted you {amount-tax} {app.config['COINS_NAME']}!")
send_repeatable_notification(receiver.id, f"🤑 [@{v.username}]({v.url}) has gifted you {amount-tax} {app.config['COINS_NAME']}!")
g.db.add(receiver)
g.db.add(v)
@ -803,8 +803,7 @@ def follow_user(username, v):
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
g.db.add(target)
existing = g.db.query(Notification.id).filter_by(followsender=v.id, user_id=target.id).first()
if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!")
send_notification(target.id, f"@{v.username} has followed you!")
g.db.commit()
@ -822,18 +821,16 @@ def unfollow_user(username, v):
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first()
if not follow: return {"message": "User unfollowed!"}
if follow:
g.db.delete(follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
g.db.add(target)
g.db.delete(follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
g.db.add(target)
send_notification(target.id, f"@{v.username} has unfollowed you!")
existing = g.db.query(Notification.id).filter_by(unfollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!")
g.db.commit()
g.db.commit()
return {"message": "User unfollowed!"}
@ -854,8 +851,7 @@ def remove_follow(username, v):
v.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=v.id).count()
g.db.add(v)
existing = g.db.query(Notification.id).filter_by(removefollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has removed your follow!")
send_repeatable_notification(target.id, f"@{v.username} has removed your follow!")
g.db.commit()

View File

@ -1,7 +1,6 @@
from files.helpers.wrappers import *
from files.helpers.get import *
from files.helpers.const import AUTOBETTER_ID
from files.helpers.alerts import send_notification
from files.classes import *
from flask import *
from files.__main__ import app, limiter, cache

View File

@ -210,7 +210,10 @@
{% if c.parent_comment_id and not standalone and level != 1 %}<a href="#comment-{{ c.parent_comment_id }}-only" class="text-muted ml-2"><i class="fas fa-reply fa-sm fa-fw fa-flip-horizontal mr-1"></i>{{ c.parent_comment.author.username }}</a>{% endif %}
<span id="timestamp-{{c.id}}" onmouseover="timestamp('timestamp-{{c.id}}','{{c.created_utc}}')" data-bs-toggle="tooltip" data-bs-placement="bottom" class="time-stamp">&nbsp;{{c.age_string}}</span>
{% if c.created_utc %}
<span id="timestamp-{{c.id}}" onmouseover="timestamp('timestamp-{{c.id}}','{{c.created_utc}}')" data-bs-toggle="tooltip" data-bs-placement="bottom" class="time-stamp">&nbsp;{{c.age_string}}</span>
{% endif %}
{% if c.edited_utc %}
<span class="time-edited" id="time-edit-{{c.id}}" onmouseover="timestamp('time-edit-{{c.id}}','{{c.edited_utc}}')"><span>&#183;</span> <span class="font-italic">Edited {{c.edited_string}}</span></span>
{% endif %}

View File

@ -56,7 +56,7 @@
<label class="custom-control-label" for="oldsite"></label>
</div>
<span class="text-small-extra text-muted">Enable if you would like to display images and videos in full size on the frontpage.</span>
<span class="text-small-extra text-muted">Enable if you would like to use the old version of the site.</span>
</div>

View File

@ -264,7 +264,6 @@ CREATE TABLE public.comments (
body character varying(10000),
body_html character varying(40000),
ban_reason character varying(25),
notifiedto integer,
realupvotes integer,
top_comment_id integer
);
@ -453,11 +452,6 @@ CREATE TABLE public.notifications (
user_id integer,
comment_id integer,
read boolean NOT NULL,
followsender integer,
unfollowsender integer,
blocksender integer,
unblocksender integer,
removefollowsender integer
);