From a74c5906a362bb132aac099fe24c21c32dc5ab9d Mon Sep 17 00:00:00 2001 From: Bobloy Date: Mon, 14 May 2018 13:32:49 -0400 Subject: [PATCH 1/5] Optimize imports and reformat --- hangman/hangman.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hangman/hangman.py b/hangman/hangman.py index 4958eac..f47b5da 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -2,10 +2,8 @@ from collections import defaultdict from random import randint import discord - -from redbot.core import Config, checks -from redbot.core import commands -from redbot.core.data_manager import cog_data_path, load_basic_configuration +from redbot.core import Config, checks, commands +from redbot.core.data_manager import cog_data_path class Hangman: @@ -26,7 +24,7 @@ class Hangman: lambda: {"running": False, "hangman": 0, "guesses": [], "trackmessage": False, "answer": ''}) self.path = str(cog_data_path(self)).replace('\\', '/') - self.answer_path = self.path+"/bundled_data/hanganswers.txt" + self.answer_path = self.path + "/bundled_data/hanganswers.txt" self.winbool = defaultdict(lambda: False) @@ -331,4 +329,3 @@ class Hangman: await self._reactmessage_menu(message) await self._checkdone(channel) - From 3a2f4332920429ed8958bfee2a152e7464e503a5 Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 7 Sep 2018 09:43:03 -0400 Subject: [PATCH 2/5] allow toggleable automatic letter emoji reactions --- hangman/hangman.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hangman/hangman.py b/hangman/hangman.py index f47b5da..602baa2 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -16,6 +16,7 @@ class Hangman: self.config = Config.get_conf(self, identifier=1049711010310997110) default_guild = { "theface": ':thinking:', + "emojis": True, } self.config.register_guild(**default_guild) @@ -127,7 +128,7 @@ class Hangman: async def hangset(self, ctx): """Adjust hangman settings""" if not ctx.invoked_subcommand: - await ctx.send_help() + pass @hangset.command(pass_context=True) async def face(self, ctx: commands.Context, theface): @@ -148,6 +149,14 @@ class Hangman: await self._update_hanglist() await ctx.send("Face has been updated!") + @hangset.command(pass_context=True) + async def toggleemoji(self, ctx: commands.Context): + """Toggles whether to automatically react with the alphabet""" + + current = await self.config.guild(ctx.guild).emojis() + await self.config.guild(ctx.guild).emojis.set(not current) + await ctx.send("Emoji Letter reactions have been set to {}".format(not current)) + @commands.command(aliases=['hang'], pass_context=True) async def hangman(self, ctx, guess: str = None): """Play a game of hangman against the bot!""" @@ -252,7 +261,7 @@ class Hangman: return if user == self.bot.user: - return # Don't remove bot's own reactions + return # Don't react to bot's own reactions message = reaction.message emoji = reaction.emoji @@ -271,12 +280,18 @@ class Hangman: async def _reactmessage_menu(self, message): """React with menu options""" + if not await self.config.guild(message.guild).emojis(): + return + await message.clear_reactions() await message.add_reaction(self.navigate[0]) await message.add_reaction(self.navigate[-1]) async def _reactmessage_am(self, message): + if not await self.config.guild(message.guild).emojis(): + return + await message.clear_reactions() for x in range(len(self.letters)): @@ -286,6 +301,8 @@ class Hangman: await message.add_reaction(self.navigate[-1]) async def _reactmessage_nz(self, message): + if not await self.config.guild(message.guild).emojis(): + return await message.clear_reactions() for x in range(len(self.letters)): From d84eb775732b50052054020ee8567b2ddfde215b Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 7 Sep 2018 09:48:21 -0400 Subject: [PATCH 3/5] Don't error on failure to clear reactions. --- hangman/hangman.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hangman/hangman.py b/hangman/hangman.py index 602baa2..1569999 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -278,12 +278,18 @@ class Hangman: if str(emoji) == self.navigate[-1]: await self._reactmessage_nz(message) + async def _try_clear_reactions(self, message): + try: + await message.clear_reactions() + except discord.Forbidden: + pass + async def _reactmessage_menu(self, message): """React with menu options""" if not await self.config.guild(message.guild).emojis(): return - await message.clear_reactions() + await self._try_clear_reactions(message) await message.add_reaction(self.navigate[0]) await message.add_reaction(self.navigate[-1]) @@ -292,7 +298,7 @@ class Hangman: if not await self.config.guild(message.guild).emojis(): return - await message.clear_reactions() + await self._try_clear_reactions(message) for x in range(len(self.letters)): if x in [i for i, b in enumerate("ABCDEFGHIJKLM") if b not in self._guesslist(message.guild)]: @@ -303,7 +309,8 @@ class Hangman: async def _reactmessage_nz(self, message): if not await self.config.guild(message.guild).emojis(): return - await message.clear_reactions() + + await self._try_clear_reactions(message) for x in range(len(self.letters)): if x in [i for i, b in enumerate("NOPQRSTUVWXYZ") if b not in self._guesslist(message.guild)]: From 01f7ba038d410fa5f8a614ddbbc4e61343e07632 Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 7 Sep 2018 09:51:12 -0400 Subject: [PATCH 4/5] Extra space --- hangman/hangman.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/hangman/hangman.py b/hangman/hangman.py index 1569999..16fb462 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -320,11 +320,8 @@ class Hangman: def _make_say(self, guild): c_say = "Guess this: " + str(self._hideanswer(guild)) + "\n" - c_say += "Used Letters: " + str(self._guesslist(guild)) + "\n" - c_say += self.hanglist[guild][self.the_data[guild]["hangman"]] + "\n" - c_say += self.navigate[0] + " for A-M, " + self.navigate[-1] + " for N-Z" return c_say From 9f3dc8ee89f2bfa648d731b5b5e1f6f943730b7d Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 7 Sep 2018 09:52:07 -0400 Subject: [PATCH 5/5] Command descriptions --- hangman/hangman.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hangman/hangman.py b/hangman/hangman.py index 16fb462..6e5dba6 100644 --- a/hangman/hangman.py +++ b/hangman/hangman.py @@ -132,6 +132,7 @@ class Hangman: @hangset.command(pass_context=True) async def face(self, ctx: commands.Context, theface): + """Set the face of the hangman""" message = ctx.message # Borrowing FlapJack's emoji validation # (https://github.com/flapjax/FlapJack-Cogs/blob/master/smartreact/smartreact.py)