Updated per FediBot refactor
This commit is contained in:
parent
cdfc853cc3
commit
0a837fac17
51
src/main.py
51
src/main.py
@ -28,24 +28,7 @@ from mastodon import MastodonAPIError
|
||||
|
||||
# A class that contains all of the rendering information for a single post
|
||||
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):
|
||||
dt_now = datetime.datetime.now()
|
||||
dt_now_str = datetime.datetime.strftime(dt_now, datetime_format)
|
||||
self.profile_name = picked["profile_name"]
|
||||
self.path = picked["path"]
|
||||
self.frames = picked["frames"]
|
||||
@ -56,9 +39,11 @@ class PickAndRenderFrame:
|
||||
self.message = picked["message"]
|
||||
self.message_nsfw = picked["message_nsfw"]
|
||||
self.render_script = picked["render_script"]
|
||||
|
||||
self.picked_frame = self._pick_frame()
|
||||
|
||||
dt_now = datetime.datetime.now()
|
||||
dt_now_str = datetime.datetime.strftime(dt_now, datetime_format)
|
||||
|
||||
# Shell-like substitutions
|
||||
translations = {
|
||||
"profile_name": self.profile_name,
|
||||
@ -115,16 +100,12 @@ class PickAndRenderFrame:
|
||||
|
||||
class YandereBot(FediBot.YandereBot):
|
||||
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)
|
||||
self.load_settings(["settings_time", "settings_post"])
|
||||
|
||||
# Maybe I should remove this from the backend?
|
||||
def print_header_stats(self, picked):
|
||||
profile, frame, nsfw, path = None, None, None, None
|
||||
profile, frame, nsfw, path = [None]*4
|
||||
|
||||
if picked:
|
||||
profile = picked.profile_name
|
||||
@ -169,12 +150,6 @@ class YandereBot(FediBot.YandereBot):
|
||||
# The post failed
|
||||
return None
|
||||
|
||||
|
||||
|
||||
class FailedToLoadCfg(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# Entry point if run from the command line
|
||||
def main():
|
||||
# Default config file
|
||||
@ -192,22 +167,12 @@ 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))
|
||||
|
||||
# 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
|
||||
)
|
||||
@ -230,7 +195,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