Updated per FediBot refactor

This commit is contained in:
Anon 2023-05-14 17:21:01 -07:00
parent cdfc853cc3
commit 0a837fac17

View File

@ -28,24 +28,7 @@ from mastodon import MastodonAPIError
# A class that contains all of the rendering information for a single post # A class that contains all of the rendering information for a single post
class PickAndRenderFrame: class PickAndRenderFrame:
# From Config File
profile_name = ""
path = ""
frames = 0
skip = tuple()
nsfw = tuple()
output_name = ""
message = ""
message_nsfw = ""
render_script = ""
# After pick
picked_frame = None
output_name_tr = ""
def __init__(self, picked, datetime_format): def __init__(self, picked, datetime_format):
dt_now = datetime.datetime.now()
dt_now_str = datetime.datetime.strftime(dt_now, datetime_format)
self.profile_name = picked["profile_name"] self.profile_name = picked["profile_name"]
self.path = picked["path"] self.path = picked["path"]
self.frames = picked["frames"] self.frames = picked["frames"]
@ -56,9 +39,11 @@ class PickAndRenderFrame:
self.message = picked["message"] self.message = picked["message"]
self.message_nsfw = picked["message_nsfw"] self.message_nsfw = picked["message_nsfw"]
self.render_script = picked["render_script"] self.render_script = picked["render_script"]
self.picked_frame = self._pick_frame() self.picked_frame = self._pick_frame()
dt_now = datetime.datetime.now()
dt_now_str = datetime.datetime.strftime(dt_now, datetime_format)
# Shell-like substitutions # Shell-like substitutions
translations = { translations = {
"profile_name": self.profile_name, "profile_name": self.profile_name,
@ -115,16 +100,12 @@ class PickAndRenderFrame:
class YandereBot(FediBot.YandereBot): class YandereBot(FediBot.YandereBot):
def __init__(self, cfg, keyfile=None, debug_mode=False): def __init__(self, cfg, keyfile=None, debug_mode=False):
settings = {
"settings_time": {},
"settings_post": {},
}
self.settings.update(settings)
super(YandereBot, self).__init__(cfg, keyfile, debug_mode) super(YandereBot, self).__init__(cfg, keyfile, debug_mode)
self.load_settings(["settings_time", "settings_post"])
# Maybe I should remove this from the backend? # Maybe I should remove this from the backend?
def print_header_stats(self, picked): def print_header_stats(self, picked):
profile, frame, nsfw, path = None, None, None, None profile, frame, nsfw, path = [None]*4
if picked: if picked:
profile = picked.profile_name profile = picked.profile_name
@ -169,12 +150,6 @@ class YandereBot(FediBot.YandereBot):
# The post failed # The post failed
return None return None
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
@ -192,22 +167,12 @@ 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))
# 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
) )
@ -230,7 +195,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: