Refactored pick to return dictionary

This commit is contained in:
Anon 2023-03-12 16:27:11 -07:00
parent 8be03dd7a9
commit de8ee32fc3

View File

@ -142,9 +142,6 @@ class YandereBot(FediBot.YandereBot):
print(e) print(e)
raise MissingMasterList raise MissingMasterList
def get_post_text(self, picked, media_list):
super(YandereBot, self).get_post_text(picked.get_post_setting()["message"], media_list)
def load_picture_list(self): def load_picture_list(self):
list_blacklist = self.read_blacklist_files() list_blacklist = self.read_blacklist_files()
self.listPictures = self.load_pictures(list_blacklist) self.listPictures = self.load_pictures(list_blacklist)
@ -162,11 +159,20 @@ class YandereBot(FediBot.YandereBot):
)) ))
def pick(self): def pick(self):
return self.listPictures.pop(0) picked = self.listPictures.pop(0)
media_list = self.get_media_list(picked)
spoiler = picked.get_post_setting()["spoiler"]
message = picked.get_post_setting()["message"]
return {
"picked": picked,
"media_list": media_list,
"spoiler": spoiler,
"message": message,
}
def after_pick(self, picked): def after_pick(self, picked):
self.blacklist(picked) self.blacklist(picked["picked"])
self.print_header_stats(picked) self.print_header_stats(picked["picked"])
def post(self, picked): def post(self, picked):
reinsert_image = False reinsert_image = False
@ -174,7 +180,7 @@ class YandereBot(FediBot.YandereBot):
return super(YandereBot, self).post(picked) return super(YandereBot, self).post(picked)
# Attempted to post a file that doesn't exist (immediately repost ignoring retry_seconds) # Attempted to post a file that doesn't exist (immediately repost ignoring retry_seconds)
except (FileNotFoundError, FediBot.InvalidPost): except (FileNotFoundError, FediBot.InvalidPost):
print("File not found:", picked.get_hash_path()) print("File not found:", picked["picked"].get_hash_path())
reinsert_image = False reinsert_image = False
# Check if the file limit has been reached # Check if the file limit has been reached
@ -199,7 +205,7 @@ class YandereBot(FediBot.YandereBot):
reinsert_image = True reinsert_image = True
if reinsert_image and self.consecutive_failed_uploads < self.settings["settings_behavior"]["max_errors"]: if reinsert_image and self.consecutive_failed_uploads < self.settings["settings_behavior"]["max_errors"]:
self.listPictures.insert(0, picked) self.listPictures.insert(0, picked["picked"])
self.handle_post_exception() self.handle_post_exception()
@ -210,6 +216,12 @@ class YandereBot(FediBot.YandereBot):
def can_post(self): def can_post(self):
return bool(len(self.listPictures)) and super(YandereBot, self).can_post() return bool(len(self.listPictures)) and super(YandereBot, self).can_post()
def start(self):
super(YandereBot, self).start()
# Return 1 if there are still pictures in the picture list
return len(self.listPictures) > 0
class FailedToLoadCfg(Exception): class FailedToLoadCfg(Exception):
pass pass