add keyword notifs for $50 patrons and higher

pull/225/head
Aevann 2024-02-24 22:11:43 +02:00
parent 5988e6a341
commit 909fe8bc0a
8 changed files with 64 additions and 47 deletions

View File

@ -126,6 +126,7 @@ class User(Base):
defaultsorting = Column(String, default="hot")
defaulttime = Column(String, default=DEFAULT_TIME_FILTER)
custom_filter_list = Column(String)
keyword_notifs = Column(String)
original_username = Column(String)
extra_username = Column(String)
prelock_username = Column(String)
@ -189,6 +190,7 @@ class User(Base):
owned_hats = relationship("Hat", back_populates="owners")
hats_equipped = relationship("Hat", lazy="raise", viewonly=True)
hole_mods = relationship("Mod", primaryjoin="User.id == Mod.user_id", lazy="raise")
notifications = relationship("Notification", back_populates="user")
def __init__(self, **kwargs):
@ -1169,6 +1171,13 @@ class User(Base):
l = [i for i in l if i]
return l
@property
@lazy
def notif_words(self):
l = self.keyword_notifs.split('\n')
l = [i for i in l if i]
return l
@property
@lazy
def lottery_stats(self):

View File

@ -5,7 +5,7 @@ import gevent
from flask import g
from pywebpush import webpush
import time
from sqlalchemy.sql import text
from sqlalchemy.sql import text, and_
from sqlalchemy.orm import load_only
from files.classes import Comment, Post, Notification, PushSubscription, Group, Mod
@ -150,9 +150,16 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=Tr
notify_users = set()
for word, id in NOTIFIED_USERS.items():
if word in text:
notify_users.add(id)
criteria = (Notification.user_id == User.id, Notification.read == False)
keyword_users = g.db.query(User).options(load_only(User.id, User.keyword_notifs)).outerjoin(Notification, and_(*criteria)).group_by(User.id).having(func.count(Notification.user_id) < 100).filter(User.keyword_notifs != None)
for user in keyword_users:
for word in user.notif_words:
if word in text:
notify_users.add(user.id)
names = set(m.group(1) for m in mention_regex.finditer(text))

View File

