2022-09-24 17:56:58 -07:00
import sys
2022-09-25 03:39:15 -07:00
import asyncio
2022-09-24 17:56:58 -07:00
import argparse
from argparse import RawTextHelpFormatter
2022-09-25 03:39:15 -07:00
import nest_asyncio
2022-09-24 17:56:58 -07:00
import talent_lists
import api_secrets
import catchup
import listen
2022-09-25 18:31:50 -07:00
from twapi import TwAPI
2022-09-24 17:56:58 -07:00
2022-09-27 02:49:03 -07:00
PROGRAM_ARGS = None
2022-09-24 17:56:58 -07:00
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 '''
def init_argparse ( ) :
p = argparse . ArgumentParser ( description = ' Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members. ' , formatter_class = RawTextHelpFormatter )
p . add_argument ( ' mode ' , nargs = ' ? ' , \
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 ' )
2022-09-27 02:49:03 -07:00
p . add_argument ( ' --announce-catchup ' , action = ' store_true ' , help = ' In catch-up mode, post a tweet announcing catch-up mode. ' )
2022-09-24 17:56:58 -07:00
return p
def command_line ( ) :
2022-09-27 02:49:03 -07:00
# TODO: implement command line mode for manually controlling the bot
2022-09-24 17:56:58 -07:00
pass
2022-09-27 02:49:03 -07:00
async def async_main ( ) :
global PROGRAM_ARGS
## Determine running mode
match PROGRAM_ARGS . mode . lower ( ) :
case ' l ' | ' listen ' :
print ( ' RUNNING IN LISTEN MODE \n ' )
listen . run ( )
case ' c ' | ' catchup ' :
print ( ' RUNNING IN CATCH-UP MODE \n ' )
await catchup . run ( PROGRAM_ARGS )
case _ :
command_line ( )
#TODO: remove message
print ( ' \n invalid mode. run with no arguments or " -h " for help page, including mode list. ' )
return
def main ( ) :
global PROGRAM_ARGS
2022-09-24 17:56:58 -07:00
parser = init_argparse ( )
if len ( sys . argv ) < 2 :
parser . print_help ( )
return
2022-09-27 02:49:03 -07:00
PROGRAM_ARGS = parser . parse_args ( )
2022-09-24 17:56:58 -07:00
2022-09-27 02:49:03 -07:00
if PROGRAM_ARGS . show_tokens :
2022-09-24 17:56:58 -07:00
print ( api_secrets . get_all_secrets ( ) )
2022-09-27 02:49:03 -07:00
if PROGRAM_ARGS . mode is None : return
2022-09-24 17:56:58 -07:00
## We expect to run in some mode now.
# Initialize shared API instance
twApi = TwAPI . instance = TwAPI ( )
# Initialize talent account lists
talent_lists . init ( )
2022-09-27 02:49:03 -07:00
## Asynchronous execution
nest_asyncio . apply ( )
asyncio . run ( async_main ( ) )
2022-09-24 17:56:58 -07:00
if __name__ == " __main__ " :
2022-09-27 02:49:03 -07:00
main ( )