2022-11-15 09:19:08 +00:00
import random
import time
from urllib . parse import quote
2023-03-04 18:33:10 +00:00
from sqlalchemy . sql import func
2022-11-15 09:19:08 +00:00
import gevent
import requests
2024-02-01 17:30:04 +00:00
import math
2022-06-15 19:33:21 +00:00
from flask import g
2023-03-04 18:33:10 +00:00
2023-06-23 16:49:23 +00:00
from files . classes . reports import Report
2022-11-15 09:19:08 +00:00
from files . classes . mod_logs import ModAction
from files . classes . notifications import Notification
2023-06-07 23:26:32 +00:00
from files . classes . polls import CommentOption , PostOption
2023-03-25 22:06:44 +00:00
from files . classes . award import AwardRelationship
2023-07-25 18:52:53 +00:00
from files . classes . exiles import Exile
2022-11-15 09:19:08 +00:00
2023-02-24 06:48:30 +00:00
from files . helpers . alerts import send_repeatable_notification , push_notif
2022-12-11 23:44:34 +00:00
from files . helpers . config . const import *
2023-03-25 22:06:44 +00:00
from files . helpers . config . awards import AWARDS
2022-11-15 09:19:08 +00:00
from files . helpers . const_stateful import *
2022-07-08 11:44:17 +00:00
from files . helpers . get import *
2022-11-30 18:09:31 +00:00
from files . helpers . logging import log_file
2022-07-08 11:44:17 +00:00
from files . helpers . sanitize import *
2022-11-30 17:37:35 +00:00
from files . helpers . settings import get_setting
2022-11-07 00:08:50 +00:00
from files . helpers . slots import check_slots_command
2022-07-08 11:44:17 +00:00
2023-07-25 16:42:16 +00:00
from files . routes . routehelpers import check_for_alts
2022-11-15 09:19:08 +00:00
def _archiveorg ( url ) :
2022-11-21 23:52:21 +00:00
try :
2023-10-24 15:15:49 +00:00
requests . post ( ' https://ghostarchive.org/archive2 ' , data = { " archive " : url } , headers = HEADERS , timeout = 10 )
2022-11-21 23:52:21 +00:00
except : pass
try :
2023-10-24 15:15:49 +00:00
requests . get ( f ' https://web.archive.org/save/ { url } ' , headers = HEADERS , timeout = 10 )
2022-09-03 14:24:16 +00:00
except : pass
2022-10-30 22:39:37 +00:00
2022-09-03 03:10:14 +00:00
2023-01-01 11:36:20 +00:00
def archive_url ( url ) :
2023-08-20 16:24:26 +00:00
gevent . spawn ( _archiveorg , url )
2022-09-03 03:10:14 +00:00
if url . startswith ( ' https://instagram.com/ ' ) :
2023-06-24 13:29:28 +00:00
url = url . replace ( ' https://instagram.com/ ' , ' https://imginn.com/ ' )
2023-08-20 16:24:26 +00:00
gevent . spawn ( _archiveorg , url )
2022-09-03 03:10:14 +00:00
2023-03-18 10:59:30 +00:00
def snappy_report ( post , reason ) :
2023-06-23 16:49:23 +00:00
report = Report ( post_id = post . id , user_id = SNAPPY_ID , reason = reason )
g . db . add ( report )
2023-03-18 10:59:30 +00:00
message = f ' @Snappy reported [ { post . title } ]( { post . shortlink } ) \n \n > { reason } '
send_repeatable_notification ( post . author_id , message )
2023-07-30 00:42:06 +00:00
def execute_snappy ( post , v ) :
2023-10-07 17:55:50 +00:00
if post . hole and g . db . query ( Exile . user_id ) . filter_by ( user_id = SNAPPY_ID , hole = post . hole ) . one_or_none ( ) :
2023-07-25 17:49:56 +00:00
return
2022-12-19 16:19:33 +00:00
ghost = post . ghost
2022-07-08 11:44:17 +00:00
snappy = get_account ( SNAPPY_ID )
2023-08-18 02:21:56 +00:00
ping_cost = 0
2023-07-17 17:24:22 +00:00
2023-07-22 17:44:21 +00:00
post_ping_group_count = len ( list ( group_mention_regex . finditer ( post . body ) ) )
2023-07-29 18:31:40 +00:00
2023-10-15 15:13:22 +00:00
if SITE_NAME == ' WPD ' and ( ' killing myself ' in post . title . lower ( ) or ( post . hole != ' suicide ' and ' suicide ' in post . title . lower ( ) ) ) :
body = " https://i.watchpeopledie.tv/images/1697382435294321.webp "
elif post_ping_group_count > 3 :
2023-07-22 17:44:21 +00:00
body = " Unnecessary and uncalled for ping :marseydownvotemad: two more strikes and you ' re getting blocked + megadownvoted buddy, don ' t test your luck "
2023-07-22 21:56:47 +00:00
vote = Vote ( user_id = SNAPPY_ID ,
vote_type = - 1 ,
post_id = post . id ,
real = True
)
g . db . add ( vote )
post . downvotes + = 1
2023-07-22 17:44:21 +00:00
elif v . id == CARP_ID :
2023-07-25 14:21:59 +00:00
if random . random ( ) < 0.08 :
2024-01-15 02:21:58 +00:00
body = random . choice ( ( " i love you carp " , " https://i.rdrama.net/images/16614707883108485.webp " , " https://i.rdrama.net/images/1636916964YyM.webp " , " https://youtube.com/watch?v=zRbQHTdsjuY " , " https://i.rdrama.net/images/1696250281381682.webp " , " https://i.rdrama.net/images/16975678508317988.webp " , " https://i.rdrama.net/images/170526627808132.webp " , " https://i.rdrama.net/images/17052853054732056.webp " ) )
2023-05-01 18:41:55 +00:00
elif IS_DKD ( ) :
body = " :#donkeykongfuckoffcarp: "
2023-09-28 23:58:09 +00:00
elif IS_HOMOWEEN ( ) :
body = " F̵̽̉U̷̓̕C̵̟̍K̴̾̍ ̵́̒O̶͐̇F̷͗̐F̴͛̄ ̸̆͠CARP "
2023-10-17 18:45:45 +00:00
elif IS_FISTMAS ( ) :
body = " Merry Christmas Carp :marseychristmasgift2: "
2023-05-01 18:41:55 +00:00
else :
2024-01-17 04:27:30 +00:00
body = " :#carpwavelove: "
2023-08-02 04:18:25 +00:00
elif v . id == AEVANN_ID :
2023-10-01 14:46:34 +00:00
body = " https://i.rdrama.net/images/16909380805064178.webp "
2022-07-08 11:44:17 +00:00
elif v . id == LAWLZ_ID :
if random . random ( ) < 0.5 : body = " wow, this lawlzpost sucks! "
else : body = " wow, a good lawlzpost for once! "
2023-12-15 01:55:56 +00:00
elif SITE == ' rdrama.net ' and v . id == 253 :
2023-10-01 14:46:34 +00:00
body = " https://i.rdrama.net/images/16961715452780113.webp "
2023-12-15 01:55:56 +00:00
elif SITE == ' rdrama.net ' and v . id == 8094 :
body = " https://i.rdrama.net/images/17025988883967621.webp "
2024-01-12 05:50:31 +00:00
elif SITE == ' rdrama.net ' and v . id == 5214 :
body = random . choice ( ( " https://rdrama.net/audio/1704983217764354.mp3 " , " Dear Chiobu: \n \n We are not accepting non-US residents because of difficulty of payment and difficulty of enforcing our Confidentiality Agreement internationally. Additionally, you seem to have opinions incompatible with ours, namely your opinions **Towards the Chinese** and **Towards Transgender Individuals**. We thank you for your interest. " ) )
2022-07-08 11:44:17 +00:00
else :
2023-04-25 17:02:56 +00:00
if IS_DKD ( ) :
2023-05-02 13:49:28 +00:00
SNAPPY_CHOICES = SNAPPY_KONGS
2023-09-28 23:58:09 +00:00
elif IS_FISTMAS ( ) :
SNAPPY_CHOICES = SNAPPY_QUOTES_FISTMAS
elif IS_HOMOWEEN ( ) :
SNAPPY_CHOICES = SNAPPY_QUOTES_HOMOWEEN
2023-05-02 13:49:28 +00:00
elif SNAPPY_MARSEYS and SNAPPY_QUOTES :
2023-09-28 23:58:09 +00:00
if random . random ( ) > 0.5 :
2022-12-19 01:20:14 +00:00
SNAPPY_CHOICES = SNAPPY_QUOTES
2023-01-01 11:36:20 +00:00
else :
2023-05-02 13:49:28 +00:00
SNAPPY_CHOICES = SNAPPY_MARSEYS
elif SNAPPY_MARSEYS :
SNAPPY_CHOICES = SNAPPY_MARSEYS
elif SNAPPY_QUOTES :
SNAPPY_CHOICES = SNAPPY_QUOTES
else :
SNAPPY_CHOICES = [ " " ]
2022-08-15 05:10:15 +00:00
body = random . choice ( SNAPPY_CHOICES ) . strip ( )
2023-10-26 16:40:36 +00:00
body = body . replace ( ' % OP % ' , f ' @ { post . author_name } ' )
2022-12-13 16:36:16 +00:00
if body . startswith ( ' ▼ ' ) or body . startswith ( ' :#marseydownvote ' ) :
2023-01-28 12:01:18 +00:00
if body . startswith ( ' ▼ ' ) : body = body [ 1 : ]
2022-07-08 11:44:17 +00:00
vote = Vote ( user_id = SNAPPY_ID ,
vote_type = - 1 ,
2023-06-07 23:26:32 +00:00
post_id = post . id ,
2022-07-08 11:44:17 +00:00
real = True
)
2023-03-16 06:27:58 +00:00
g . db . add ( vote )
2022-07-08 11:44:17 +00:00
post . downvotes + = 1
if body . startswith ( ' OP is a Trump supporter ' ) :
2023-03-18 10:59:30 +00:00
snappy_report ( post , ' Trump supporter ' )
2022-07-08 11:44:17 +00:00
elif body . startswith ( ' You had your chance. Downvoted and reported ' ) :
2023-03-18 10:59:30 +00:00
snappy_report ( post , ' Retard ' )
2022-11-22 21:45:50 +00:00
elif body . startswith ( ' ▲ ' ) or body . startswith ( ' :#marseyupvote ' ) :
2023-01-28 12:01:18 +00:00
if body . startswith ( ' ▲ ' ) : body = body [ 1 : ]
2022-07-08 11:44:17 +00:00
vote = Vote ( user_id = SNAPPY_ID ,
vote_type = 1 ,
2023-06-07 23:26:32 +00:00
post_id = post . id ,
2022-07-08 11:44:17 +00:00
real = True
)
2023-03-16 06:27:58 +00:00
g . db . add ( vote )
2022-07-08 11:44:17 +00:00
post . upvotes + = 1
2023-10-27 16:04:45 +00:00
elif ' :#marseyghost ' in body :
2022-12-19 16:19:33 +00:00
ghost = True
2023-03-04 18:33:10 +00:00
elif body == ' !slots ' :
body = f ' !slots { snappy . coins } '
elif body == ' !pinggroup ' :
2024-01-03 22:09:23 +00:00
group = g . db . query ( Group ) . filter ( Group . name != ' focusgroup ' ) . order_by ( func . random ( ) ) . first ( )
2023-03-04 18:33:10 +00:00
2023-08-20 16:36:13 +00:00
cost = len ( group . member_ids ) * 5
2023-03-04 18:33:10 +00:00
snappy . charge_account ( ' coins ' , cost )
body = f ' ! { group . name } '
2023-08-01 07:38:58 +00:00
2023-07-17 17:24:22 +00:00
ping_cost = cost
2023-03-25 22:08:36 +00:00
elif body . startswith ( ' :#marseyglow ' ) :
2023-03-25 22:06:44 +00:00
award_object = AwardRelationship (
user_id = snappy . id ,
kind = " glowie " ,
2023-06-07 23:26:32 +00:00
post_id = post . id ,
2024-02-03 03:18:47 +00:00
awarded_utc = time . time ( ) ,
2023-03-25 22:06:44 +00:00
)
g . db . add ( award_object )
awarded_coins = int ( AWARDS [ " glowie " ] [ ' price ' ] * COSMETIC_AWARD_COIN_AWARD_PCT ) if AWARDS [ " glowie " ] [ ' cosmetic ' ] else 0
if AWARDS [ " glowie " ] [ ' cosmetic ' ] :
post . author . pay_account ( ' coins ' , awarded_coins )
msg = f " @Snappy has given your [post]( { post . shortlink } ) the { AWARDS [ ' glowie ' ] [ ' title ' ] } Award "
if awarded_coins > 0 :
msg + = f " and you have received { awarded_coins } coins as a result "
msg + = " ! "
send_repeatable_notification ( post . author . id , msg )
2023-03-04 18:33:10 +00:00
2022-07-08 11:44:17 +00:00
body + = " \n \n "
2023-06-08 00:32:33 +00:00
if post . url and not post . url . startswith ( ' / ' ) and not post . url . startswith ( f ' { SITE_FULL } / ' ) and not post . url . startswith ( SITE_FULL_IMAGES ) :
2023-10-26 21:53:16 +00:00
if post . url . startswith ( ' https://old.reddit.com/r/ ' ) and ' /comments/ ' in post . url :
2023-09-09 15:44:47 +00:00
rev = post . url . replace ( ' https://old.reddit.com/ ' , ' ' )
rev = f " * [undelete.pullpush.io](https://undelete.pullpush.io/ { rev } ) \n \n "
2023-09-18 18:26:21 +00:00
elif post . url . startswith ( " https://old.reddit.com/user/ " ) :
rev = post . url . replace ( ' https://old.reddit.com/user/ ' , ' ' )
rev = f " * [search-new.pullpush.io](https://search-new.pullpush.io/?author= { rev } &type=submission) \n \n "
2023-09-09 15:44:47 +00:00
else : rev = ' '
2023-10-01 08:41:01 +00:00
body + = f " Snapshots: \n \n { rev } * [ghostarchive.org](https://ghostarchive.org/search?term= { quote ( post . url ) } ) \n \n * [archive.org](https://web.archive.org/ { post . url } ) \n \n * [archive.ph](https://archive.ph/?url= { quote ( post . url ) } &run=1) (click to archive) \n \n "
2022-09-22 20:45:26 +00:00
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 href , title in captured :
2023-10-26 21:35:08 +00:00
if href == post . url : continue
2023-06-08 00:32:33 +00:00
if href . startswith ( f ' { SITE_FULL } / ' ) or href . startswith ( SITE_FULL_IMAGES ) : continue
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 '
2023-10-26 21:53:16 +00:00
if href . startswith ( ' https://old.reddit.com/r/ ' ) and ' /comments/ ' in href :
2023-09-09 15:44:47 +00:00
rev = href . replace ( ' https://old.reddit.com/ ' , ' ' )
addition + = f ' * [undelete.pullpush.io](https://undelete.pullpush.io/ { rev } ) \n \n '
2023-09-18 18:26:21 +00:00
elif href . startswith ( ' https://old.reddit.com/user/ ' ) :
rev = href . replace ( ' https://old.reddit.com/user/ ' , ' ' )
addition + = f " * [search-new.pullpush.io](https://search-new.pullpush.io/?author= { rev } &type=submission) \n \n "
2023-02-26 10:20:32 +00:00
addition + = f ' * [ghostarchive.org](https://ghostarchive.org/search?term= { quote ( href ) } ) \n \n '
2023-10-01 08:41:01 +00:00
addition + = f ' * [archive.org](https://web.archive.org/ { href } ) \n \n '
2023-02-26 10:20:32 +00:00
addition + = f ' * [archive.ph](https://archive.ph/?url= { quote ( href ) } &run=1) (click to archive) \n \n '
2022-10-14 13:19:47 +00:00
if len ( f ' { body } { addition } ' ) > COMMENT_BODY_LENGTH_LIMIT : break
2022-07-08 11:44:17 +00:00
body + = addition
2022-09-03 03:10:14 +00:00
archive_url ( href )
2022-08-15 17:45:43 +00:00
2023-07-30 06:20:02 +00:00
body = body [ : COMMENT_BODY_LENGTH_LIMIT ] . strip ( )
2023-06-22 12:52:31 +00:00
body_html = sanitize ( body , snappy = True , showmore = True )
2022-07-08 11:44:17 +00:00
2022-07-09 10:50:53 +00:00
if len ( body_html ) == 0 :
return
2022-10-14 13:19:47 +00:00
if len ( body_html ) < COMMENT_BODY_HTML_LENGTH_LIMIT :
2022-07-08 11:44:17 +00:00
c = Comment ( author_id = SNAPPY_ID ,
distinguish_level = 6 ,
2023-06-23 13:46:42 +00:00
parent_post = post . id ,
2022-07-08 11:44:17 +00:00
level = 1 ,
2023-10-05 10:19:50 +00:00
nsfw = False ,
2022-07-08 11:44:17 +00:00
is_bot = True ,
app_id = None ,
body = body ,
body_html = body_html ,
2023-08-18 02:21:56 +00:00
ghost = ghost ,
ping_cost = ping_cost ,
2022-07-08 11:44:17 +00:00
)
2023-03-16 06:27:58 +00:00
g . db . add ( c )
2022-07-08 11:44:17 +00:00
2022-12-09 05:55:18 +00:00
check_slots_command ( c , v , snappy )
2022-11-07 00:08:50 +00:00
2022-07-08 11:44:17 +00:00
snappy . comment_count + = 1
2022-11-20 10:50:02 +00:00
snappy . pay_account ( ' coins ' , 1 )
2023-03-16 06:27:58 +00:00
g . db . add ( snappy )
2022-07-08 11:44:17 +00:00
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 "
2023-08-23 21:57:39 +00:00
ma = ModAction (
2022-10-01 17:37:25 +00:00
kind = " ban_user " ,
user_id = snappy . id ,
target_user_id = v . id ,
2022-12-30 15:47:40 +00:00
_note = f ' duration: { duration } , reason: " { reason } " '
2022-10-01 17:37:25 +00:00
)
2023-03-16 06:27:58 +00:00
g . db . add ( ma )
2022-10-01 17:37:25 +00:00
post . bannedfor = f ' { duration } by @Snappy '
2023-03-16 06:27:58 +00:00
g . db . flush ( )
2022-07-08 11:44:17 +00:00
2023-08-18 02:21:56 +00:00
if c . ping_cost :
for x in group . member_ids :
n = Notification ( comment_id = c . id , user_id = x )
g . db . add ( n )
push_notif ( { x } , f ' New mention of you by @Snappy ' , c . body , c )
2023-04-24 13:47:55 +00:00
2022-07-08 11:44:17 +00:00
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
2023-10-06 13:16:07 +00:00
def execute_zozbot ( c , level , post , v ) :
2022-12-09 03:35:28 +00:00
if SITE_NAME != ' rDrama ' : return
2023-10-06 13:16:55 +00:00
2023-10-06 17:09:40 +00:00
if random . random ( ) > = 0.001 : return
2023-10-06 13:16:55 +00:00
2023-10-06 13:16:07 +00:00
posting_to_post = isinstance ( post , Post )
2023-10-06 17:09:40 +00:00
2023-10-07 17:55:50 +00:00
if posting_to_post and post . hole and g . db . query ( Exile . user_id ) . filter_by ( user_id = ZOZBOT_ID , hole = post . hole ) . one_or_none ( ) :
2023-10-06 17:09:40 +00:00
return
2022-10-09 13:28:18 +00:00
c2 = Comment ( author_id = ZOZBOT_ID ,
2023-10-06 13:16:07 +00:00
parent_post = post . id if posting_to_post else None ,
wall_user_id = post . id if not posting_to_post else None ,
2022-10-09 13:29:58 +00:00
parent_comment_id = c . id ,
level = level + 1 ,
is_bot = True ,
body = " zoz " ,
2022-11-23 00:09:42 +00:00
body_html = ' <p class= " zozbot " >zoz</p> ' ,
2022-10-09 13:29:58 +00:00
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
2022-10-09 13:28:18 +00:00
2023-03-16 06:27:58 +00:00
g . db . add ( c2 )
g . db . flush ( )
2022-10-09 13:28:18 +00:00
n = Notification ( comment_id = c2 . id , user_id = v . id )
2023-03-16 06:27:58 +00:00
g . db . add ( n )
2022-10-09 13:28:18 +00:00
c3 = Comment ( author_id = ZOZBOT_ID ,
2023-10-06 13:16:07 +00:00
parent_post = post . id if posting_to_post else None ,
wall_user_id = post . id if not posting_to_post else None ,
2022-10-09 13:28:18 +00:00
parent_comment_id = c2 . id ,
level = level + 2 ,
is_bot = True ,
body = " zle " ,
2022-11-23 00:09:42 +00:00
body_html = ' <p class= " zozbot " >zle</p> ' ,
2022-10-09 13:28:18 +00:00
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
2023-03-16 06:27:58 +00:00
g . db . add ( c3 )
g . db . flush ( )
2022-11-11 08:45:28 +00:00
2022-10-09 13:28:18 +00:00
c4 = Comment ( author_id = ZOZBOT_ID ,
2023-10-06 13:16:07 +00:00
parent_post = post . id if posting_to_post else None ,
wall_user_id = post . id if not posting_to_post else None ,
2022-10-09 13:28:18 +00:00
parent_comment_id = c3 . id ,
level = level + 3 ,
is_bot = True ,
body = " zozzle " ,
2022-11-23 00:09:42 +00:00
body_html = ' <p class= " zozbot " >zozzle</p> ' ,
2022-10-09 13:28:18 +00:00
top_comment_id = c . top_comment_id ,
ghost = c . ghost ,
distinguish_level = 6
)
2023-03-16 06:27:58 +00:00
g . db . add ( c4 )
2022-10-09 13:28:18 +00:00
zozbot = get_account ( ZOZBOT_ID )
zozbot . comment_count + = 3
2022-11-20 10:50:02 +00:00
zozbot . pay_account ( ' coins ' , 1 )
2023-03-16 06:27:58 +00:00
g . db . add ( zozbot )
2022-10-09 13:28:18 +00:00
2023-06-23 13:46:42 +00:00
if posting_to_post :
2023-10-06 13:16:07 +00:00
post . comment_count + = 3
g . db . add ( post )
2023-02-18 21:59:17 +00:00
2023-02-27 13:35:53 +00:00
push_notif ( { v . id } , f ' New reply by @ { c2 . author_name } ' , " zoz " , c2 )
2023-02-18 21:59:17 +00:00
2023-10-06 13:16:07 +00:00
def execute_longpostbot ( c , level , body , body_html , post , v ) :
2022-12-09 03:35:28 +00:00
if SITE_NAME != ' rDrama ' : return
2023-10-06 13:16:55 +00:00
2022-10-09 16:40:20 +00:00
if not len ( c . body . split ( ) ) > = 200 : return
2023-10-06 17:09:40 +00:00
2022-10-09 20:13:55 +00:00
if " </blockquote> " in body_html : return
2023-10-06 17:09:40 +00:00
posting_to_post = isinstance ( post , Post )
2023-10-07 17:55:50 +00:00
if posting_to_post and post . hole and g . db . query ( Exile . user_id ) . filter_by ( user_id = LONGPOSTBOT_ID , hole = post . hole ) . one_or_none ( ) :
2023-10-06 17:09:40 +00:00
return
2023-08-10 12:04:20 +00:00
body = random . choice ( LONGPOSTBOT_REPLIES )
2022-10-09 13:28:18 +00:00
if body . startswith ( ' ▼ ' ) :
body = body [ 1 : ]
vote = CommentVote ( user_id = LONGPOSTBOT_ID ,
vote_type = - 1 ,
comment_id = c . id ,
real = True
)
2023-03-16 06:27:58 +00:00
g . db . add ( vote )
2022-10-09 13:28:18 +00:00
c . downvotes = 1
2023-02-25 16:09:20 +00:00
body_html = sanitize ( body )
2022-10-09 13:28:18 +00:00
c2 = Comment ( author_id = LONGPOSTBOT_ID ,
2023-10-06 13:16:07 +00:00
parent_post = post . id if posting_to_post else None ,
wall_user_id = post . id if not posting_to_post else None ,
2022-10-09 13:28:18 +00:00
parent_comment_id = c . id ,
level = level + 1 ,
is_bot = True ,
body = body ,
2023-02-25 16:09:20 +00:00
body_html = body_html ,
2022-10-09 13:28:18 +00:00
top_comment_id = c . top_comment_id ,
ghost = c . ghost
)
2023-03-16 06:27:58 +00:00
g . db . add ( c2 )
2022-10-09 13:28:18 +00:00
longpostbot = get_account ( LONGPOSTBOT_ID )
longpostbot . comment_count + = 1
2022-11-20 10:50:02 +00:00
longpostbot . pay_account ( ' coins ' , 1 )
2023-03-16 06:27:58 +00:00
g . db . add ( longpostbot )
g . db . flush ( )
2022-10-09 13:28:18 +00:00
n = Notification ( comment_id = c2 . id , user_id = v . id )
2023-03-16 06:27:58 +00:00
g . db . add ( n )
2022-10-09 13:49:08 +00:00
2023-06-23 13:46:42 +00:00
if posting_to_post :
2023-10-06 13:16:07 +00:00
post . comment_count + = 1
g . db . add ( post )
2023-02-18 21:59:17 +00:00
2023-02-27 13:35:53 +00:00
push_notif ( { v . id } , f ' New reply by @ { c2 . author_name } ' , c2 . body , c2 )
2023-02-18 21:59:17 +00:00
2023-07-01 15:25:23 +00:00
def tempban_for_spam ( v ) :
text = " Your account has been banned for **1 day** for the following reason: \n \n > Too much spam! "
send_repeatable_notification ( v . id , text )
v . ban ( reason = " Spam " , days = 1 )
2023-08-23 21:57:39 +00:00
ma = ModAction (
2023-07-01 15:25:23 +00:00
kind = " ban_user " ,
user_id = AUTOJANNY_ID ,
target_user_id = v . id ,
_note = f ' duration: for 1 day, reason: " Spam " '
)
g . db . add ( ma )
2023-06-23 13:46:42 +00:00
def execute_antispam_post_check ( title , v , url ) :
2023-08-31 10:38:01 +00:00
if v . admin_level > = PERMS [ ' BYPASS_ANTISPAM_CHECKS ' ] :
2023-08-31 10:31:04 +00:00
return True
2023-08-08 12:04:15 +00:00
2022-10-12 05:11:20 +00:00
now = int ( time . time ( ) )
cutoff = now - 60 * 60 * 24
2023-06-07 23:26:32 +00:00
similar_posts = g . db . query ( Post ) . filter (
Post . author_id == v . id ,
Post . title . op ( ' <-> ' ) ( title ) < SPAM_SIMILARITY_THRESHOLD ,
Post . created_utc > cutoff
2022-10-12 05:11:20 +00:00
) . all ( )
if url :
2023-06-07 23:26:32 +00:00
similar_urls = g . db . query ( Post ) . filter (
Post . author_id == v . id ,
Post . url . op ( ' <-> ' ) ( url ) < SPAM_URL_SIMILARITY_THRESHOLD ,
Post . created_utc > cutoff
2022-10-12 05:11:20 +00:00
) . all ( )
else : similar_urls = [ ]
threshold = SPAM_SIMILAR_COUNT_THRESHOLD
if v . age > = ( 60 * 60 * 24 * 7 ) : threshold * = 3
elif v . age > = ( 60 * 60 * 24 ) : threshold * = 2
if max ( len ( similar_urls ) , len ( similar_posts ) ) > = threshold :
2023-07-01 15:25:23 +00:00
tempban_for_spam ( v )
2022-10-12 05:11:20 +00:00
for post in similar_posts + similar_urls :
post . is_banned = True
post . is_pinned = False
post . ban_reason = " AutoJanny "
2023-03-16 06:27:58 +00:00
g . db . add ( post )
2024-01-31 21:56:32 +00:00
ma = ModAction (
2022-10-12 05:11:20 +00:00
user_id = AUTOJANNY_ID ,
2023-06-07 23:26:32 +00:00
target_post_id = post . id ,
2022-10-12 05:11:20 +00:00
kind = " ban_post " ,
2023-02-19 13:24:42 +00:00
_note = " Spam "
2022-10-12 05:11:20 +00:00
)
2023-03-16 06:27:58 +00:00
g . db . add ( ma )
2022-10-12 05:11:20 +00:00
return False
return True
2023-07-30 00:42:06 +00:00
def execute_antispam_duplicate_comment_check ( v , body_html ) :
2023-08-31 10:38:01 +00:00
if v . admin_level > = PERMS [ ' BYPASS_ANTISPAM_CHECKS ' ] :
2023-08-31 10:31:04 +00:00
return
if v . id in ANTISPAM_BYPASS_IDS :
return
if v . age > = NOTIFICATION_SPAM_AGE_THRESHOLD :
return
if len ( body_html ) < 16 :
return
2023-03-07 01:08:10 +00:00
2022-11-23 20:45:09 +00:00
ANTISPAM_DUPLICATE_THRESHOLD = 3
2022-11-14 03:48:52 +00:00
compare_time = int ( time . time ( ) ) - 60 * 60 * 24
2023-03-16 06:27:58 +00:00
count = g . db . query ( Comment . id ) . filter ( Comment . body_html == body_html ,
2022-11-23 20:45:09 +00:00
Comment . created_utc > = compare_time ) . count ( )
if count < = ANTISPAM_DUPLICATE_THRESHOLD : return
2023-07-01 15:25:23 +00:00
tempban_for_spam ( v )
2023-03-16 06:27:58 +00:00
g . db . commit ( )
2022-11-14 03:48:52 +00:00
abort ( 403 , " Too much spam! " )
2023-07-30 00:42:06 +00:00
def execute_antispam_comment_check ( body , v ) :
2023-08-31 10:38:01 +00:00
if v . admin_level > = PERMS [ ' BYPASS_ANTISPAM_CHECKS ' ] :
2023-08-31 10:31:04 +00:00
return
2023-03-07 01:08:10 +00:00
2022-10-24 17:27:25 +00:00
if v . id in ANTISPAM_BYPASS_IDS : return
2022-10-12 05:11:20 +00:00
if len ( body ) < = COMMENT_SPAM_LENGTH_THRESHOLD : return
now = int ( time . time ( ) )
cutoff = now - 60 * 60 * 24
2023-03-16 06:27:58 +00:00
similar_comments = g . db . query ( Comment ) . filter (
2022-10-12 05:11:20 +00:00
Comment . author_id == v . id ,
Comment . body . op ( ' <-> ' ) ( body ) < COMMENT_SPAM_SIMILAR_THRESHOLD ,
Comment . created_utc > cutoff
) . all ( )
threshold = COMMENT_SPAM_COUNT_THRESHOLD
if v . age > = ( 60 * 60 * 24 * 7 ) :
threshold * = 3
elif v . age > = ( 60 * 60 * 24 ) :
threshold * = 2
2022-11-11 08:45:28 +00:00
2022-10-12 05:11:20 +00:00
if len ( similar_comments ) < = threshold : return
2023-07-01 15:25:23 +00:00
tempban_for_spam ( v )
2022-10-12 05:11:20 +00:00
for comment in similar_comments :
comment . is_banned = True
comment . ban_reason = " AutoJanny "
2023-03-16 06:27:58 +00:00
g . db . add ( comment )
2024-01-31 21:56:32 +00:00
ma = ModAction (
2022-10-12 05:11:20 +00:00
user_id = AUTOJANNY_ID ,
target_comment_id = comment . id ,
kind = " ban_comment " ,
2023-02-19 13:24:42 +00:00
_note = " Spam "
2022-10-12 05:11:20 +00:00
)
2023-03-16 06:27:58 +00:00
g . db . add ( ma )
g . db . commit ( )
2022-10-21 00:28:05 +00:00
abort ( 403 , " Too much spam! " )
2022-10-23 17:01:00 +00:00
2023-07-30 00:42:06 +00:00
def execute_under_siege ( v , target , body , kind ) :
2023-05-14 22:01:10 +00:00
if v . shadowbanned : return
2023-06-30 20:17:56 +00:00
2023-08-31 10:38:01 +00:00
if v . admin_level > = PERMS [ ' BYPASS_UNDER_SIEGE_MODE ' ] : return
2023-02-27 12:49:19 +00:00
2024-01-31 23:28:39 +00:00
thresholds = cache . get ( " under_siege_thresholds " )
if not thresholds :
thresholds = DEFAULT_UNDER_SIEGE_THRESHOLDS
cache . set ( " under_siege_thresholds " , thresholds )
2023-02-27 12:49:19 +00:00
2024-01-31 23:28:39 +00:00
if v . age > thresholds [ kind ] * 60 :
return
2022-12-18 14:23:59 +00:00
2023-08-11 13:15:34 +00:00
unshadowbannedcels = [ x [ 0 ] for x in g . db . query ( ModAction . target_user_id ) . filter_by ( kind = ' unshadowban ' ) ]
2023-05-14 22:01:10 +00:00
if v . id in unshadowbannedcels : return
2023-07-25 16:42:16 +00:00
check_for_alts ( v )
if v . shadowbanned : return
2023-05-14 22:01:10 +00:00
v . shadowbanned = AUTOJANNY_ID
v . ban_reason = " Under Siege "
g . db . add ( v )
if kind == " report " :
2023-06-07 23:26:32 +00:00
if isinstance ( target , Post ) :
2023-05-14 22:01:10 +00:00
reason = f ' report on <a href= " { target . permalink } " >post</a> '
else :
reason = f ' report on <a href= " { target . permalink } " >comment</a> '
else :
reason = kind
2024-02-01 17:30:04 +00:00
minutes = math . ceil ( v . age / 60 )
time_taken = f ' { minutes } minute '
if minutes > 1 :
time_taken + = ' s '
2023-05-14 22:01:10 +00:00
ma = ModAction (
kind = " shadowban " ,
user_id = AUTOJANNY_ID ,
target_user_id = v . id ,
2024-02-01 17:30:04 +00:00
_note = f ' reason: " Under Siege ( { reason } , { time_taken } ) " '
2023-05-14 22:01:10 +00:00
)
g . db . add ( ma )
if kind == ' message ' :
2024-02-05 04:25:06 +00:00
notified_ids = [ x [ 0 ] for x in g . db . query ( User . id ) . filter (
User . admin_level > = PERMS [ ' BLACKJACK_NOTIFICATIONS ' ] ,
User . id != AEVANN_ID ,
) ]
2023-05-14 22:01:10 +00:00
for uid in notified_ids :
n = Notification ( comment_id = target . id , user_id = uid )
g . db . add ( n )
2022-12-18 14:25:24 +00:00
2022-11-30 17:37:35 +00:00
2023-07-30 00:42:06 +00:00
def execute_lawlz_actions ( v , p ) :
2022-10-23 17:01:00 +00:00
if v . id != LAWLZ_ID : return
if SITE_NAME != ' rDrama ' : return
2022-10-23 17:14:27 +00:00
if not FEATURES [ ' PINS ' ] : return
2022-10-23 17:01:00 +00:00
p . stickied_utc = int ( time . time ( ) ) + 86400
2022-12-01 12:27:12 +00:00
p . stickied = " AutoJanny "
2022-10-23 17:01:00 +00:00
p . distinguish_level = 6
2022-11-05 02:24:30 +00:00
p . flair = filter_emojis_only ( " :ben10: Required Reading " )
2023-08-23 21:57:39 +00:00
ma_1 = ModAction (
2022-10-23 17:01:00 +00:00
kind = " pin_post " ,
2022-11-26 01:56:04 +00:00
user_id = AUTOJANNY_ID ,
2023-06-07 23:26:32 +00:00
target_post_id = p . id ,
2022-12-30 15:47:40 +00:00
_note = ' for 1 day '
2022-10-23 17:01:00 +00:00
)
2023-08-23 21:57:39 +00:00
ma_2 = ModAction (
2022-10-23 17:01:00 +00:00
kind = " distinguish_post " ,
2022-11-26 01:56:04 +00:00
user_id = AUTOJANNY_ID ,
2023-06-07 23:26:32 +00:00
target_post_id = p . id
2022-10-23 17:01:00 +00:00
)
2023-08-23 21:57:39 +00:00
ma_3 = ModAction (
2022-10-23 17:01:00 +00:00
kind = " flair_post " ,
2022-11-26 01:56:04 +00:00
user_id = AUTOJANNY_ID ,
2023-06-07 23:26:32 +00:00
target_post_id = p . id ,
2022-10-23 17:01:00 +00:00
_note = f ' " { p . flair } " '
)
2023-03-16 06:27:58 +00:00
g . db . add ( p )
g . db . add ( ma_1 )
g . db . add ( ma_2 )
g . db . add ( ma_3 )
2022-12-04 21:46:27 +00:00
2022-12-09 03:35:28 +00:00
2023-10-17 09:02:46 +00:00
def process_options ( v , target ) :
2023-02-28 22:09:16 +00:00
patterns = [ ( poll_regex , 0 ) , ( choice_regex , 1 ) ]
2023-03-12 17:36:35 +00:00
if v . admin_level > = PERMS [ ' POST_BETS ' ] :
2023-02-28 22:09:16 +00:00
patterns . append ( ( bet_regex , 2 ) )
option_count = 0
2023-03-23 15:52:31 +00:00
option_objects = [ ]
2023-02-28 22:09:16 +00:00
for pattern , exclusive in patterns :
2023-07-14 14:46:35 +00:00
body_html = target . body_html . replace ( ' & ' , ' & ' )
for i in pattern . finditer ( body_html ) :
2023-02-28 22:09:16 +00:00
option_count + = 1
if option_count > POLL_MAX_OPTIONS :
abort ( 400 , f " Max number of poll options is { POLL_MAX_OPTIONS } " )
2023-03-12 18:40:18 +00:00
body = i . group ( 2 )
2023-02-28 22:09:16 +00:00
if len ( body ) > 500 :
abort ( 400 , f " Poll option body too long! (Max 500 characters) " )
2023-06-07 23:26:32 +00:00
if isinstance ( target , Post ) :
cls = PostOption
2023-02-28 22:09:16 +00:00
else :
cls = CommentOption
2023-03-16 06:27:58 +00:00
existing = g . db . query ( cls ) . filter_by (
2023-02-28 22:09:16 +00:00
parent_id = target . id ,
2023-07-14 14:46:35 +00:00
body_html = body ,
2023-02-28 22:09:16 +00:00
exclusive = exclusive ,
2023-02-28 23:46:11 +00:00
) . first ( )
2023-05-05 21:45:25 +00:00
2023-02-28 22:09:16 +00:00
if not existing :
option = cls (
parent_id = target . id ,
2023-07-14 14:46:35 +00:00
body_html = body ,
2023-02-28 22:09:16 +00:00
exclusive = exclusive ,
)
2023-03-23 15:53:01 +00:00
option_objects . append ( option ) #shitty hack to bypass autoflush
2023-03-23 15:52:31 +00:00
g . db . add_all ( option_objects )