From 3c21e661fda56455aa294e73476579a6c129d3c3 Mon Sep 17 00:00:00 2001 From: phi1997 Date: Thu, 2 May 2024 19:38:36 -0500 Subject: [PATCH 1/3] Allow title of game in alt text to be set in configuration. --- bot.py | 7 ++++++- config.toml.example | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 8631e14..7b1de68 100644 --- a/bot.py +++ b/bot.py @@ -161,7 +161,8 @@ def run(self): self.gameboy.empty_directory(gif_dir) image = self.gameboy.screenshot() - media = self.retry_mastodon_call(self.mastodon.media_post, retries=5, interval=10, media_file=image, description='Screenshot of Pokemon Gold') + alt_text = 'Screenshot of ' + self.gameboy_config.get('title') + media = self.retry_mastodon_call(self.mastodon.media_post, retries=5, interval=10, media_file=image, description=alt_text) media_ids = [] try: # Probably add a check here if generating a gif is enabled (so we don't have to generate one every single hour?) previous_frames = self.gameboy.get_recent_frames("screenshots", 25) @@ -175,13 +176,17 @@ def run(self): # time.sleep(45) # media = self.mastodon.media_post(image, description='Screenshot of pokemon gold') #time.sleep(50) + post = self.retry_mastodon_call(self.mastodon.status_post, retries=5, interval=10, status=f"Previous Action: {top_result}\n\n#pokemon #gameboy #nintendo #FediPlaysPokemon", media_ids=[media_ids]) + #post = self.retry_mastodon_call(self.mastodon.status_post, retries=5, interval=10, status=f"Previous Action: {top_result}\n\nTest account", media_ids=[media_ids]) #try: # post = self.mastodon.status_post(f"Previous Action: {top_result}\n\n#pokemon #gameboy #nintendo", media_ids=[media['id']]) #except: # time.sleep(30) # post = self.mastodon.status_post(f"Previous Action: {top_result}\n\n#pokemon #gamebody #nintendo", media_ids=[media['id']]) + poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\n#FediPlaysPokemon", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️", "🅰", "🅱", "Start", "Select"], reply_id=post['id'] ) + #poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\nTest account", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️"], reply_id=post['id'] ) #ry: # poll = self.post_poll("Vote on the next action:", ["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️", "🅰", "🅱", "Start", "Select"], reply_id=post['id']) diff --git a/config.toml.example b/config.toml.example index c656ea8..4bee34c 100644 --- a/config.toml.example +++ b/config.toml.example @@ -4,3 +4,6 @@ access_token = "" [gameboy] rom = "Pokemon - Gold Version.gbc" + +[post] +title = "Pokémon Gold" \ No newline at end of file From 0595c3750f7f590bbe61487d433ac927dc774b8f Mon Sep 17 00:00:00 2001 From: phi1997 Date: Fri, 3 May 2024 12:50:27 -0500 Subject: [PATCH 2/3] Add support for configurable poll duration, add default value for alt text in case the game's title isn't set, and correct example config. --- bot.py | 8 +++++--- config.toml.example | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 7b1de68..cc01237 100644 --- a/bot.py +++ b/bot.py @@ -161,7 +161,7 @@ def run(self): self.gameboy.empty_directory(gif_dir) image = self.gameboy.screenshot() - alt_text = 'Screenshot of ' + self.gameboy_config.get('title') + alt_text = 'Screenshot of ' + self.gameboy_config.get('title', 'a Game Boy game.') media = self.retry_mastodon_call(self.mastodon.media_post, retries=5, interval=10, media_file=image, description=alt_text) media_ids = [] try: # Probably add a check here if generating a gif is enabled (so we don't have to generate one every single hour?) @@ -170,6 +170,8 @@ def run(self): media_ids = [media['id'], previous_media['id']] except: media_ids = [media['id']] + + poll_duration = self.mastodon_config.get('poll_duration', 60) #try: # media = self.mastodon.media_post(image, description='Screenshot of pokemon gold') #except: @@ -185,8 +187,8 @@ def run(self): # time.sleep(30) # post = self.mastodon.status_post(f"Previous Action: {top_result}\n\n#pokemon #gamebody #nintendo", media_ids=[media['id']]) - poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\n#FediPlaysPokemon", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️", "🅰", "🅱", "Start", "Select"], reply_id=post['id'] ) - #poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\nTest account", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️"], reply_id=post['id'] ) + poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\n#FediPlaysPokemon", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️", "🅰", "🅱", "Start", "Select"], expires_in=poll_duration*60, reply_id=post['id'] ) + #poll = self.retry_mastodon_call(self.post_poll, retries=5, interval=10, status="Vote on the next action:\n\nTest account", options=["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️"], expires_in=poll_duration*60, reply_id=post['id'] ) #ry: # poll = self.post_poll("Vote on the next action:", ["Up ⬆️", "Down ⬇️", "Right ➡️ ", "Left ⬅️", "🅰", "🅱", "Start", "Select"], reply_id=post['id']) diff --git a/config.toml.example b/config.toml.example index 4bee34c..dd0e1d4 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,9 +1,8 @@ [mastodon] server = "https://tomkahe.com" access_token = "" +poll_duration = 60 [gameboy] rom = "Pokemon - Gold Version.gbc" - -[post] title = "Pokémon Gold" \ No newline at end of file From eab258d0ef0799dd7c4b75de904b58f81ec8151f Mon Sep 17 00:00:00 2001 From: Tom Casavant Date: Sun, 5 May 2024 12:15:05 -0400 Subject: [PATCH 3/3] Fixed pep8 whitespace issues, re-add accidentally removed functionality from merge --- bot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 40f01ea..0fe6efd 100644 --- a/bot.py +++ b/bot.py @@ -197,10 +197,10 @@ def run(self): image = self.gameboy.screenshot() alt_text = 'Screenshot of ' + self.gameboy_config.get('title', 'a Game Boy game.') media = self.retry_mastodon_call( - self.mastodon.media_post, - retries=5, - interval=10, - media_file=image, + self.mastodon.media_post, + retries=5, + interval=10, + media_file=image, description=alt_text ) media_ids = [] @@ -230,6 +230,8 @@ def run(self): media_ids=[media_ids], ) + poll_duration = self.mastodon_config.get('poll_duration', 60) + poll = self.retry_mastodon_call( self.post_poll, retries=5, @@ -245,6 +247,7 @@ def run(self): "Start", "Select", ], + expires_in=poll_duration*60, reply_id=post["id"], )