From ed3e20f50af7255b787b6ff54c373765682c0492 Mon Sep 17 00:00:00 2001 From: pocketjawa Date: Fri, 11 Aug 2017 21:04:58 -0400 Subject: [PATCH] Made setplaying write to a temp file that gets loaded on start, added command to reset the status --- helpcommand.txt | 1 + pocketbot.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/helpcommand.txt b/helpcommand.txt index 767c4c5..a97c567 100644 --- a/helpcommand.txt +++ b/helpcommand.txt @@ -10,6 +10,7 @@ **!ups**: Print the status of the main UPS. Updated once a minute. **!tohru**: Posts a random pic of the one and only Tohru! **!setplaying**: Sets the bot's Now Playing status to whatever you say (eg !setplaying with Tohru) +**!resetplaying**: Resets the bot's Now Playing status. **!xkcd**: Posts a random xkcd comic **!xkcd latest**: Posts the latest xkcd comic **!xkcd x**: Posts xkcd comic number x (if it exists) diff --git a/pocketbot.py b/pocketbot.py index fe6e2b3..39ab623 100644 --- a/pocketbot.py +++ b/pocketbot.py @@ -50,7 +50,11 @@ def on_ready(): print(client.user.id) print('------') yield from client.send_message(bot_channel_id, "This isn't Tatooine...") - yield from client.change_presence(game=discord.Game(name='with some droids')) + if os.path.isfile(cwd + "/tmp/status.txt"): + status_file = open(cwd + "/tmp/status.txt", "r") + yield from client.change_presence(game=discord.Game(name=status_file.read())) + else: + yield from client.change_presence(game=discord.Game(name='with some droids')) @client.event @asyncio.coroutine @@ -112,7 +116,17 @@ def on_message(message): #Sets the bot's Now Playing status elif message.content.lower().startswith('!setplaying'): - yield from client.change_presence(game=discord.Game(name=message.content.partition(' ')[2])) + args = message.content.partition(' ')[2] + yield from client.change_presence(game=discord.Game(name=args)) + conf_file = open(cwd + "/tmp/status.txt", "w") + conf_file.write(args) + conf_file.close() + + #Reset bot's Now Playing status + elif message.content.lower().startswith('!resetplaying'): + if os.path.isfile(cwd + "/tmp/status.txt"): + os.remove(cwd + "/tmp/status.txt") + yield from client.change_presence(game=discord.Game(name='with some droids')) #xkcd comic fetcher elif message.content.lower().startswith('!xkcd'):