@ -103,6 +103,10 @@ class Instance:
self . tracker_report ( )
time . sleep ( 60 )
def respond ( self , status , message ) :
log_print ( self . name , " Responded with: {} " . format ( message ) )
self . api . status_reply ( status , " {} \n {} " . format ( message , config [ " tag " ] ) , visibility = " direct " , untag = True )
def tracker ( self ) :
my_id = self . api . me ( ) [ " id " ]
@ -129,7 +133,7 @@ class Instance:
md_text = h2t . handle ( status [ " content " ] )
if " #cringefilter " in md_text :
if config [ " tag " ] in md_text :
continue
mail_text = toot_dict_to_mail ( status ) . format ( )
@ -156,71 +160,66 @@ class Instance:
self . save_state ( )
else :
<< << << < HEAD
replied_id = status . get ( " in_reply_to_id " , None )
log_pprint ( self . name , status )
if replied_id :
try :
replied_status = self . api . status ( replied_id )
replied_md = h2t . handle ( replied_status [ " content " ] )
if " #cringefilter " in replied_md :
target_status_id = status . get ( " in_reply_to_id " , None )
if config [ " tag " ] in replied_md :
target_status_id = replied_ status. get ( " in_reply_to_id " , None )
if target_status_id :
try :
target_status = self . api . status ( target_status_id )
target_timeslot_key = encode_time ( status [ " created_at " ] )
target_mail_text = toot_dict_to_mail ( target_status ) . format ( )
command = h2t . handle ( status [ " content " ] )
if " learn spam " in command :
command = h2t . handle ( status [ " content " ] ) . strip ( )
log_print ( " Received command: {} " . format ( command ) )
if command == " learn spam " :
bogofilter . run ( target_mail_text , [ bogofilter . LEARN_SPAM ] )
self . track_status ( target_status )
self . api . status_reply ( status , " @ {} Learned as spam\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
elif " unlearn spam " in command :
self . respond ( status , " Learned as spam ")
elif command == " unlearn spam " :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_SPAM ] )
self . expire_status ( target_timeslot_key , target_status_id )
self . api . status_reply ( status , " @ {} Unlearned as spam\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
elif " relearn spam " in command :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_HAM , bogofilter . LEARM _SPAM ] )
self . respond ( status , " Unlearned as spam ")
elif command == " relearn spam " :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_HAM , bogofilter . LEARN _SPAM ] )
self . track_status ( target_status )
self . api . status_reply ( status , " @ {} Relearned as spam\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
if " learn ham " in command :
self . respond ( status , " Relearned as spam ")
el if command == " learn ham " :
bogofilter . run ( target_mail_text , [ bogofilter . LEARN_HAM ] )
self . expire_status ( target_timeslot_key , target_status_id )
self . api . status_reply ( status , " @ {} Learned as ham\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
elif " unlearn ham " in command :
self . respond ( status , " Learned as ham ")
elif command == " unlearn ham " :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_HAM ] )
self . api . status_reply ( status , " @ {} Unlearned as ham\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
elif " relearn ham " in command :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_SPAM , bogofilter . LEARM _HAM ] )
self . respond ( status , " Unlearned as ham ")
elif command == " relearn ham " :
bogofilter . run ( target_mail_text , [ bogofilter . UNLEARN_SPAM , bogofilter . LEARN _HAM ] )
self . expire_status ( target_timeslot_key , target_status_id )
self . api . status_reply ( status , " @ {} Relearned as ham\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
self . respond ( status , " Relearned as ham ")
else :
self . api . status_reply ( status , " @ {} Unknown command \n #cringefilter " . format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
continue
self . respond ( status , " Unknown command " )
except MastodonNotFoundError :
self . api . status_reply ( status , " @ {} Original status is missing \n #cringefilter " . format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
continue
self . respond ( status , " Original status is missing " )
else :
self . api . status_reply ( status , " @ {} Original status not referenced\n #cringefilter ". format ( self . api . me ( ) [ " username " ] ) , visibility = " direct " , untag = True )
continue
self . respond ( status , " Original status not referenced ")
continue
except MastodonNotFoundError :
log_print ( self . name ,
" Cannot find replied-to status {} on server " . format ( status_id ) )
pass
result = bogofilter . run ( mail_text , [ bogofilter . CLASSIFY , bogofilter . REGISTER ] )
bogo_report = " Bogofilter: Category= {} , Score= {} " . format ( result . category , result . score )
bogo_report = " Bogofilter: Category= {} , Score= {} " . format ( result . category , " {:.4f} " . format ( result . score ) )
if result . category == bogofilter . SPAM :
log_print ( self . name , " SPAM: Tracking status with ID {} as spam " . format ( status [ " id " ] ) )
self . api . status_reply ( status , " @ {me} Tracked as spam\n {bogo } \n #cringefilter ". format ( me = self . api . me ( ) [ " username " ] , bogo = bogo_report ) , visibility = " direct " , untag = True )
self . respond ( status , " Tracked as spam \n {} ". format ( bogo_report ) )
time . sleep ( 1 )
else :
log_print ( self . name , " HAM: Not tracking status with ID {} as spam " . format ( status [ " id " ] ) )
self . api . status_reply ( status , " @ {me} Tracked as ham\n {bogo } \n #cringefilter ". format ( me = self . api . me ( ) [ " username " ] , bogo = bogo_report ) , visibility = " direct " , untag = True )
self . respond ( status , " Tracked as ham \n {} ". format ( bogo_report ) )
time . sleep ( 1 )
log_print ( self . name , bogo_report )
print ( )
print ( mail_text )