wrap up catch-up mode, add tweets nuker

This commit is contained in:
muskit
2022-09-27 15:09:09 -07:00
committed by msk
parent 07e7e28dcb
commit 4f53bda1f8
6 changed files with 154 additions and 33 deletions
+18 -4
View File
@@ -2,6 +2,7 @@ import sys
import asyncio
import argparse
from argparse import RawTextHelpFormatter
import code
import nest_asyncio
@@ -14,8 +15,9 @@ from twapi import TwAPI
PROGRAM_ARGS = None
MODES_HELP_STR = '''mode to run the bot at:
l,listen: listen for new tweets from all accounts; will not terminate unless error occurs
c,catchup: scan all tweets from all accounts; will terminate when done'''
l,listen: listen for new tweets from all accounts; will not terminate unless error occurs
c,catchup: scan all tweets from all accounts; will terminate when done
d,delete-all: delete all tweets on account provided by secrets.ini; make sure the function is uncommented in twapi.py'''
def init_argparse():
p = argparse.ArgumentParser(description='Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.', formatter_class=RawTextHelpFormatter)
@@ -23,12 +25,21 @@ def init_argparse():
help=MODES_HELP_STR)
p.add_argument('--show-tokens', action='store_true', help='[DO NOT USE IN PUBLIC SETTING] print stored tokens from secrets.ini')
p.add_argument('--announce-catchup', action='store_true', help='In catch-up mode, post a tweet announcing catch-up mode.')
p.add_argument('--no-delay', action='store_true', help='In self-destruct mode, clear tweets without safety waiting.')
return p
def command_line():
# TODO: implement command line mode for manually controlling the bot
print('Shell coming soon. For now, here\'s a Python interpretor.')
code.interact(local=globals())
pass
async def self_destruct():
if not PROGRAM_ARGS.no_delay:
print('\033[31;6m-----DELETING ALL TWEETS IN 10 SECONDS!! PRESS CTRL+C TO CANCEL.-----\033[0m')
await asyncio.sleep(10)
await TwAPI.instance.nuke_tweets()
async def async_main():
global PROGRAM_ARGS
@@ -40,9 +51,12 @@ async def async_main():
case 'c' | 'catchup':
print('RUNNING IN CATCH-UP MODE\n')
await catchup.run(PROGRAM_ARGS)
case _:
case 'd' | 'delete-all':
print('WARNING: SELF-DESTRUCT MODE')
await self_destruct()
case 'cmd':
command_line()
#TODO: remove message
case _:
print('\ninvalid mode. run with no arguments or "-h" for help page, including mode list.')
return