Updated per FediBot refactor
This commit is contained in:
parent
dab5fc33e9
commit
826e9d60ab
57
src/main.py
57
src/main.py
@ -35,21 +35,23 @@ class InvalidMimeType(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class YandereBot(FediBot.YandereBot):
|
class YandereBot(FediBot.YandereBot):
|
||||||
currentSessionCount = 0
|
|
||||||
currentIndexCount = 0
|
|
||||||
currentProfileIndex = []
|
|
||||||
|
|
||||||
def __init__(self, cfg, keyfile=None, debug_mode=False):
|
def __init__(self, cfg, keyfile=None, debug_mode=False):
|
||||||
settings = {
|
self.currentSessionCount = 0
|
||||||
"settings_time": {},
|
self.currentIndexCount = 0
|
||||||
"settings_post": {},
|
self.currentProfileIndex = []
|
||||||
"settings_backend": {}
|
|
||||||
}
|
|
||||||
self.settings.update(settings)
|
|
||||||
super(YandereBot, self).__init__(cfg, keyfile, debug_mode)
|
super(YandereBot, self).__init__(cfg, keyfile, debug_mode)
|
||||||
|
|
||||||
random.seed(os.urandom(16))
|
random.seed(os.urandom(16))
|
||||||
|
self.load_settings(["settings_time", "settings_post", "settings_backend"])
|
||||||
self.currentProfileIndex = [0] * len(self.settings["settings_post"])
|
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):
|
def print_header_stats(self, picked):
|
||||||
settings_post = self.settings["settings_post"]
|
settings_post = self.settings["settings_post"]
|
||||||
profile = picked["profile"]["name"] if picked else None
|
profile = picked["profile"]["name"] if picked else None
|
||||||
@ -200,11 +202,6 @@ class YandereBot(FediBot.YandereBot):
|
|||||||
def can_post(self):
|
def can_post(self):
|
||||||
return self.currentIndexCount >= 0 and super(YandereBot, self).can_post()
|
return self.currentIndexCount >= 0 and super(YandereBot, self).can_post()
|
||||||
|
|
||||||
|
|
||||||
class FailedToLoadCfg(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# Entry point if run from the command line
|
# Entry point if run from the command line
|
||||||
def main():
|
def main():
|
||||||
# Default config file
|
# Default config file
|
||||||
@ -226,40 +223,28 @@ def main():
|
|||||||
parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER)
|
parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER)
|
||||||
arguments = parser.parse_args()
|
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
|
# Flag if the bot is running in debug mode
|
||||||
debug_mode = arguments.dry_run or arguments.debug
|
debug_mode = arguments.dry_run or arguments.debug
|
||||||
|
|
||||||
|
# Yandere Lewd Bot
|
||||||
yandere = YandereBot(
|
yandere = YandereBot(
|
||||||
yandere_config,
|
arguments.config,
|
||||||
arguments.keyfile,
|
arguments.keyfile,
|
||||||
debug_mode,
|
debug_mode,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if arguments.list:
|
||||||
|
yandere.print_profiles()
|
||||||
|
return
|
||||||
|
|
||||||
if arguments.zfill:
|
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)
|
yandere.currentIndexCount = int(arguments.index)
|
||||||
if arguments.state:
|
if arguments.state:
|
||||||
state = arguments.state.split(",")
|
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...")
|
print("State length does not match profile length. Ignoring...")
|
||||||
else:
|
else:
|
||||||
yandere.currentProfileIndex = list(map(int, state))
|
yandere.currentProfileIndex = list(map(int, state))
|
||||||
@ -282,7 +267,7 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
# Exceptions raised from the main function
|
# Exceptions raised from the main function
|
||||||
except FailedToLoadCfg:
|
except FediBot.FailedToLoadCfg:
|
||||||
sys.exit(10)
|
sys.exit(10)
|
||||||
# Exceptions raised from the bot
|
# Exceptions raised from the bot
|
||||||
except FediBot.Debug:
|
except FediBot.Debug:
|
||||||
|
Reference in New Issue
Block a user