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-10-21 20:50:00 +00:00
from files . helpers . sanitize import filter_title
2021-10-15 14:08:27 +00:00
2021-11-01 18:25:10 +00:00
discounts = {
69 : 0.02 ,
70 : 0.04 ,
71 : 0.06 ,
72 : 0.08 ,
73 : 0.10 ,
}
2021-10-21 15:06:55 +00:00
AWARDS2 = {
" ban " : {
" kind " : " ban " ,
" title " : " 1-Day Ban " ,
2021-10-27 00:37:34 +00:00
" description " : " Bans the recipient for a day. " ,
2021-10-21 15:06:55 +00:00
" icon " : " fas fa-gavel " ,
" color " : " text-danger " ,
" price " : 3000
} ,
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 " ,
" price " : 500
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 " ,
" price " : 500
} ,
}
2021-10-15 14:08:27 +00:00
@app.get ( " /shop " )
@app.get ( " /settings/shop " )
@auth_required
def shop ( v ) :
2021-11-02 21:29:53 +00:00
AWARDS = {
" shit " : {
" kind " : " shit " ,
" title " : " Shit " ,
" description " : " Makes flies swarm the post. " ,
" icon " : " fas fa-poop " ,
" color " : " text-black-50 " ,
" owned " : 0 ,
" price " : 500
} ,
" fireflies " : {
" kind " : " fireflies " ,
" title " : " Fireflies " ,
" description " : " Makes fireflies swarm the post. " ,
" icon " : " fas fa-sparkles " ,
" color " : " text-warning " ,
" owned " : 0 ,
" price " : 500
} ,
" train " : {
" kind " : " train " ,
" title " : " Train " ,
" description " : " Summons a train on the post. " ,
" icon " : " fas fa-train " ,
" color " : " text-pink " ,
" owned " : 0 ,
" price " : 500
} ,
" pin " : {
" kind " : " pin " ,
" title " : " 1-Hour Pin " ,
" description " : " Pins the post/comment. " ,
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-warning " ,
" owned " : 0 ,
" price " : 750
} ,
" unpin " : {
" kind " : " unpin " ,
" title " : " 1-Hour Unpin " ,
" description " : " Removes 1 hour from the pin duration of the post/comment. " ,
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-black " ,
" owned " : 0 ,
" price " : 1000
} ,
" flairlock " : {
" kind " : " flairlock " ,
" title " : " 1-Day Flairlock " ,
" description " : " Sets a flair for the recipient and locks it or 24 hours. " ,
" icon " : " fas fa-lock " ,
" color " : " text-black " ,
" owned " : 0 ,
" price " : 1250
} ,
" agendaposter " : {
" kind " : " agendaposter " ,
" title " : " Agendaposter " ,
" description " : " Forces the agendaposter theme on the recipient for 24 hours. " ,
" icon " : " fas fa-snooze " ,
" color " : " text-purple " ,
" owned " : 0 ,
" price " : 2500
} ,
" marsey " : {
" kind " : " marsey " ,
" title " : " Marsey " ,
" description " : " Makes the recipient unable to post/comment anything but marsey emojis for 24 hours. " ,
" icon " : " fas fa-cat " ,
" color " : " text-orange " ,
" owned " : 0 ,
" price " : 3000
} ,
" ban " : {
" kind " : " ban " ,
" title " : " 1-Day Ban " ,
" description " : " Bans the recipient for a day. " ,
" icon " : " fas fa-gavel " ,
" color " : " text-danger " ,
" owned " : 0 ,
" price " : 3000
} ,
" unban " : {
" kind " : " unban " ,
" title " : " 1-Day Unban " ,
" description " : " Removes 1 day from the ban duration of the recipient. " ,
" icon " : " fas fa-gavel " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 3500
} ,
" grass " : {
" kind " : " grass " ,
" title " : " Grass " ,
" description " : " Ban the recipient permanently (must provide a timestamped picture of them touching grass to the admins to get unbanned) " ,
" icon " : " fas fa-seedling " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 10000
} ,
" pause " : {
" kind " : " pause " ,
" title " : " Pause " ,
" description " : " Gives the recipient the ability to pause profile anthems. " ,
" icon " : " fas fa-volume-mute " ,
" color " : " text-danger " ,
" owned " : 0 ,
" price " : 20000
} ,
" unpausable " : {
" kind " : " unpausable " ,
" title " : " Unpausable " ,
" description " : " Makes the profile anthem of the recipient unpausable. " ,
" icon " : " fas fa-volume " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 40000
} ,
}
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
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 ( ) :
val [ " price " ] = int ( val [ " price " ] * discount )
2021-10-15 14:08:27 +00:00
2021-11-06 15:52:48 +00:00
sales = g . db . query ( Vote . id ) . count ( ) + g . db . query ( CommentVote . id ) . count ( ) - g . db . query ( func . sum ( User . coins ) ) . scalar ( )
2021-10-22 23:50:00 +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 ) :
2021-11-02 21:29:53 +00:00
AWARDS = {
" shit " : {
" kind " : " shit " ,
" title " : " Shit " ,
" description " : " Makes flies swarm the post. " ,
" icon " : " fas fa-poop " ,
" color " : " text-black-50 " ,
" price " : 500
} ,
" fireflies " : {
" kind " : " fireflies " ,
" title " : " Fireflies " ,
" description " : " Makes fireflies swarm the post. " ,
" icon " : " fas fa-sparkles " ,
" color " : " text-warning " ,
" price " : 500
} ,
" train " : {
" kind " : " train " ,
" title " : " Train " ,
" description " : " Summons a train on the post. " ,
" icon " : " fas fa-train " ,
" color " : " text-pink " ,
" price " : 500
} ,
" pin " : {
" kind " : " pin " ,
" title " : " 1-Hour Pin " ,
" description " : " Pins the post/comment. " ,
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-warning " ,
" price " : 750
} ,
" unpin " : {
" kind " : " unpin " ,
" title " : " 1-Hour Unpin " ,
" description " : " Removes 1 hour from the pin duration of the post/comment. " ,
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-black " ,
" price " : 1000
} ,
" flairlock " : {
" kind " : " flairlock " ,
" title " : " 1-Day Flairlock " ,
" description " : " Sets a flair for the recipient and locks it or 24 hours. " ,
" icon " : " fas fa-lock " ,
" color " : " text-black " ,
" price " : 1250
} ,
" agendaposter " : {
" kind " : " agendaposter " ,
" title " : " Agendaposter " ,
" description " : " Forces the agendaposter theme on the recipient for 24 hours. " ,
" icon " : " fas fa-snooze " ,
" color " : " text-purple " ,
" price " : 2500
} ,
" marsey " : {
" kind " : " marsey " ,
" title " : " Marsey " ,
" description " : " Makes the recipient unable to post/comment anything but marsey emojis for 24 hours. " ,
" icon " : " fas fa-cat " ,
" color " : " text-orange " ,
" price " : 3000
} ,
" ban " : {
" kind " : " ban " ,
" title " : " 1-Day Ban " ,
" description " : " Bans the recipient for a day. " ,
" icon " : " fas fa-gavel " ,
" color " : " text-danger " ,
" price " : 3000
} ,
" unban " : {
" kind " : " unban " ,
" title " : " 1-Day Unban " ,
" description " : " Removes 1 day from the ban duration of the recipient. " ,
" icon " : " fas fa-gavel " ,
" color " : " text-success " ,
" price " : 3500
} ,
" grass " : {
" kind " : " grass " ,
" title " : " Grass " ,
" description " : " Ban the recipient permanently (must provide a timestamped picture of them touching grass to the admins to get unbanned) " ,
" icon " : " fas fa-seedling " ,
" color " : " text-success " ,
" price " : 10000
} ,
" pause " : {
" kind " : " pause " ,
" title " : " Pause " ,
" description " : " Gives the recipient the ability to pause profile anthems. " ,
" icon " : " fas fa-volume-mute " ,
" color " : " text-danger " ,
" price " : 20000
} ,
" unpausable " : {
" kind " : " unpausable " ,
" title " : " Unpausable " ,
" description " : " Makes the profile anthem of the recipient unpausable. " ,
" icon " : " fas fa-volume " ,
" color " : " text-success " ,
" price " : 40000
} ,
}
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
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
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 )
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 )
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 ) :
new_badge = Badge ( badge_id = 71 , user_id = v . id )
g . db . add ( new_badge )
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 )
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 )
2021-10-21 22:55:48 +00:00
g . db . add ( v )
2021-10-15 14:08:27 +00:00
2021-10-21 22:55:48 +00:00
g . db . add ( v )
2021-10-16 10:16:59 +00:00
g . db . flush ( )
2021-11-06 15:52:48 +00:00
thing = g . db . query ( AwardRelationship ) . order_by ( AwardRelationship . id . desc ( ) ) . first ( ) . id
2021-10-15 14:08:27 +00:00
thing + = 1
award = AwardRelationship ( id = thing , user_id = v . id , kind = award )
g . db . add ( award )
g . db . commit ( )
return { " message " : " Award bought! " }
@app.post ( " /post/<pid>/awards " )
@limiter.limit ( " 1/second " )
@auth_required
def award_post ( pid , v ) :
if v . is_suspended and v . unban_utc == 0 : return { " error " : " forbidden. " } , 403
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 (
2021-10-15 14:08:27 +00:00
and_ (
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
)
) . first ( )
if not post_award :
return { " error " : " You don ' t have that award. " } , 404
2021-11-06 15:52:48 +00:00
post = g . db . query ( Submission ) . filter_by ( id = pid ) . first ( )
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
2021-11-06 15:52:48 +00:00
existing_award = g . db . query ( AwardRelationship ) . filter (
2021-10-15 14:08:27 +00:00
and_ (
AwardRelationship . submission_id == post . id ,
AwardRelationship . user_id == v . id ,
AwardRelationship . kind == kind
)
) . first ( )
post_award . submission_id = post . id
g . db . add ( post_award )
msg = f " @ { v . username } has given your [post]( { post . permalink } ) the { AWARDS [ kind ] [ ' title ' ] } Award! "
note = request . values . get ( " note " , " " ) . strip ( )
2021-10-18 19:06:00 +00:00
if note : msg + = f " \n \n > { note } "
2021-10-15 14:08:27 +00:00
2021-10-23 16:10:05 +00:00
send_notification ( post . author . id , msg )
2021-10-15 14:08:27 +00:00
2021-10-21 17:01:25 +00:00
author = post . author
2021-10-18 19:06:00 +00:00
if kind == " ban " :
2021-10-18 19:07:52 +00:00
link = f " [this post]( { post . permalink } ) "
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 )
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " Your account has been suspended for a day for { link } . It sucked and you should feel bad. " )
2021-10-18 19:06:00 +00:00
elif author . unban_utc > 0 :
2021-10-27 20:12:16 +00:00
author . unban_utc + = 86400
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " Your account has been suspended 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
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " 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
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " You have been unbanned! " )
2021-10-18 19:06:00 +00:00
elif kind == " grass " :
author . is_banned = AUTOJANNY_ACCOUNT
2021-10-18 20:03:43 +00:00
author . ban_reason = f " grass award used by @ { v . username } on /post/ { post . id } "
2021-10-18 19:07:52 +00:00
link = f " [this post]( { post . permalink } ) "
2021-10-23 16:10:05 +00:00
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! " )
2021-10-20 21:06:25 +00:00
elif kind == " pin " :
2021-10-20 23:18:58 +00:00
if post . stickied and post . stickied . startswith ( " t: " ) : t = int ( post . stickied [ 2 : ] ) + 3600
2021-10-20 21:06:25 +00:00
else : t = int ( time . time ( ) ) + 3600
post . stickied = f " t: { t } "
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 " :
if not ( post . stickied and post . stickied . startswith ( " t: " ) ) : abort ( 403 )
t = int ( post . stickied [ 2 : ] ) - 3600
if time . time ( ) > t :
post . stickied = None
cache . delete_memoized ( frontlist )
else : post . stickied = f " t: { t } "
g . db . add ( post )
2021-10-21 17:01:25 +00:00
elif kind == " agendaposter " and not ( author . agendaposter and author . agendaposter_expires_utc == 0 ) :
if author . agendaposter_expires_utc and time . time ( ) < author . agendaposter_expires_utc : author . agendaposter_expires_utc + = 86400
else : author . agendaposter_expires_utc = time . time ( ) + 86400
author . agendaposter = True
if not author . has_badge ( 26 ) :
badge = Badge ( user_id = author . id , badge_id = 26 )
g . db . add ( badge )
2021-10-21 20:50:00 +00:00
elif kind == " flairlock " :
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " )
author . customtitleplain = new_name
author . customtitle = filter_title ( new_name )
if len ( author . customtitle ) > 1000 : abort ( 403 )
author . flairchanged = time . time ( ) + 86400
2021-10-23 15:57:25 +00:00
elif kind == " pause " :
author . mute = True
2021-10-23 16:10:05 +00:00
send_notification ( 995 , f " @ { v . username } bought { kind } award! " )
2021-10-24 18:59:50 +00:00
new_badge = Badge ( badge_id = 68 , user_id = author . id )
g . db . add ( new_badge )
2021-10-23 15:57:25 +00:00
elif kind == " unpausable " :
author . unmutable = True
2021-10-23 16:10:05 +00:00
send_notification ( 995 , f " @ { v . username } bought { kind } award! " )
2021-10-24 18:59:50 +00:00
new_badge = Badge ( badge_id = 67 , user_id = author . id )
g . db . add ( new_badge )
2021-10-27 00:37:34 +00:00
elif kind == " marsey " :
2021-10-27 20:12:16 +00:00
author . marseyawarded = time . time ( ) + 86400
2021-10-15 14:08:27 +00:00
post . author . received_award_count + = 1
g . db . add ( post . author )
g . db . commit ( )
if request . referrer and len ( request . referrer ) > 1 : return redirect ( request . referrer )
else : return redirect ( " / " )
@app.post ( " /comment/<cid>/awards " )
@limiter.limit ( " 1/second " )
@auth_required
def award_comment ( cid , v ) :
if v . is_suspended and v . unban_utc == 0 : return { " error " : " forbidden " } , 403
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 (
2021-10-15 14:08:27 +00:00
and_ (
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
)
) . first ( )
if not comment_award :
return { " error " : " You don ' t have that award. " } , 404
2021-11-06 15:52:48 +00:00
c = g . db . query ( Comment ) . filter_by ( id = cid ) . first ( )
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
2021-11-06 15:52:48 +00:00
existing_award = g . db . query ( AwardRelationship ) . filter (
2021-10-15 14:08:27 +00:00
and_ (
AwardRelationship . comment_id == c . id ,
AwardRelationship . user_id == v . id ,
AwardRelationship . kind == kind
)
) . first ( )
comment_award . comment_id = c . id
g . db . add ( comment_award )
msg = f " @ { v . username } has given your [comment]( { c . permalink } ) the { AWARDS [ kind ] [ ' title ' ] } Award! "
note = request . values . get ( " note " , " " ) . strip ( )
2021-10-20 21:06:25 +00:00
if note : msg + = f " \n \n > { note } "
2021-10-15 14:08:27 +00:00
2021-10-23 16:10:05 +00:00
send_notification ( c . author . id , msg )
2021-10-21 17:01:25 +00:00
author = c . author
2021-10-15 14:08:27 +00:00
2021-10-18 19:07:52 +00:00
if kind == " ban " :
2021-10-18 20:43:34 +00:00
link = f " [this comment]( { c . permalink } ) "
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 )
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " Your account has been suspended for a day for { link } . It sucked and you should feel bad. " )
2021-10-18 19:07:52 +00:00
elif author . unban_utc > 0 :
2021-10-27 20:12:16 +00:00
author . unban_utc + = 86400
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " Your account has been suspended 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
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " 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
2021-10-23 16:10:05 +00:00
send_notification ( author . id , f " You have been unbanned! " )
2021-10-18 19:07:52 +00:00
elif kind == " grass " :
author . is_banned = AUTOJANNY_ACCOUNT
2021-10-18 20:43:34 +00:00
author . ban_reason = f " grass award used by @ { v . username } on /comment/ { c . id } "
link = f " [this comment]( { c . permalink } ) "
2021-10-23 16:10:05 +00:00
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! " )
2021-10-21 14:47:27 +00:00
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
c . is_pinned = f " t: { t } "
g . db . add ( c )
elif kind == " unpin " :
if not ( c . is_pinned and c . is_pinned . startswith ( " t: " ) ) : abort ( 403 )
t = int ( c . is_pinned [ 2 : ] ) - 3600
if time . time ( ) > t : c . is_pinned = None
else : c . is_pinned = f " t: { t } "
g . db . add ( c )
2021-10-21 17:01:25 +00:00
elif kind == " agendaposter " and not ( author . agendaposter and author . agendaposter_expires_utc == 0 ) :
if author . agendaposter_expires_utc and time . time ( ) < author . agendaposter_expires_utc : author . agendaposter_expires_utc + = 86400
else : author . agendaposter_expires_utc = time . time ( ) + 86400
author . agendaposter = True
if not author . has_badge ( 26 ) :
badge = Badge ( user_id = author . id , badge_id = 26 )
g . db . add ( badge )
2021-10-21 20:50:00 +00:00
elif kind == " flairlock " :
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " )
author . customtitleplain = new_name
author . customtitle = filter_title ( new_name )
if len ( author . customtitle ) > 1000 : abort ( 403 )
author . flairchanged = time . time ( ) + 86400
2021-10-23 16:10:05 +00:00
elif kind == " pause " :
author . mute = True
send_notification ( 995 , f " @ { v . username } bought { kind } award! " )
2021-10-24 18:59:50 +00:00
new_badge = Badge ( badge_id = 68 , user_id = author . id )
g . db . add ( new_badge )
2021-10-23 16:10:05 +00:00
elif kind == " unpausable " :
author . unmutable = True
send_notification ( 995 , f " @ { v . username } bought { kind } award! " )
2021-10-24 18:59:50 +00:00
new_badge = Badge ( badge_id = 67 , user_id = author . id )
g . db . add ( new_badge )
2021-10-27 00:37:34 +00:00
elif kind == " marsey " :
2021-10-27 20:12:16 +00:00
author . marseyawarded = time . time ( ) + 86400
2021-10-23 15:57:25 +00:00
2021-10-15 14:08:27 +00:00
c . author . received_award_count + = 1
g . db . add ( c . author )
g . db . commit ( )
if request . referrer and len ( request . referrer ) > 1 : return redirect ( request . referrer )
else : return redirect ( " / " )
2021-10-20 14:37:46 +00:00
@app.get ( " /admin/awards " )
@admin_level_required ( 6 )
2021-10-15 14:08:27 +00:00
def admin_userawards_get ( v ) :
2021-10-27 23:51:08 +00:00
if request . host == ' rdrama.net ' and v . id not in [ 1 , 28 , 995 , 2513 ] : render_template ( " admin/awards.html " , awards = list ( AWARDS2 . values ( ) ) , v = v )
2021-10-27 21:08:58 +00:00
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v )
2021-10-15 14:08:27 +00:00
2021-10-20 14:37:46 +00:00
@app.post ( " /admin/awards " )
2021-10-15 14:08:27 +00:00
@limiter.limit ( " 1/second " )
@auth_required
@validate_formkey
def admin_userawards_post ( v ) :
2021-10-27 20:12:16 +00:00
if v . admin_level < 6 : abort ( 403 )
2021-10-15 14:08:27 +00:00
try : u = request . values . get ( " username " ) . strip ( )
except : abort ( 404 )
u = get_user ( u , graceful = False , v = v )
notify_awards = { }
2021-11-06 15:52:48 +00:00
latest = g . db . query ( AwardRelationship ) . order_by ( AwardRelationship . id . desc ( ) ) . first ( )
2021-10-15 14:08:27 +00:00
thing = latest . id
for key , value in request . values . items ( ) :
2021-10-21 17:01:25 +00:00
if key not in AWARDS : continue
2021-10-15 14:08:27 +00:00
if value :
2021-11-11 13:10:45 +00:00
if int ( value ) > 10 : abort ( 403 )
2021-10-15 14:08:27 +00:00
2021-10-27 20:12:16 +00:00
if int ( value ) > 0 : notify_awards [ key ] = int ( value )
2021-10-15 14:08:27 +00:00
for x in range ( int ( value ) ) :
thing + = 1
award = AwardRelationship (
id = thing ,
user_id = u . id ,
kind = key
)
g . db . add ( award )
text = " You were given the following awards: \n \n "
2021-10-27 20:12:16 +00:00
for key , value in notify_awards . items ( ) : text + = f " - ** { value } ** { AWARDS [ key ] [ ' title ' ] } { ' Awards ' if value != 1 else ' Award ' } \n "
2021-10-15 14:08:27 +00:00
2021-10-23 16:10:05 +00:00
send_notification ( u . id , text )
2021-10-15 14:08:27 +00:00
g . db . commit ( )
2021-10-27 23:51:08 +00:00
if request . host == ' rdrama.net ' and v . id not in [ 1 , 28 , 995 , 2513 ] : render_template ( " admin/awards.html " , awards = list ( AWARDS2 . values ( ) ) , v = v )
2021-10-27 21:08:58 +00:00
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v )
2021-10-26 22:30:06 +00:00
@app.get ( " /api/shop/items " )
@auth_required
def items ( v ) :
AWARDS = {
" shit " : {
" kind " : " shit " ,
" title " : " Shit " ,
2021-11-01 18:25:10 +00:00
" description " : " Makes flies swarm the post. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-poop " ,
" color " : " text-black-50 " ,
" owned " : 0 ,
" price " : 500
} ,
" fireflies " : {
" kind " : " fireflies " ,
" title " : " Fireflies " ,
2021-11-01 18:25:10 +00:00
" description " : " Makes fireflies swarm the post. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-sparkles " ,
" color " : " text-warning " ,
" owned " : 0 ,
" price " : 500
} ,
" train " : {
" kind " : " train " ,
" title " : " Train " ,
" description " : " Summons a train on the post. " ,
" icon " : " fas fa-train " ,
" color " : " text-pink " ,
" owned " : 0 ,
" price " : 500
} ,
" pin " : {
" kind " : " pin " ,
" title " : " 1-Hour Pin " ,
2021-11-01 18:25:10 +00:00
" description " : " Pins the post/comment. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-warning " ,
" owned " : 0 ,
" price " : 750
} ,
" unpin " : {
" kind " : " unpin " ,
" title " : " 1-Hour Unpin " ,
2021-11-01 18:25:10 +00:00
" description " : " Removes 1 hour from the pin duration of the post/comment. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-thumbtack fa-rotate--45 " ,
" color " : " text-black " ,
" owned " : 0 ,
" price " : 1000
} ,
" flairlock " : {
" kind " : " flairlock " ,
" title " : " 1-Day Flairlock " ,
2021-10-27 00:37:34 +00:00
" description " : " Sets a flair for the recipient and locks it or 24 hours. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-lock " ,
" color " : " text-black " ,
" owned " : 0 ,
" price " : 1250
} ,
" agendaposter " : {
" kind " : " agendaposter " ,
" title " : " Agendaposter " ,
2021-10-27 00:37:34 +00:00
" description " : " Forces the agendaposter theme on the recipient for 24 hours. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-snooze " ,
" color " : " text-purple " ,
" owned " : 0 ,
2021-10-27 22:19:53 +00:00
" price " : 2500
2021-10-26 22:30:06 +00:00
} ,
2021-10-27 00:37:34 +00:00
" marsey " : {
" kind " : " marsey " ,
" title " : " Marsey " ,
" description " : " Makes the recipient unable to post/comment anything but marsey emojis for 24 hours. " ,
" icon " : " fas fa-cat " ,
" color " : " text-orange " ,
" owned " : 0 ,
" price " : 3000
} ,
2021-10-26 22:30:06 +00:00
" ban " : {
" kind " : " ban " ,
" title " : " 1-Day Ban " ,
2021-10-27 00:37:34 +00:00
" description " : " Bans the recipient for a day. " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-gavel " ,
" color " : " text-danger " ,
" owned " : 0 ,
" price " : 3000
} ,
" unban " : {
" kind " : " unban " ,
" title " : " 1-Day Unban " ,
" description " : " Removes 1 day from the ban duration of the recipient. " ,
" icon " : " fas fa-gavel " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 3500
} ,
" grass " : {
" kind " : " grass " ,
" title " : " Grass " ,
2021-10-27 00:37:34 +00:00
" description " : " Ban the recipient permanently (must provide a timestamped picture of them touching grass to the admins to get unbanned) " ,
2021-10-26 22:30:06 +00:00
" icon " : " fas fa-seedling " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 10000
} ,
" pause " : {
" kind " : " pause " ,
" title " : " Pause " ,
" description " : " Gives the recipient the ability to pause profile anthems. " ,
" icon " : " fas fa-volume-mute " ,
" color " : " text-danger " ,
" owned " : 0 ,
" price " : 20000
} ,
" unpausable " : {
" kind " : " unpausable " ,
" title " : " Unpausable " ,
" description " : " Makes the profile anthem of the recipient unpausable. " ,
" icon " : " fas fa-volume " ,
" color " : " text-success " ,
" owned " : 0 ,
" price " : 40000
} ,
}
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 ( ) : AWARDS [ useraward . kind ] [ " owned " ] + = 1
2021-10-26 22:30:06 +00:00
2021-10-27 00:37:34 +00:00
if v . patron == 1 : discount = 0.10
elif v . patron == 2 : discount = 0.15
elif v . patron == 3 : discount = 0.20
elif v . patron == 4 : discount = 0.25
elif v . patron == 5 : discount = 0.30
else : discount = 0
2021-10-26 22:30:06 +00:00
2021-10-26 22:52:52 +00:00
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
2021-10-27 00:37:34 +00:00
for val in AWARDS . values ( ) : val [ " discount " ] = discount
2021-10-26 22:52:52 +00:00
return AWARDS