@ -643,8 +643,6 @@ BADGE_BLACKLIST = { # only grantable by admins higher than PERMS['IGNORE_BADGE_B
137, # Lottery Winner
}
NOTIFIED_USERS = {}
if SITE in {'rdrama.net', 'staging.rdrama.net'}:
NOTIFICATION_SPAM_AGE_THRESHOLD = 0.5 * 86400
@ -710,36 +708,6 @@ if SITE in {'rdrama.net', 'staging.rdrama.net'}:
3336: 24, #Snally
}
NOTIFIED_USERS = {
'aevan': AEVANN_ID,
'avean': AEVANN_ID,
' capy': AEVANN_ID,
'capy ': AEVANN_ID,
'the rodent': AEVANN_ID,
'carp': CARP_ID,
'clit': CARP_ID,
'pizzashill': PIZZASHILL_ID,
'joan': 28,
'pewkie': 28,
'homocracy': 147,
'marco': 152,
'donger': 541,
'kaam': 1048,
'august': 1830,
'klen': 2050,
'soren': 2546,
'marseyismywaifu': 3377,
'mimw': 3377,
'heymoon': 3635,
'chiobu': 5214,
'impassionata': 5800,
'schizo': 8494,
'gaslight': 18121,
'sirpings': 2663,
'spal': 2663,
}
WELCOME_MSG = f"Hi there! It's me, your soon-to-be favorite rDrama user @carpathianflorist here to give you a brief rundown on some of the sick features we have here. You'll probably want to start by following me, though. So go ahead and click my name and then smash that Follow button. This is actually really important, so go on. Hurry.\n\nThanks!\n\nNext up: If you're a member of the media, similarly just shoot me a DM and I'll set about verifying you and then we can take care of your sad journalism stuff.\n\n**FOR EVERYONE ELSE**\n\n Begin by navigating to [the settings page](/settings/profile) (we'll be prettying this up so it's less convoluted soon, don't worry) and getting some basic customization done.\n\n### Themes\n\nDefinitely change your theme right away, the default one (Midnight) is pretty enough, but why not use something *exotic* like Win98, or *flashy* like Tron? Even Coffee is super tasteful and way more fun than the default. More themes to come when we get around to it!\n\n### Avatar/pfp\n\nYou'll want to set this pretty soon. Set the banner too while you're at it. Your profile is important!\n\n### Flairs\n\nSince you're already on the settings page, you may as well set a flair, too. As with your username, you can - obviously - choose the color of this, either with a hex value or just from the preset colors. And also like your username, you can change this at any time. Paypigs can even further relive the glory days of 90s-00s internet and set obnoxious signatures.\n\n### PROFILE ANTHEMS\n\nSpeaking of profiles, hey, remember MySpace? Do you miss autoplaying music assaulting your ears every time you visited a friend's page? Yeah, we brought that back. Enter a YouTube URL, wait a few seconds for it to process, and then BAM! you've got a profile anthem which people cannot mute. Unless they spend 20,000 dramacoin in the shop for a mute button. Which you can then remove from your profile by spending 40,000 dramacoin on an unmuteable anthem. Get fucked poors!\n\n### Dramacoin?\n\nDramacoin is basically our take on the karma system. Except unlike the karma system, it's not gay and boring and stupid and useless. Dramacoin can be spent at [Marsey's Dramacoin Emporium](/shop/awards) on upgrades to your user experience (many more coming than what's already listed there), and best of all on tremendously annoying awards to fuck with your fellow dramautists. We're always adding more, so check back regularly in case you happen to miss one of the announcement posts.\n\nLike karma, dramacoin is obtained by getting upvotes on your threads and comments. *Unlike* karma, it's also obtained by getting downvotes on your threads and comments. Downvotes don't really do anything here - they pay the same amount of dramacoin and they increase thread/comment ranking just the same as an upvote. You just use them to express petty disapproval and hopefully start a fight. Because all votes are visible here. To hell with your anonymity.\n\nDramacoin can also be traded amongst users from their profiles. Note that there is a 3% transaction fee.\n\n### Badges\n\nRemember all those neat little metallic icons you saw on my profile when you were following me? If not, scroll back up and go have a look. And doublecheck to make sure you pressed the Follow button. Anyway, those are badges. You earn them by doing a variety of things. Some of them even offer benefits, like discounts at the shop. A [complete list of badges and their requirements can be found here](/badges), though I add more pretty regularly, so keep an eye on the [changelog](/post/{CHANGELOG_THREAD}).\n\n### Other stuff\n\nWe're always adding new features, and we take a fun-first approach to development. If you have a suggestion for something that would be fun, funny, annoying - or best of all, some combination of all three - definitely make a thread about it. Or just DM me if you're shy. Weirdo. Anyway there's also the [leaderboards](/leaderboard), boring stuff like two-factor authentication you can toggle on somewhere in the settings page (psycho), the ability to save posts and comments, more than a thousand emojis already (most of which are rDrama originals), and on and on and on and on. This is just the basics, mostly to help you get acquainted with some of the things you can do here to make it more easy on the eyes, customizable, and enjoyable. If you don't enjoy it, just go away! We're not changing things to suit you! Get out of here loser! And no, you can't delete your account :na:\n\nI love you.<br>*xoxo Carp* 💋"
elif SITE in {'watchpeopledie.tv', 'marsey.world'}:
NOTIFICATION_SPAM_AGE_THRESHOLD = 0.5 * 86400
@ -828,15 +796,6 @@ elif SITE in {'watchpeopledie.tv', 'marsey.world'}:
CURRENCY_TRANSFER_ID = 48
ANTISPAM_BYPASS_IDS = {1718156}
NOTIFIED_USERS = {
'aevan': AEVANN_ID,
'avean': AEVANN_ID,
' capy': AEVANN_ID,
'capy ': AEVANN_ID,
'g-tix': GTIX_ID,
'gtix': GTIX_ID,
}
TIER_TO_NAME = {
1: "Beneficiary",
2: "Victim",

View File

@ -324,6 +324,7 @@ def _award_timers_task():
_process_timer(User.patron_utc, [22,23,24,25,26,27,28], f"Your {patron} status has expired!", {
User.patron: 0,
User.extra_username: None,
User.keyword_notifs: None,
})
_process_timer(User.chud, [58], "Your temporary chud status has expired!", {
User.chud_phrase: None,

View File

@ -408,10 +408,32 @@ def filters(v):
if len(filters) > 1000:
abort(400, "Filters are too long (max 1000 characters)")
v.custom_filter_list=filters
v.custom_filter_list = filters
g.db.add(v)
return {"message": "Your custom filters have been updated!"}
@app.post("/settings/keyword_notifs")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def keyword_notifs(v):
if v.patron < 5:
abort(403, f"Keyword notifications are only available to {patron}s donating $50/month or higher!")
keyword_notifs = request.values.get("keyword_notifs", "").replace('\r','').strip('\n')
if keyword_notifs == v.keyword_notifs:
abort(400, "You didn't change anything!")
if len(keyword_notifs) > 1000:
abort(400, "Keywords are too long (max 1000 characters)")
v.keyword_notifs = keyword_notifs
g.db.add(v)
return {"message": "Your keyword notifications have been updated!"}
def set_color(v, attr):
color = request.values.get(attr)

View File

@ -175,6 +175,24 @@
{{common.toggle_section('Hole Creation and Deletion Notifications', 'hole_creation_notifs', 'hole_creation_notifs', v.hole_creation_notifs, 'Get a notification when a hole is made or deleted.', false)}}
{% endif %}
{{common.toggle_section('Ping Group Creation Notifications', 'group_creation_notifs', 'group_creation_notifs', v.group_creation_notifs, 'Get a notification when a new ping group is made.', false)}}
<div class="d-lg-flex border-bottom">
<div class="title w-lg-25">
<label for="keyword-notifs">Keyword Notifications</label>
</div>
<div class="body w-lg-100">
<form id="keyword-notifs" action="/settings/keyword_notifs" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHR(this)">
<input hidden name="formkey" value="{{v|formkey}}">
<span>Notifies you when specific words or phrases are mentioned.</span>
<textarea autocomplete="off" class="form-control rounded my-2" placeholder="Add your own keyword notifications."
rows="3" name="keyword_notifs" form="keyword-notifs" maxlength="1000">{% if v.keyword_notifs %}{{v.keyword_notifs}}{% endif %}</textarea>
<span>Use a new line for each entry. Limit of 1000 characters.</span>
<p>Will stop taking effect if you reach 100 unread red notifications.</p>
<div class="d-flex">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Save Changes">
</div>
</form>
</div>
</div>
</div>
</section>

View File

@ -0,0 +1 @@
alter table users add column keyword_notifs varchar(1000);

View File

@ -92,6 +92,7 @@ CREATE TABLE public.users (
is_private boolean DEFAULT false NOT NULL,
unban_utc integer DEFAULT 0,
custom_filter_list character varying(1000) DEFAULT ''::character varying,
keyword_notifs character varying(1000),
stored_subscriber_count integer DEFAULT 0 NOT NULL,
original_username character varying(30),
flair_html character varying(1000),
@ -3074,4 +3075,3 @@ ALTER TABLE ONLY public.comments
--
-- PostgreSQL database dump complete
--