Updated per FediBot refactor
This commit is contained in:
parent
dab5fc33e9
commit
826e9d60ab
57
src/main.py
57
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:
|
||||
|
Reference in New Issue
Block a user