From 04495d7fccc9aaae740b4f4f909699e3a7f9d0ca Mon Sep 17 00:00:00 2001 From: phi1997 Date: Sun, 5 May 2024 20:17:39 -0500 Subject: [PATCH 1/4] Add option in example config file for game-specific modes for when feature is implemented. --- config.toml.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.toml.example b/config.toml.example index 041bd8d..4ffbfdc 100644 --- a/config.toml.example +++ b/config.toml.example @@ -7,3 +7,7 @@ poll_duration = 60 rom = "Pokemon - Gold Version.gbc" title = "Pokémon Gold" gif_outline="gameboy.png" +# Modes: +# "generic": Default mode, no game-specific messages +# "gs": Adds messages with player info for Pokémon Gold/Silver Versions. May not be compatible with Crystal. +mode = "generic" From 9fe0c716cfc26e5cc20c8578dd9ab2f87af4e0dd Mon Sep 17 00:00:00 2001 From: phi1997 Date: Tue, 7 May 2024 19:36:17 -0500 Subject: [PATCH 2/4] Add debug option to replace full poll options with just the directions or just the buttons. This is intended for testing the bot on a server that do not allow 8 options for polls and is not intended for use in a prod environment. --- bot.py | 34 ++++++++++++++++++++++++++-------- config.toml.example | 5 +++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 6c69995..14869fd 100644 --- a/bot.py +++ b/bot.py @@ -28,6 +28,7 @@ def __init__(self, config_path="config.toml"): self.config = toml.load(config_file) self.mastodon_config = self.config.get("mastodon", {}) self.gameboy_config = self.config.get("gameboy", {}) + self.debug_config = self.config.get("debug", {}) self.mastodon = self.login() print(self.gameboy_config.get("rom")) @@ -236,21 +237,38 @@ def run(self): poll_duration = self.mastodon_config.get('poll_duration', 60) - poll = self.retry_mastodon_call( - self.post_poll, - retries=5, - interval=10, - status="Vote on the next action:\n\n#FediPlaysPokemon", - options=[ + poll_options = [ + "Up ⬆️", + "Down ⬇️", + "Right ➡️ ", + "Left ⬅️", + "🅰", + "🅱", + "Start", + "Select", + ] + + if self.debug_config.get("poll_options", "full") == "directions": + poll_options = [ "Up ⬆️", "Down ⬇️", "Right ➡️ ", - "Left ⬅️", + "Left ⬅️" + ] + elif self.debug_config.get("poll_options", "full") == "buttons": + poll_options = [ "🅰", "🅱", "Start", "Select", - ], + ] + + poll = self.retry_mastodon_call( + self.post_poll, + retries=5, + interval=10, + status="Vote on the next action:\n\n#FediPlaysPokemon", + options=poll_options, expires_in=poll_duration*60, reply_id=post["id"], ) diff --git a/config.toml.example b/config.toml.example index 4ffbfdc..e055dd5 100644 --- a/config.toml.example +++ b/config.toml.example @@ -11,3 +11,8 @@ gif_outline="gameboy.png" # "generic": Default mode, no game-specific messages # "gs": Adds messages with player info for Pokémon Gold/Silver Versions. May not be compatible with Crystal. mode = "generic" + +[debug] +# Limit what buttons can be pressed. Accepts "full" (default), "directions", or "buttons". +# Mostly used to test on servers with only 4 options allowed per poll. +poll_options = "full" \ No newline at end of file From c78302d95b25f2899d4fd84856840ac6948a9614 Mon Sep 17 00:00:00 2001 From: phi1997 Date: Tue, 7 May 2024 19:44:29 -0500 Subject: [PATCH 3/4] Add configuration options for the status messages accompanying screenshots and polls. This was added to avoid the test account from getting attention on popular hashtags, but those values shouldn't be hard-coded anyway in case the bot is used for a non-Pokemon game. --- bot.py | 7 ++++--- config.toml.example | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index 14869fd..0775751 100644 --- a/bot.py +++ b/bot.py @@ -229,8 +229,8 @@ def run(self): retries=5, interval=10, status=( - f"Previous Action: {top_result}\n\n" - "#pokemon #gameboy #nintendo #FediPlaysPokemon" + f"Previous Action: {top_result}\n\n" + + self.mastodon_config.get("screenshot_status", "") ), media_ids=[media_ids], ) @@ -267,7 +267,8 @@ def run(self): self.post_poll, retries=5, interval=10, - status="Vote on the next action:\n\n#FediPlaysPokemon", + status="Vote on the next action:\n\n" + + self.mastodon_config.get("poll_status", ""), options=poll_options, expires_in=poll_duration*60, reply_id=post["id"], diff --git a/config.toml.example b/config.toml.example index e055dd5..3cc8010 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,6 +1,8 @@ [mastodon] server = "https://tomkahe.com" access_token = "" +screenshot_status = "#pokemon #gameboy #nintendo #FediPlaysPokemon" +poll_status = "#FediPlaysPokemon" poll_duration = 60 [gameboy] From cbdcc7db4c3a2b54d237a634474a20398ac9422e Mon Sep 17 00:00:00 2001 From: phi1997 Date: Thu, 9 May 2024 12:43:40 -0500 Subject: [PATCH 4/4] Add configuration option for defining save state path. This is useful for running multiple games or instances of games in the same environment. --- bot.py | 8 ++++---- config.toml.example | 1 + gb.py | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bot.py b/bot.py index 0775751..09822f3 100644 --- a/bot.py +++ b/bot.py @@ -166,7 +166,7 @@ def run(self): """ Runs the main gameplay, reads mastodon poll result, takes action, generates new posts """ - self.gameboy.load() + self.gameboy.load(self.gameboy_config.get("save_state_path", "save.state")) post_id, poll_id = self.read_ids() top_result = None @@ -302,11 +302,11 @@ def run(self): self.save_ids(post["id"], poll["id"]) # Save game state - self.gameboy.save() + self.gameboy.save(self.gameboy_config.get("save_state_path", "save.state")) def test(self): """Method used for testing""" - self.gameboy.load() + self.gameboy.load(self.gameboy_config.get("save_state_path", "save.state")) self.gameboy.get_recent_frames("screenshots", 25) # self.gameboy.build_gif("gif_images") while True: @@ -334,7 +334,7 @@ def test(self): self.gameboy.empty_directory(gif_dir) else: print(f"No action defined for '{inp}'.") - self.gameboy.save() + self.gameboy.save(self.gameboy_config.get("save_state_path", "save.state")) # self.gameboy.build_gif("gif_images") # self.take_action(inp) # self.gameboy.tick(300) diff --git a/config.toml.example b/config.toml.example index 3cc8010..deb7bd2 100644 --- a/config.toml.example +++ b/config.toml.example @@ -8,6 +8,7 @@ poll_duration = 60 [gameboy] rom = "Pokemon - Gold Version.gbc" title = "Pokémon Gold" +save_state_path = "save.state" gif_outline="gameboy.png" # Modes: # "generic": Default mode, no game-specific messages diff --git a/gb.py b/gb.py index b0f7033..cf3e713 100644 --- a/gb.py +++ b/gb.py @@ -251,11 +251,11 @@ def random_button(self): ) button() - def load(self): + def load(self, state): """Loads the save state""" # Get the directory of the current script script_dir = os.path.dirname(os.path.realpath(__file__)) - save_loc = os.path.join(script_dir, "save.state") + save_loc = os.path.join(script_dir, state) result = False if os.path.exists(save_loc): with open(save_loc, "rb") as file: @@ -265,11 +265,11 @@ def load(self): print("Save state does not exist") return result - def save(self): + def save(self, state): """Saves current state to a file""" # Get the directory of the current script script_dir = os.path.dirname(os.path.realpath(__file__)) - save_loc = os.path.join(script_dir, "save.state") + save_loc = os.path.join(script_dir, state) with open(save_loc, "wb") as file: self.pyboy.save_state(file)