From 826e9d60ab029b36afefe6211149996b8e1f47f2 Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 14 May 2023 17:20:09 -0700 Subject: [PATCH] Updated per FediBot refactor --- src/main.py | 57 ++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/main.py b/src/main.py index cb9b4b3..b18909a 100755 --- a/src/main.py +++ b/src/main.py @@ -35,20 +35,22 @@ class InvalidMimeType(Exception): class YandereBot(FediBot.YandereBot): - currentSessionCount = 0 - currentIndexCount = 0 - currentProfileIndex = [] - def __init__(self, cfg, keyfile=None, debug_mode=False): - settings = { - "settings_time": {}, - "settings_post": {}, - "settings_backend": {} - } - self.settings.update(settings) + self.currentSessionCount = 0 + self.currentIndexCount = 0 + self.currentProfileIndex = [] + super(YandereBot, self).__init__(cfg, keyfile, debug_mode) + random.seed(os.urandom(16)) + self.load_settings(["settings_time", "settings_post", "settings_backend"]) self.currentProfileIndex = [0] * len(self.settings["settings_post"]) + + def print_profiles(self): + for x in self.settings["settings_post"]: + for y in x: + print(y["name"], end=",") + print("") def print_header_stats(self, picked): settings_post = self.settings["settings_post"] @@ -200,11 +202,6 @@ class YandereBot(FediBot.YandereBot): def can_post(self): return self.currentIndexCount >= 0 and super(YandereBot, self).can_post() - -class FailedToLoadCfg(Exception): - pass - - # Entry point if run from the command line def main(): # Default config file @@ -226,40 +223,28 @@ def main(): parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER) arguments = parser.parse_args() - # Yandere Lewd Bot - yandere = None - yandere_config = None - - # Configuration file for Yandere Lewd Bot - try: - import importlib - yandere_config = importlib.import_module(arguments.config) - except ImportError: - raise FailedToLoadCfg("Invalid config file: {}".format(arguments.config)) - - if arguments.list: - for x in yandere_config.settings_post: - for y in x: - print(y["name"], end=",") - print("") - return 1 # Flag if the bot is running in debug mode debug_mode = arguments.dry_run or arguments.debug + # Yandere Lewd Bot yandere = YandereBot( - yandere_config, + arguments.config, arguments.keyfile, debug_mode, ) + if arguments.list: + yandere.print_profiles() + return + if arguments.zfill: - yandere.currentProfileIndex = list(map(int, [arguments.zfill]*len(yandere_config.settings_post))) + yandere.currentProfileIndex = list(map(int, [arguments.zfill]*len(yandere.settings["settings_post"]))) yandere.currentIndexCount = int(arguments.index) if arguments.state: state = arguments.state.split(",") - if len(state) != len(yandere_config.settings_post): + if len(state) != len(yandere.settings["settings_post"]): print("State length does not match profile length. Ignoring...") else: yandere.currentProfileIndex = list(map(int, state)) @@ -282,7 +267,7 @@ if __name__ == "__main__": try: sys.exit(main()) # Exceptions raised from the main function - except FailedToLoadCfg: + except FediBot.FailedToLoadCfg: sys.exit(10) # Exceptions raised from the bot except FediBot.Debug: