2022-06-15 19:33:21 +00:00
from flask import g
from files . classes . badges import Badge
from files . helpers . alerts import send_repeatable_notification
2022-07-08 11:44:17 +00:00
from files . helpers . const import *
from files . helpers . get import *
from files . helpers . sanitize import *
import random
2022-07-08 12:40:07 +00:00
from urllib . parse import quote
2022-07-08 11:44:17 +00:00
2022-09-21 20:27:12 +00:00
def badge_grant ( user , badge_id , description = None , url = None , notify = True ) :
2022-06-15 21:17:31 +00:00
assert user != None
2022-06-15 20:29:25 +00:00
if user . has_badge ( badge_id ) :
2022-06-15 20:08:26 +00:00
return
2022-06-06 04:07:38 +00:00
badge = Badge (
2022-06-15 20:08:26 +00:00
badge_id = int ( badge_id ) ,
user_id = user . id ,
description = description ,
url = url ,
2022-06-06 04:07:38 +00:00
)
g . db . add ( badge )
2022-08-17 17:57:32 +00:00
g . db . flush ( )
2022-06-15 19:33:21 +00:00
2022-09-21 20:27:12 +00:00
if notify :
send_repeatable_notification ( user . id ,
f " @AutoJanny has given you the following profile badge: \n \n " +
f " ![]( { badge . path } ) \n \n ** { badge . name } ** \n \n { badge . badge . description } " )
2022-07-08 11:44:17 +00:00
2022-07-08 12:40:07 +00:00
def archiveorg ( url ) :
2022-09-26 04:01:25 +00:00
try : requests . get ( f ' https://web.archive.org/save/ { url } ' , headers = { ' User-Agent ' : ' Mozilla/4.0 (compatible; MSIE 5.5; Windows NT) ' } , timeout = 100 )
2022-09-03 14:24:16 +00:00
except : pass
2022-09-03 03:10:14 +00:00
2022-09-03 18:05:00 +00:00
def archive_url ( url ) :
2022-09-03 03:10:14 +00:00
gevent . spawn ( archiveorg , url )
if url . startswith ( ' https://twitter.com/ ' ) :
2022-09-29 05:36:10 +00:00
url = url . replace ( ' https://twitter.com/ ' , ' https://nitter.lacontrevoie.fr/ ' )
2022-09-03 03:10:14 +00:00
gevent . spawn ( archiveorg , url )
if url . startswith ( ' https://instagram.com/ ' ) :
2022-09-03 19:37:20 +00:00
url = url . replace ( ' https://instagram.com/ ' , ' https://imginn.com/ ' )
2022-09-03 03:10:14 +00:00
gevent . spawn ( archiveorg , url )
2022-07-08 12:40:07 +00:00
2022-07-08 11:44:17 +00:00
def execute_snappy ( post , v ) :
snappy = get_account ( SNAPPY_ID )
if post . sub == ' dankchristianmemes ' or post . sub == ' truth ' :
body = random . choice ( christian_emojis )
elif v . id == CARP_ID :
if random . random ( ) < 0.02 : body = " i love you carp "
2022-08-25 23:40:57 +00:00
elif random . random ( ) < 0.02 : body = " ![](/images/16614707883108485.webp) "
2022-07-08 11:44:17 +00:00
else : body = " :#marseyfuckoffcarp: "
elif v . id == LAWLZ_ID :
if random . random ( ) < 0.5 : body = " wow, this lawlzpost sucks! "
else : body = " wow, a good lawlzpost for once! "
2022-08-15 05:10:15 +00:00
elif not SNAPPY_MARSEYS and not SNAPPY_QUOTES :
2022-07-09 10:50:53 +00:00
body = " "
2022-07-08 11:44:17 +00:00
else :
2022-08-15 05:10:15 +00:00
if SNAPPY_MARSEYS and SNAPPY_QUOTES :
if random . random ( ) < 0.5 : SNAPPY_CHOICES = SNAPPY_MARSEYS
else : SNAPPY_CHOICES = SNAPPY_QUOTES
elif SNAPPY_MARSEYS : SNAPPY_CHOICES = SNAPPY_MARSEYS
elif SNAPPY_QUOTES : SNAPPY_CHOICES = SNAPPY_QUOTES
body = random . choice ( SNAPPY_CHOICES ) . strip ( )
2022-07-08 11:44:17 +00:00
if body . startswith ( ' ▼ ' ) :
body = body [ 1 : ]
vote = Vote ( user_id = SNAPPY_ID ,
vote_type = - 1 ,
submission_id = post . id ,
real = True
)
g . db . add ( vote )
post . downvotes + = 1
if body . startswith ( ' OP is a Trump supporter ' ) :
flag = Flag ( post_id = post . id , user_id = SNAPPY_ID , reason = ' Trump supporter ' )
g . db . add ( flag )
elif body . startswith ( ' You had your chance. Downvoted and reported ' ) :
flag = Flag ( post_id = post . id , user_id = SNAPPY_ID , reason = ' Retard ' )
g . db . add ( flag )
elif body . startswith ( ' ▲ ' ) :
body = body [ 1 : ]
vote = Vote ( user_id = SNAPPY_ID ,
vote_type = 1 ,
submission_id = post . id ,
real = True
)
g . db . add ( vote )
post . upvotes + = 1
body + = " \n \n "
2022-09-23 12:01:42 +00:00
if post . url and not post . url . startswith ( SITE_FULL ) and not post . url . startswith ( ' / ' ) and not post . url . startswith ( ' https://rdrama.org/ ' ) :
2022-07-08 11:44:17 +00:00
if post . url . startswith ( ' https://old.reddit.com/r/ ' ) :
rev = post . url . replace ( ' https://old.reddit.com/ ' , ' ' )
rev = f " * [unddit.com](https://unddit.com/ { rev } ) \n "
elif post . url . startswith ( " https://old.reddit.com/u/ " ) :
rev = post . url . replace ( ' https://old.reddit.com/u/ ' , ' ' )
2022-07-15 13:00:51 +00:00
rev = f " * [camas.unddit.com](https://camas.unddit.com/reddit-search/# \u007b \" author \" : \" { rev } \" , \" resultSize \" :100 \u007d ) \n "
2022-07-08 11:44:17 +00:00
else : rev = ' '
2022-09-22 20:45:26 +00:00
body + = f " Snapshots: \n \n { rev } * [archive.org](https://web.archive.org/ { post . url } ) \n * [archive.ph](https://archive.ph/?url= { quote ( post . url ) } &run=1) (click to archive) \n * [ghostarchive.org](https://ghostarchive.org/search?term= { quote ( post . url ) } ) (click to archive) \n \n "
archive_url ( post . url )
2022-08-15 17:45:43 +00:00
2022-07-08 11:44:17 +00:00
captured = [ ]
body_for_snappy = post . body_html . replace ( ' data-src= " ' , ' src= " ' )
2022-07-11 17:45:07 +00:00
for i in list ( snappy_url_regex . finditer ( body_for_snappy ) ) :
href = i . group ( 1 )
if href in [ x [ 0 ] for x in captured ] : continue
2022-07-08 11:44:17 +00:00
title = i . group ( 2 )
2022-07-11 17:45:07 +00:00
captured . append ( ( href , title ) )
for i in list ( snappy_youtube_regex . finditer ( body_for_snappy ) ) :
href = f ' https://youtube.com/watch?v= { i . group ( 1 ) } '
if href in [ x [ 0 ] for x in captured ] : continue
captured . append ( ( href , href ) )
for href , title in captured :
2022-09-23 12:01:42 +00:00
if href . startswith ( SITE_FULL ) or href . startswith ( ' https://rdrama.org/ ' ) : continue
2022-09-03 18:05:00 +00:00
2022-07-08 11:44:17 +00:00
if " Snapshots: \n \n " not in body : body + = " Snapshots: \n \n "
if f ' **[ { title } ]( { href } )**: \n \n ' not in body :
addition = f ' **[ { title } ]( { href } )**: \n \n '
if href . startswith ( ' https://old.reddit.com/r/ ' ) :
rev = href . replace ( ' https://old.reddit.com/ ' , ' ' )
addition + = f ' * [unddit.com](https://unddit.com/ { rev } ) \n '
if href . startswith ( ' https://old.reddit.com/u/ ' ) :
rev = href . replace ( ' https://old.reddit.com/u/ ' , ' ' )
2022-07-15 13:00:51 +00:00
addition + = f " * [camas.unddit.com](https://camas.unddit.com/reddit-search/# \u007b \" author \" : \" { rev } \" , \" resultSize \" :100 \u007d ) \n "
2022-07-08 11:44:17 +00:00
addition + = f ' * [archive.org](https://web.archive.org/ { href } ) \n '
addition + = f ' * [archive.ph](https://archive.ph/?url= { quote ( href ) } &run=1) (click to archive) \n '
addition + = f ' * [ghostarchive.org](https://ghostarchive.org/search?term= { quote ( href ) } ) (click to archive) \n \n '
if len ( f ' { body } { addition } ' ) > 10000 : break
body + = addition
2022-09-03 03:10:14 +00:00
archive_url ( href )
2022-08-15 17:45:43 +00:00
2022-10-05 09:14:12 +00:00
body = body . strip ( ) [ : POST_BODY_LENGTH_LIMIT ]
2022-07-08 11:44:17 +00:00
body_html = sanitize ( body )
2022-07-09 10:50:53 +00:00
if len ( body_html ) == 0 :
return
2022-10-05 09:14:12 +00:00
if len ( body_html ) < POST_BODY_HTML_LENGTH_LIMIT :
2022-07-08 11:44:17 +00:00
c = Comment ( author_id = SNAPPY_ID ,
distinguish_level = 6 ,
parent_submission = post . id ,
level = 1 ,
over_18 = False ,
is_bot = True ,
app_id = None ,
body = body ,
body_html = body_html ,
ghost = post . ghost
)
g . db . add ( c )
snappy . comment_count + = 1
snappy . coins + = 1
g . db . add ( snappy )
2022-07-18 05:10:01 +00:00
if FEATURES [ ' PINS ' ] and ( body . startswith ( ' :#marseypin: ' ) or body . startswith ( ' :#marseypin2: ' ) ) :
2022-07-08 11:44:17 +00:00
post . stickied = " Snappy "
post . stickied_utc = int ( time . time ( ) ) + 3600
2022-10-01 17:37:59 +00:00
elif SITE_NAME == ' rDrama ' and body . startswith ( ' :#marseyban: ' ) :
2022-10-01 17:37:25 +00:00
days = 0.01
reason = f ' <a href= " /post/ { post . id } " >/post/ { post . id } </a> '
v . ban ( admin = snappy , reason = reason , days = days )
text = f " @Snappy has banned you for ** { days } ** days for the following reason: \n \n > { reason } "
send_repeatable_notification ( v . id , text )
duration = f " for { days } days "
note = f ' reason: " { reason } " , duration: { duration } '
ma = ModAction (
kind = " ban_user " ,
user_id = snappy . id ,
target_user_id = v . id ,
_note = note
)
g . db . add ( ma )
post . bannedfor = f ' { duration } by @Snappy '
2022-07-08 11:44:17 +00:00
g . db . flush ( )
c . top_comment_id = c . id
post . comment_count + = 1
2022-07-09 10:50:53 +00:00
post . replies = [ c ]
2022-10-09 13:28:18 +00:00
def execute_zozbot ( c , level , parent_submission , v ) :
if random . random ( ) > = 0.001 : return
c2 = Comment ( author_id = ZOZBOT_ID ,
parent_submission = parent_submission ,
parent_comment_id = c . id ,
level = level + 1 ,
is_bot = True ,
body = " zoz " ,
body_html = " <p>zoz</p> " ,
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
g . db . add ( c2 )
g . db . flush ( )
n = Notification ( comment_id = c2 . id , user_id = v . id )
g . db . add ( n )
c3 = Comment ( author_id = ZOZBOT_ID ,
parent_submission = parent_submission ,
parent_comment_id = c2 . id ,
level = level + 2 ,
is_bot = True ,
body = " zle " ,
body_html = " <p>zle</p> " ,
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
g . db . add ( c3 )
g . db . flush ( )
c4 = Comment ( author_id = ZOZBOT_ID ,
parent_submission = parent_submission ,
parent_comment_id = c3 . id ,
level = level + 3 ,
is_bot = True ,
body = " zozzle " ,
body_html = " <p>zozzle</p> " ,
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
g . db . add ( c4 )
zozbot = get_account ( ZOZBOT_ID )
zozbot . comment_count + = 3
zozbot . coins + = 3
g . db . add ( zozbot )
def execute_longpostbot ( c , level , body , body_html , parent_submission , v ) :
if not len ( c . body . split ( ) ) > = 200 and " < " not in body and " </blockquote> " not in body_html : return
body = random . choice ( LONGPOST_REPLIES )
if body . startswith ( ' ▼ ' ) :
body = body [ 1 : ]
vote = CommentVote ( user_id = LONGPOSTBOT_ID ,
vote_type = - 1 ,
comment_id = c . id ,
real = True
)
g . db . add ( vote )
c . downvotes = 1
c2 = Comment ( author_id = LONGPOSTBOT_ID ,
parent_submission = parent_submission ,
parent_comment_id = c . id ,
level = level + 1 ,
is_bot = True ,
body = body ,
body_html = f " <p> { body } </p> " ,
top_comment_id = c . top_comment_id ,
ghost = c . ghost
)
g . db . add ( c2 )
longpostbot = get_account ( LONGPOSTBOT_ID )
longpostbot . comment_count + = 1
longpostbot . coins + = 1
g . db . add ( longpostbot )
g . db . flush ( )
n = Notification ( comment_id = c2 . id , user_id = v . id )
g . db . add ( n )