diff --git a/src/yandere_bot.py b/src/yandere_bot.py index ccb8f7b..58b042d 100644 --- a/src/yandere_bot.py +++ b/src/yandere_bot.py @@ -118,14 +118,14 @@ class YandereBot: except (MastodonIllegalArgumentError, MastodonVersionError) as e: print(e) raise FailedLogin - + # Maybe I should remove this from the backend? def print_header_stats(self, picked, date_selection, date_next_selection): picked_name = picked["profile"]["name"] if picked else None picked_url = picked["file_url"] if picked else None picked_path = picked["full_path"] if picked else None picked_nsfw = picked["nsfw"] if picked else None - picked_index = max(0, self.currentIndexCount - 1) % len(self.settings_post) + picked_index = (self.currentIndexCount - int(self.currentSessionCount > 0)) % len(self.settings_post) next_selection_seconds = max(0, int(time_diff_seconds(date_next_selection, date_selection))) print("[Profile]", picked_name, "[Index]", picked_index) @@ -247,7 +247,7 @@ class YandereBot: if tag_select == "random": pick_index = random.randint(0, len(profiles) - 1) elif tag_select == "sequential": - pick_index = max(0, self.currentIndexCount % len(profiles)) + pick_index = self.currentIndexCount % len(profiles) return profiles[pick_index] @@ -280,42 +280,27 @@ class YandereBot: # Invalid post (move to next profile) except InvalidPost as e: + self.currentIndexCount += 1 print("Invalid post:", e) + # Invalid post (remove downloaded files) except (FileTooLarge, InvalidMimeType) as e: os.remove(picked["full_path"]) - self.currentIndexCount -= 1 print("Unable to post:", e) - - except FileNotFoundError as e: - self.currentIndexCount -= 1 - print("File not found:", e) - - # Check if the file limit has been reached - except MastodonAPIError as e: - # Check if the file limit has been reached (413 error) - file_limit_reached = False - with contextlib.suppress(IndexError): - file_limit_reached = (e.args[1] == 413) - if file_limit_reached: - self.currentIndexCount -= 1 - - print("API Error:", e) - - # Server Errors - # Assume all exceptions are on the server side + + # Server Errors and other general exceptions + # Assume all exceptions are on the server side (besides FileNotFoundError of course) # If the connection is timing out it could be for two reasons: # 1. The error was caused by the user attempting to upload a large file over a slow connection: # a. FIX: Reduce settings_behavior["max_size"] # 2. The server is down. Check to verify in a web browser (this is the default assumption since the # mastodon.py API will not specify why the connection timed out). # The default assumption is #2 - except Exception as e: - print("Unhandled Exception:", e) + except (FileNotFoundError, MastodonAPIError, Exception) as e: + print("Exception:", e) # An exception occurred self.failed_uploads += 1 - self.currentIndexCount += 1 print("[Errors: {}]".format(self.failed_uploads)) # Sleep @@ -380,7 +365,11 @@ class YandereBot: # 1. User presses Ctrl+C # 2. settings_behavior["uploads_per_post"] is less than one for some reason def can_post(self): - return not self.eventSleep.is_set() and self.settings_behavior["uploads_per_post"] > 0 + return ( + not self.eventSleep.is_set() and + self.settings_behavior["uploads_per_post"] > 0 and + self.currentIndexCount >= 0 + ) def main_loop(self): target_posts = self.settings_behavior["uploads_per_post"]