2021-10-15 14:08:27 +00:00
from files . __main__ import app , limiter
from files . helpers . wrappers import *
from files . helpers . alerts import *
from files . helpers . get import *
from files . helpers . const import *
from files . classes . award import *
2021-10-20 21:13:30 +00:00
from . front import frontlist
2021-10-15 14:08:27 +00:00
from flask import g , request
2021-12-07 23:18:06 +00:00
from files . helpers . sanitize import filter_emojis_only
2021-12-15 19:30:26 +00:00
from copy import deepcopy
2021-10-15 14:08:27 +00:00
2021-11-19 18:42:59 +00:00
AWARDS3 = {
2021-10-21 17:01:25 +00:00
" fireflies " : {
" kind " : " fireflies " ,
" title " : " Fireflies " ,
2021-11-01 18:25:10 +00:00
" description " : " Makes fireflies swarm the post. " ,
2021-10-21 17:01:25 +00:00
" icon " : " fas fa-sparkles " ,
" color " : " text-warning " ,
2021-12-31 23:45:27 +00:00
" price " : 300
2021-10-21 15:06:55 +00:00
} ,
" shit " : {
" kind " : " shit " ,
" title " : " Shit " ,
2021-11-01 18:25:10 +00:00
" description " : " Makes flies swarm the post. " ,
2021-10-21 15:06:55 +00:00
" icon " : " fas fa-poop " ,
" color " : " text-black-50 " ,
2021-12-31 23:45:27 +00:00
" price " : 300
2021-10-21 15:06:55 +00:00
} ,
2022-01-01 20:20:15 +00:00
" train " : {
" kind " : " train " ,
" title " : " Train " ,
" description " : " Summons a train on the post. " ,
" icon " : " fas fa-train " ,
" color " : " text-pink " ,
" price " : 300
} ,
2022-02-11 23:32:14 +00:00
" scooter " : {
" kind " : " scooter " ,
" title " : " Scooter " ,
" description " : " Summons a scooter on the post. " ,
" icon " : " fas fa-flag-usa " ,
" color " : " text-muted " ,
" price " : 300
} ,
2022-01-01 20:20:15 +00:00
" wholesome " : {
2022-02-16 02:15:17 +00:00
" kind " : " wholesome " ,
" title " : " Wholesome " ,
" description " : " Summons a wholesome marsey on the post. " ,
" icon " : " fas fa-smile-beam " ,
" color " : " text-yellow " ,
" price " : 300
} ,
2022-02-11 23:32:14 +00:00
" tilt " : {
2022-02-16 02:15:17 +00:00
" kind " : " tilt " ,
" title " : " Tilt " ,
" description " : " Tilts the post by 1 degree (up to 4) " ,
" icon " : " fas fa-car-tilt " ,
" color " : " text-blue " ,
" price " : 300
} ,
2021-10-21 15:06:55 +00:00
}
2021-10-15 14:08:27 +00:00
@app.get ( " /shop " )
@app.get ( " /settings/shop " )
@auth_required
def shop ( v ) :
2021-12-15 19:30:26 +00:00
AWARDS = deepcopy ( AWARDS2 )
2021-12-14 21:55:19 +00:00
for val in AWARDS . values ( ) : val [ " owned " ] = 0
2021-10-15 14:08:27 +00:00
2021-11-06 15:52:48 +00:00
for useraward in g . db . query ( AwardRelationship ) . filter ( AwardRelationship . user_id == v . id , AwardRelationship . submission_id == None , AwardRelationship . comment_id == None ) . all ( ) :
2021-11-01 18:56:56 +00:00
if useraward . kind in AWARDS : AWARDS [ useraward . kind ] [ " owned " ] + = 1
2021-10-15 14:08:27 +00:00
2021-10-26 22:52:52 +00:00
if v . patron == 1 : discount = 0.90
elif v . patron == 2 : discount = 0.85
elif v . patron == 3 : discount = 0.80
elif v . patron == 4 : discount = 0.75
elif v . patron == 5 : discount = 0.70
2022-02-18 20:38:07 +00:00
elif v . patron == 6 : discount = 0.65
2022-03-17 08:59:44 +00:00
elif v . patron == 7 : discount = 0.60
2021-10-26 22:52:52 +00:00
else : discount = 1
for badge in [ 69 , 70 , 71 , 72 , 73 ] :
2021-11-01 18:25:10 +00:00
if v . has_badge ( badge ) : discount - = discounts [ badge ]
2021-10-26 22:52:52 +00:00
for val in AWARDS . values ( ) :
2022-02-01 22:59:57 +00:00
val [ " baseprice " ] = int ( val [ " price " ] )
2021-10-26 22:52:52 +00:00
val [ " price " ] = int ( val [ " price " ] * discount )
2021-10-15 14:08:27 +00:00
2022-01-19 05:09:28 +00:00
sales = g . db . query ( func . sum ( User . coins_spent ) ) . scalar ( )
2022-01-14 12:04:35 +00:00
return render_template ( " shop.html " , awards = list ( AWARDS . values ( ) ) , v = v , sales = sales )
2021-10-15 14:08:27 +00:00
@app.post ( " /buy/<award> " )
@auth_required
def buy ( v , award ) :
2022-01-17 18:38:15 +00:00
if award == ' benefactor ' and not request . values . get ( " mb " ) :
2022-01-17 20:29:06 +00:00
return { " error " : " You can only buy the Benefactor award with marseybux. " } , 403
2022-01-17 18:38:15 +00:00
2021-12-15 19:30:26 +00:00
AWARDS = deepcopy ( AWARDS2 )
2021-10-15 14:08:27 +00:00
if award not in AWARDS : abort ( 400 )
price = AWARDS [ award ] [ " price " ]
2021-10-26 22:52:52 +00:00
if v . patron == 1 : discount = 0.90
elif v . patron == 2 : discount = 0.85
elif v . patron == 3 : discount = 0.80
elif v . patron == 4 : discount = 0.75
elif v . patron == 5 : discount = 0.70
2022-02-18 20:38:07 +00:00
elif v . patron == 6 : discount = 0.65
2021-10-26 22:52:52 +00:00
else : discount = 1
for badge in [ 69 , 70 , 71 , 72 , 73 ] :
2021-11-01 18:25:10 +00:00
if v . has_badge ( badge ) : discount - = discounts [ badge ]
2021-10-26 22:52:52 +00:00
price = int ( price * discount )
2021-10-15 14:08:27 +00:00
2021-10-21 22:55:48 +00:00
if request . values . get ( " mb " ) :
if v . procoins < price : return { " error " : " Not enough marseybux. " } , 400
2021-12-10 16:28:16 +00:00
if award == " grass " : return { " error " : " You can ' t buy the grass award with marseybux. " } , 403
2021-10-21 22:55:48 +00:00
v . procoins - = price
else :
if v . coins < price : return { " error " : " Not enough coins. " } , 400
v . coins - = price
v . coins_spent + = price
2021-10-24 18:59:50 +00:00
if v . coins_spent > = 1000000 and not v . has_badge ( 73 ) :
new_badge = Badge ( badge_id = 73 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-24 18:59:50 +00:00
old_badge = v . has_badge ( 72 )
2021-11-01 18:25:10 +00:00
if old_badge : g . db . delete ( old_badge )
2021-10-24 18:59:50 +00:00
elif v . coins_spent > = 500000 and not v . has_badge ( 72 ) :
new_badge = Badge ( badge_id = 72 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-24 18:59:50 +00:00
old_badge = v . has_badge ( 71 )
2021-11-01 18:25:10 +00:00
if old_badge : g . db . delete ( old_badge )
2021-10-24 18:59:50 +00:00
elif v . coins_spent > = 250000 and not v . has_badge ( 71 ) :
2021-12-28 19:32:32 +00:00
2021-10-24 18:59:50 +00:00
new_badge = Badge ( badge_id = 71 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-24 18:59:50 +00:00
old_badge = v . has_badge ( 70 )
2021-11-01 18:25:10 +00:00
if old_badge : g . db . delete ( old_badge )
2021-10-24 18:59:50 +00:00
elif v . coins_spent > = 100000 and not v . has_badge ( 70 ) :
new_badge = Badge ( badge_id = 70 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-24 18:59:50 +00:00
old_badge = v . has_badge ( 69 )
2021-11-01 18:25:10 +00:00
if old_badge : g . db . delete ( old_badge )
2021-10-24 18:59:50 +00:00
elif v . coins_spent > = 10000 and not v . has_badge ( 69 ) :
new_badge = Badge ( badge_id = 69 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-21 22:55:48 +00:00
g . db . add ( v )
2021-10-15 14:08:27 +00:00
2021-12-14 20:57:25 +00:00
if award == " lootbox " :
2021-12-20 20:03:59 +00:00
send_repeatable_notification ( 995 , f " @ { v . username } bought a lootbox! " )
2021-12-14 20:57:25 +00:00
for i in [ 1 , 2 , 3 , 4 , 5 ] :
award = random . choice ( [ " snow " , " gingerbread " , " lights " , " candycane " , " fireplace " ] )
2022-02-13 21:25:09 +00:00
award = AwardRelationship ( user_id = v . id , kind = award )
2021-12-14 20:57:25 +00:00
g . db . add ( award )
g . db . flush ( )
2021-12-14 22:06:54 +00:00
v . lootboxes_bought + = 1
if v . lootboxes_bought == 10 and not v . has_badge ( 76 ) :
new_badge = Badge ( badge_id = 76 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-12-14 22:06:54 +00:00
elif v . lootboxes_bought == 50 and not v . has_badge ( 77 ) :
new_badge = Badge ( badge_id = 77 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-12-14 22:06:54 +00:00
elif v . lootboxes_bought == 150 and not v . has_badge ( 78 ) :
new_badge = Badge ( badge_id = 78 , user_id = v . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-12-14 22:06:54 +00:00
2021-12-14 20:57:25 +00:00
else :
2022-02-13 21:25:09 +00:00
award = AwardRelationship ( user_id = v . id , kind = award )
2021-12-14 20:57:25 +00:00
g . db . add ( award )
2021-10-15 14:08:27 +00:00
2021-12-14 22:06:54 +00:00
g . db . add ( v )
2021-10-15 14:08:27 +00:00
g . db . commit ( )
return { " message " : " Award bought! " }
2022-02-18 08:01:21 +00:00
@app.post ( " /award_post/<pid> " )
2022-01-15 06:31:17 +00:00
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " )
2022-02-08 09:39:41 +00:00
@is_not_permabanned
2021-10-15 14:08:27 +00:00
def award_post ( pid , v ) :
2022-01-16 01:47:21 +00:00
if v . shadowbanned : return render_template ( ' errors/500.html ' , err = True , v = v ) , 500
2021-12-04 20:48:10 +00:00
2021-10-15 14:08:27 +00:00
kind = request . values . get ( " kind " , " " ) . strip ( )
if kind not in AWARDS :
return { " error " : " That award doesn ' t exist. " } , 404
2021-11-06 15:52:48 +00:00
post_award = g . db . query ( AwardRelationship ) . filter (
2022-02-16 02:15:17 +00:00
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
2022-01-02 12:10:01 +00:00
) . first ( )
2021-10-15 14:08:27 +00:00
if not post_award :
return { " error " : " You don ' t have that award. " } , 404
2022-01-02 00:06:46 +00:00
post = g . db . query ( Submission ) . filter_by ( id = pid ) . one_or_none ( )
2021-10-15 14:08:27 +00:00
2021-10-20 21:06:25 +00:00
if not post :
return { " error " : " That post doesn ' t exist. " } , 404
2021-10-15 14:08:27 +00:00
post_award . submission_id = post . id
g . db . add ( post_award )
2022-01-07 01:39:07 +00:00
note = request . values . get ( " note " , " " ) . strip ( )
2022-02-02 00:06:29 +00:00
author = post . author
2022-03-17 16:12:59 +00:00
if author . id == PIZZASHILL_ID :
return { " error " : " Pizzashill is immune to awards. " } , 403
2022-02-02 00:06:29 +00:00
if v . id != author . id :
2022-02-24 13:20:48 +00:00
msg = f " @ { v . username } has given your [post]( { post . shortlink } ) the { AWARDS [ kind ] [ ' title ' ] } Award! "
2022-01-03 10:32:31 +00:00
if note : msg + = f " \n \n > { note } "
2022-02-02 00:06:29 +00:00
send_repeatable_notification ( author . id , msg )
2022-01-17 18:20:42 +00:00
if kind == " benefactor " and author . id == v . id :
return { " error " : " You can ' t use this award on yourself. " } , 400
2021-10-18 19:06:00 +00:00
if kind == " ban " :
2022-02-24 13:20:48 +00:00
link = f " [this post]( { post . shortlink } ) "
2021-10-18 19:06:00 +00:00
if not author . is_suspended :
2021-10-20 19:34:56 +00:00
author . ban ( reason = f " 1-Day ban award used by @ { v . username } on /post/ { post . id } " , days = 1 )
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **a day** for { link } . It sucked and you should feel bad. " )
2022-01-12 01:19:13 +00:00
elif author . unban_utc :
2021-10-27 20:12:16 +00:00
author . unban_utc + = 86400
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **yet another day** for { link } . Seriously man? " )
2021-10-20 22:01:30 +00:00
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
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " Your ban duration has been reduced by 1 day! " )
2021-10-20 22:01:30 +00:00
else :
author . unban_utc = 0
author . is_banned = 0
2021-10-21 18:06:57 +00:00
author . ban_evade = 0
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " You have been unbanned! " )
2021-10-18 19:06:00 +00:00
elif kind == " grass " :
2021-11-18 14:21:19 +00:00
author . is_banned = AUTOJANNY_ID
2021-10-18 20:03:43 +00:00
author . ban_reason = f " grass award used by @ { v . username } on /post/ { post . id } "
2021-12-27 02:09:06 +00:00
author . unban_utc = int ( time . time ( ) ) + 30 * 86400
2022-02-24 13:20:48 +00:00
link = f " [this post]( { post . shortlink } ) "
2022-03-09 01:44:53 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned permanently for { link } . You must [provide the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned! " )
2021-10-20 21:06:25 +00:00
elif kind == " pin " :
2021-12-26 01:03:21 +00:00
if post . stickied and post . stickied_utc :
post . stickied_utc + = 3600
else :
post . stickied = f ' { v . username } (pin award) '
post . stickied_utc = int ( time . time ( ) ) + 3600
2021-10-20 21:06:25 +00:00
g . db . add ( post )
2021-10-20 21:13:30 +00:00
cache . delete_memoized ( frontlist )
2021-10-20 23:37:53 +00:00
elif kind == " unpin " :
2021-12-26 01:03:21 +00:00
if not post . stickied_utc : abort ( 403 )
t = post . stickied_utc - 3600
2021-10-20 23:37:53 +00:00
if time . time ( ) > t :
post . stickied = None
2021-12-26 01:03:21 +00:00
post . stickied_utc = None
2021-10-20 23:37:53 +00:00
cache . delete_memoized ( frontlist )
2021-12-26 01:03:21 +00:00
else : post . stickied_utc = t
2021-10-20 23:37:53 +00:00
g . db . add ( post )
2022-02-12 23:10:29 +00:00
elif kind == " agendaposter " and not ( author . agendaposter and author . agendaposter == 0 ) :
2022-01-22 10:14:15 +00:00
if author . marseyawarded :
return { " error " : " This user is the under the effect of a conflicting award: Marsey award. " } , 404
2022-02-12 23:10:29 +00:00
if author . agendaposter and time . time ( ) < author . agendaposter : author . agendaposter + = 86400
else : author . agendaposter = int ( time . time ( ) ) + 86400
2021-10-21 17:01:25 +00:00
2022-02-19 21:42:55 +00:00
if not author . has_badge ( 28 ) :
badge = Badge ( user_id = author . id , badge_id = 28 )
2021-10-21 17:01:25 +00:00
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-21 20:50:00 +00:00
elif kind == " flairlock " :
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " )
2022-01-11 00:11:34 +00:00
if not new_name and author . flairchanged :
author . flairchanged + = 86400
else :
author . customtitleplain = new_name
author . customtitle = filter_emojis_only ( new_name )
if len ( author . customtitle ) > 1000 : abort ( 403 )
author . flairchanged = int ( time . time ( ) ) + 86400
if not author . has_badge ( 96 ) :
badge = Badge ( user_id = author . id , badge_id = 96 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-11 00:11:34 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-23 15:57:25 +00:00
elif kind == " pause " :
author . mute = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 68 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 68 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-23 15:57:25 +00:00
elif kind == " unpausable " :
author . unmutable = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 67 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 67 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-18 20:02:26 +00:00
elif kind == " marsey " :
2021-11-18 20:58:03 +00:00
if author . marseyawarded : author . marseyawarded + = 86400
2021-12-31 23:45:27 +00:00
else : author . marseyawarded = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 98 ) :
badge = Badge ( user_id = author . id , badge_id = 98 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-18 21:06:34 +00:00
elif kind == " pizzashill " :
2021-11-23 22:49:11 +00:00
if author . bird :
return { " error " : " This user is the under the effect of a conflicting award: Bird Site award. " } , 404
2021-11-18 20:58:03 +00:00
if author . longpost : author . longpost + = 86400
2021-12-31 23:45:27 +00:00
else : author . longpost = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 97 ) :
badge = Badge ( user_id = author . id , badge_id = 97 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-23 22:36:38 +00:00
elif kind == " bird " :
2021-11-23 22:48:23 +00:00
if author . longpost :
return { " error " : " This user is the under the effect of a conflicting award: Pizzashill award. " } , 404
2021-11-23 22:36:38 +00:00
if author . bird : author . bird + = 86400
2021-12-31 23:45:27 +00:00
else : author . bird = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 95 ) :
badge = Badge ( user_id = author . id , badge_id = 95 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-18 19:15:22 +00:00
elif kind == " eye " :
author . eye = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 83 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 83 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-18 20:02:26 +00:00
elif kind == " alt " :
author . alt = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 84 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 84 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-23 22:36:38 +00:00
elif kind == " unblockable " :
author . unblockable = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 87 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 87 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-23 22:36:38 +00:00
for block in g . db . query ( UserBlock ) . filter_by ( target_id = author . id ) . all ( ) : g . db . delete ( block )
2021-12-10 04:58:55 +00:00
elif kind == " fish " :
author . fish = True
2021-12-10 18:17:58 +00:00
if not author . has_badge ( 90 ) :
new_badge = Badge ( badge_id = 90 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-12-31 23:45:27 +00:00
elif kind == " progressivestack " :
if author . progressivestack : author . progressivestack + = 21600
else : author . progressivestack = int ( time . time ( ) ) + 21600
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 94 ) :
badge = Badge ( user_id = author . id , badge_id = 94 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2022-01-17 18:20:42 +00:00
elif kind == " benefactor " :
author . patron = 1
2022-01-29 02:48:34 +00:00
author . patron_utc + = int ( time . time ( ) ) + 2629746
2022-01-17 18:20:42 +00:00
author . procoins + = 2500
if not v . has_badge ( 103 ) :
badge = Badge ( user_id = v . id , badge_id = 103 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-17 18:20:42 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2022-01-31 01:41:04 +00:00
elif kind == " rehab " :
if author . rehab : author . rehab + = 86400
else : author . rehab = int ( time . time ( ) ) + 86400
2022-02-01 16:12:43 +00:00
if not author . has_badge ( 109 ) :
badge = Badge ( user_id = author . id , badge_id = 109 )
2022-01-31 01:41:04 +00:00
g . db . add ( badge )
g . db . flush ( )
2022-02-01 16:12:43 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-15 14:08:27 +00:00
2022-02-02 00:06:29 +00:00
if author . received_award_count : author . received_award_count + = 1
else : author . received_award_count = 1
g . db . add ( author )
2021-10-15 14:08:27 +00:00
g . db . commit ( )
2022-01-19 06:20:05 +00:00
if request . referrer and len ( request . referrer ) > 1 :
2022-01-24 17:37:37 +00:00
if request . referrer == f ' { SITE_FULL } /submit ' : return redirect ( post . permalink )
2022-02-28 00:14:53 +00:00
elif request . referrer . startswith ( SITE_FULL ) : return redirect ( request . referrer )
2022-02-28 00:13:07 +00:00
return redirect ( SITE_FULL )
2021-10-15 14:08:27 +00:00
2022-02-18 08:45:36 +00:00
@app.post ( " /award_comment/<cid> " )
2022-01-15 06:31:17 +00:00
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " )
2022-02-08 09:39:41 +00:00
@is_not_permabanned
2021-10-15 14:08:27 +00:00
def award_comment ( cid , v ) :
2022-01-16 01:47:21 +00:00
if v . shadowbanned : return render_template ( ' errors/500.html ' , err = True , v = v ) , 500
2021-12-04 20:48:10 +00:00
2021-10-15 14:08:27 +00:00
kind = request . values . get ( " kind " , " " ) . strip ( )
if kind not in AWARDS :
return { " error " : " That award doesn ' t exist. " } , 404
2021-11-06 15:52:48 +00:00
comment_award = g . db . query ( AwardRelationship ) . filter (
2022-02-16 02:15:17 +00:00
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
2022-01-02 12:10:01 +00:00
) . first ( )
2021-10-15 14:08:27 +00:00
if not comment_award :
return { " error " : " You don ' t have that award. " } , 404
2022-01-02 00:06:46 +00:00
c = g . db . query ( Comment ) . filter_by ( id = cid ) . one_or_none ( )
2021-10-15 14:08:27 +00:00
2021-10-20 21:06:25 +00:00
if not c :
return { " error " : " That comment doesn ' t exist. " } , 404
2021-10-15 14:08:27 +00:00
comment_award . comment_id = c . id
g . db . add ( comment_award )
2022-01-07 01:39:07 +00:00
note = request . values . get ( " note " , " " ) . strip ( )
2022-02-02 00:06:29 +00:00
author = c . author
2022-03-17 16:12:59 +00:00
if author . id == PIZZASHILL_ID :
return { " error " : " Pizzashill is immune to awards. " } , 403
2022-02-02 00:06:29 +00:00
if v . id != author . id :
2022-02-24 13:20:48 +00:00
msg = f " @ { v . username } has given your [comment]( { c . shortlink } ) the { AWARDS [ kind ] [ ' title ' ] } Award! "
2022-01-03 10:32:31 +00:00
if note : msg + = f " \n \n > { note } "
2022-02-02 00:06:29 +00:00
send_repeatable_notification ( author . id , msg )
2021-10-15 14:08:27 +00:00
2022-01-17 18:20:42 +00:00
if kind == " benefactor " and author . id == v . id :
return { " error " : " You can ' t use this award on yourself. " } , 400
2021-10-18 19:07:52 +00:00
if kind == " ban " :
2022-02-24 13:20:48 +00:00
link = f " [this comment]( { c . shortlink } ) "
2021-10-18 19:07:52 +00:00
if not author . is_suspended :
2021-10-20 19:34:56 +00:00
author . ban ( reason = f " 1-Day ban award used by @ { v . username } on /comment/ { c . id } " , days = 1 )
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **a day** for { link } . It sucked and you should feel bad. " )
2022-01-12 01:19:13 +00:00
elif author . unban_utc :
2021-10-27 20:12:16 +00:00
author . unban_utc + = 86400
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **yet another day** for { link } . Seriously man? " )
2021-10-20 22:01:30 +00:00
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
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " Your ban duration has been reduced by 1 day! " )
2021-10-20 22:01:30 +00:00
else :
author . unban_utc = 0
author . is_banned = 0
2021-10-21 18:06:57 +00:00
author . ban_evade = 0
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " You have been unbanned! " )
2021-10-18 19:07:52 +00:00
elif kind == " grass " :
2021-11-18 14:21:19 +00:00
author . is_banned = AUTOJANNY_ID
2021-10-18 20:43:34 +00:00
author . ban_reason = f " grass award used by @ { v . username } on /comment/ { c . id } "
2021-12-27 02:09:06 +00:00
author . unban_utc = int ( time . time ( ) ) + 30 * 86400
2022-02-24 13:20:48 +00:00
link = f " [this comment]( { c . shortlink } ) "
2022-03-09 01:44:53 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned permanently for { link } . You must [provide the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned! " )
2021-10-21 14:47:27 +00:00
elif kind == " pin " :
2021-12-26 01:03:21 +00:00
if c . is_pinned and c . is_pinned_utc : c . is_pinned_utc + = 3600
else :
c . is_pinned = f ' { v . username } (pin award) '
c . is_pinned_utc = int ( time . time ( ) ) + 3600
2021-10-21 14:47:27 +00:00
g . db . add ( c )
elif kind == " unpin " :
2021-12-26 01:03:21 +00:00
if not c . is_pinned_utc : abort ( 403 )
t = c . is_pinned_utc - 3600
if time . time ( ) > t :
c . is_pinned = None
c . is_pinned_utc = None
else : c . is_pinned_utc = t
2021-10-21 14:47:27 +00:00
g . db . add ( c )
2022-02-12 23:10:29 +00:00
elif kind == " agendaposter " and not ( author . agendaposter and author . agendaposter == 0 ) :
2022-01-22 10:14:15 +00:00
if author . marseyawarded :
return { " error " : " This user is the under the effect of a conflicting award: Marsey award. " } , 404
2022-02-12 23:10:29 +00:00
if author . agendaposter and time . time ( ) < author . agendaposter : author . agendaposter + = 86400
else : author . agendaposter = int ( time . time ( ) ) + 86400
2021-10-21 17:01:25 +00:00
2022-02-19 21:42:55 +00:00
if not author . has_badge ( 28 ) :
badge = Badge ( user_id = author . id , badge_id = 28 )
2021-10-21 17:01:25 +00:00
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-21 20:50:00 +00:00
elif kind == " flairlock " :
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " )
2022-01-11 00:11:34 +00:00
if not new_name and author . flairchanged :
author . flairchanged + = 86400
else :
author . customtitleplain = new_name
author . customtitle = filter_emojis_only ( new_name )
if len ( author . customtitle ) > 1000 : abort ( 403 )
author . flairchanged = int ( time . time ( ) ) + 86400
if not author . has_badge ( 96 ) :
badge = Badge ( user_id = author . id , badge_id = 96 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-11 00:11:34 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-23 16:10:05 +00:00
elif kind == " pause " :
author . mute = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 68 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 68 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-10-23 16:10:05 +00:00
elif kind == " unpausable " :
author . unmutable = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 67 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 67 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-18 20:02:26 +00:00
elif kind == " marsey " :
2021-11-18 20:58:03 +00:00
if author . marseyawarded : author . marseyawarded + = 86400
2021-12-31 23:45:27 +00:00
else : author . marseyawarded = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 98 ) :
badge = Badge ( user_id = author . id , badge_id = 98 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-18 21:06:34 +00:00
elif kind == " pizzashill " :
2021-11-23 22:49:11 +00:00
if author . bird :
return { " error " : " This user is the under the effect of a conflicting award: Bird Site award. " } , 404
2021-11-18 20:58:03 +00:00
if author . longpost : author . longpost + = 86400
2021-12-31 23:45:27 +00:00
else : author . longpost = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 97 ) :
badge = Badge ( user_id = author . id , badge_id = 97 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-23 22:36:38 +00:00
elif kind == " bird " :
2021-11-23 22:48:16 +00:00
if author . longpost :
return { " error " : " This user is the under the effect of a conflicting award: Pizzashill award. " } , 404
2021-11-23 22:36:38 +00:00
if author . bird : author . bird + = 86400
2021-12-31 23:45:27 +00:00
else : author . bird = int ( time . time ( ) ) + 86400
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 95 ) :
badge = Badge ( user_id = author . id , badge_id = 95 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-11-18 19:30:34 +00:00
elif kind == " eye " :
author . eye = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 83 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 83 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-18 20:02:26 +00:00
elif kind == " alt " :
author . alt = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 84 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 84 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-23 22:36:38 +00:00
elif kind == " unblockable " :
author . unblockable = True
2021-11-30 19:13:57 +00:00
if not author . has_badge ( 87 ) :
2021-11-30 19:12:25 +00:00
new_badge = Badge ( badge_id = 87 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-11-23 22:36:38 +00:00
for block in g . db . query ( UserBlock ) . filter_by ( target_id = author . id ) . all ( ) : g . db . delete ( block )
2021-12-10 04:58:55 +00:00
elif kind == " fish " :
author . fish = True
2021-12-10 18:17:58 +00:00
if not author . has_badge ( 90 ) :
new_badge = Badge ( badge_id = 90 , user_id = author . id )
g . db . add ( new_badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2021-12-28 13:51:26 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { new_badge . path } ) \n \n { new_badge . name } " )
2021-12-31 23:45:27 +00:00
elif kind == " progressivestack " :
if author . progressivestack : author . progressivestack + = 21600
else : author . progressivestack = int ( time . time ( ) ) + 21600
2022-01-06 22:28:27 +00:00
if not author . has_badge ( 94 ) :
badge = Badge ( user_id = author . id , badge_id = 94 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-06 22:28:27 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2022-01-17 18:20:42 +00:00
elif kind == " benefactor " :
author . patron = 1
2022-01-29 02:48:34 +00:00
author . patron_utc + = int ( time . time ( ) ) + 2629746
2022-01-17 18:20:42 +00:00
author . procoins + = 2500
if not v . has_badge ( 103 ) :
badge = Badge ( user_id = v . id , badge_id = 103 )
g . db . add ( badge )
2022-01-24 23:49:02 +00:00
g . db . flush ( )
2022-01-17 18:20:42 +00:00
send_notification ( v . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2022-01-31 01:41:04 +00:00
elif kind == " rehab " :
if author . rehab : author . rehab + = 86400
else : author . rehab = int ( time . time ( ) ) + 86400
2022-02-01 16:12:43 +00:00
if not author . has_badge ( 109 ) :
badge = Badge ( user_id = author . id , badge_id = 109 )
2022-01-31 01:41:04 +00:00
g . db . add ( badge )
g . db . flush ( )
2022-02-01 16:12:43 +00:00
send_notification ( author . id , f " @AutoJanny has given you the following profile badge: \n \n ![]( { badge . path } ) \n \n { badge . name } " )
2021-10-23 15:57:25 +00:00
2022-02-02 00:06:29 +00:00
if author . received_award_count : author . received_award_count + = 1
else : author . received_award_count = 1
g . db . add ( author )
2021-10-15 14:08:27 +00:00
g . db . commit ( )
2022-02-28 00:14:53 +00:00
if request . referrer and len ( request . referrer ) > 1 and request . referrer . startswith ( SITE_FULL ) :
2022-01-17 11:06:12 +00:00
return redirect ( request . referrer )
2022-02-28 00:13:07 +00:00
return redirect ( SITE_FULL )
2022-01-24 01:20:29 +00:00
@app.get ( " /admin/awards " )
@admin_level_required ( 2 )
def admin_userawards_get ( v ) :
2022-01-27 20:25:48 +00:00
if request . host == ' pcmemes.net ' and v . admin_level < 3 : abort ( 403 )
2022-01-24 01:20:29 +00:00
if v . admin_level != 3 :
return render_template ( " admin/awards.html " , awards = list ( AWARDS3 . values ( ) ) , v = v )
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v )
@app.post ( " /admin/awards " )
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " )
@admin_level_required ( 2 )
def admin_userawards_post ( v ) :
2022-01-27 20:25:48 +00:00
if request . host == ' pcmemes.net ' and v . admin_level < 3 : abort ( 403 )
2022-01-24 01:20:29 +00:00
try : u = request . values . get ( " username " ) . strip ( )
except : abort ( 404 )
u = get_user ( u , graceful = False , v = v )
notify_awards = { }
for key , value in request . values . items ( ) :
if key not in AWARDS : continue
if value :
if int ( value ) > 10 : abort ( 403 )
if int ( value ) : notify_awards [ key ] = int ( value )
for x in range ( int ( value ) ) :
award = AwardRelationship (
user_id = u . id ,
kind = key
)
g . db . add ( award )
if v . id != u . id :
2022-02-22 11:43:38 +00:00
text = f " @ { v . username } has given the following awards: \n \n "
2022-01-24 01:20:29 +00:00
for key , value in notify_awards . items ( ) :
text + = f " - ** { value } ** { AWARDS [ key ] [ ' title ' ] } { ' Awards ' if value != 1 else ' Award ' } \n "
send_repeatable_notification ( u . id , text )
note = " "
for key , value in notify_awards . items ( ) :
note + = f " { value } { AWARDS [ key ] [ ' title ' ] } , "
if len ( note ) > 256 : return { " error " : " You ' re giving too many awards at the same time! " }
ma = ModAction (
kind = " grant_awards " ,
user_id = v . id ,
target_user_id = u . id ,
_note = note [ : - 2 ]
)
g . db . add ( ma )
g . db . commit ( )
if v . admin_level != 3 : return render_template ( " admin/awards.html " , awards = list ( AWARDS3 . values ( ) ) , v = v )
2022-02-01 04:20:31 +00:00
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v )