diff --git a/files/classes/comment.py b/files/classes/comment.py index 6da2c33fc..8c0570f09 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -135,6 +135,7 @@ class Comment(Base): ban_reason = Column(String) treasure_amount = Column(String) slots_result = Column(String) + ping_cost = Column(Integer) blackjack_result = Column(String) casino_game_id = Column(Integer, ForeignKey("casino_games.id")) chudded = Column(Boolean, default=False) diff --git a/files/classes/post.py b/files/classes/post.py index ecb369634..6d3f167ee 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -60,6 +60,7 @@ class Post(Base): new = Column(Boolean) notify = Column(Boolean) chudded = Column(Boolean, default=False) + ping_cost = Column(Integer) author = relationship("User", primaryjoin="Post.author_id==User.id") oauth_app = relationship("OauthApp") diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 988ea90a7..9383c2cbc 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -122,7 +122,7 @@ def add_notif(cid, uid, text, pushnotif_url=''): push_notif({uid}, 'New notification', text, pushnotif_url) -def NOTIFY_USERS(text, v, oldtext=None, ghost=False): +def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None): # Restrict young accounts from generating notifications if v.age < NOTIFICATION_SPAM_AGE_THRESHOLD: return set() @@ -176,6 +176,9 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False): if cost > v.coins: abort(403, f"You need {cost} coins to mention these ping groups!") + if log_cost: + log_cost.ping_cost = cost + g.db.query(User).filter(User.id.in_(members)).update({ User.coins: User.coins + mul }) v.charge_account('coins', cost) diff --git a/files/routes/comments.py b/files/routes/comments.py index 0f0acd2b2..ee84d8b3b 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -331,7 +331,7 @@ def comment(v:User): execute_zozbot(c, level, post_target, v) if not v.shadowbanned: - notify_users = NOTIFY_USERS(body, v, ghost=c.ghost) + notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, log_cost=c) if notify_users == 'everyone': alert_everyone(c.id) @@ -642,7 +642,7 @@ def edit_comment(cid, v): if v.marseyawarded and marseyaward_body_regex.search(body_html): abort(403, "You can only type marseys!") - notify_users = NOTIFY_USERS(body, v, c.body, ghost=c.ghost) + notify_users = NOTIFY_USERS(body, v, c.body, ghost=c.ghost, log_cost=c) if notify_users == 'everyone': alert_everyone(c.id) diff --git a/files/routes/posts.py b/files/routes/posts.py index 846be7e3d..e4f678c2c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -45,7 +45,7 @@ def publish(pid, v): p.created_utc = int(time.time()) g.db.add(p) - notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost) + notify_users = NOTIFY_USERS(f'{p.title} {p.body}', v, ghost=p.ghost, log_cost=p) if notify_users: cid, text = notif_comment2(p) @@ -665,7 +665,7 @@ def submit_post(v:User, sub=None): gevent.spawn(thumbnail_thread, p.id, v.id) if not p.private: - notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost) + notify_users = NOTIFY_USERS(f'{title} {body}', v, ghost=p.ghost, log_cost=p) if notify_users: cid, text = notif_comment2(p) @@ -1023,7 +1023,7 @@ def edit_post(pid, v): if not p.private: - notify_users = NOTIFY_USERS(f'{title} {body}', v, f'{p.title} {p.body}', ghost=p.ghost) + notify_users = NOTIFY_USERS(f'{title} {body}', v, f'{p.title} {p.body}', ghost=p.ghost, log_cost=p) if notify_users: cid, text = notif_comment2(p) if notify_users == 'everyone': diff --git a/files/templates/comments.html b/files/templates/comments.html index a166d6b01..3fba23e36 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -223,11 +223,15 @@ {% endif %} {% endif %} + {% if c.ping_cost %} + spent {{c.ping_cost}} coins on pings + {% endif %} + {% if c.slots_result %} - {{c.slots_result}} + {{c.slots_result}} {% elif c.casino_game_id %} {% set game_state = c.casino_game.game_state_json %} - {{game_state['symbols'].replace(',','')}} {{game_state['text']}} + {{game_state['symbols'].replace(',','')}} {{game_state['text']}} {% endif %} {% if c.blackjack_result %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 624fb6e40..cf042b276 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -96,6 +96,10 @@ {% endif %} {{p.views}} thread views   #{{p.id}} + + {% if p.ping_cost %} + spent {{p.ping_cost}} coins on pings + {% endif %} {% endmacro %} diff --git a/migrations/20230624-add-ping_costsql.sql b/migrations/20230624-add-ping_costsql.sql new file mode 100644 index 000000000..15e35332e --- /dev/null +++ b/migrations/20230624-add-ping_costsql.sql @@ -0,0 +1,2 @@ +alter table comments add column ping_cost int; +alter table posts add column ping_cost int;