From 1ea2f7ecbf2daea09f99e2796855ca54a91f7266 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Tue, 6 Apr 2021 11:09:38 +0200 Subject: [PATCH] :sparkles: Moved reaction code --- cogs/EventCog.py | 6 +++++ cogs/ReactionCog.py | 51 ------------------------------------------ utils/eventHandlers.py | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 51 deletions(-) delete mode 100644 cogs/ReactionCog.py diff --git a/cogs/EventCog.py b/cogs/EventCog.py index 0aa4ee7..7b72f6b 100644 --- a/cogs/EventCog.py +++ b/cogs/EventCog.py @@ -24,5 +24,11 @@ class EventCog(commands.Cog): async def on_error(self, method, *args, **kwargs): await self.bot.errorHandler.on_error(method) + # If someone reacted to a message, checks if it's a reaction it's + # Gwendolyn has been waiting for, and then does something + @commands.Cog.listener() + async def on_reaction_add(self, reaction, user): + await self.bot.eventHandler.on_reaction_add(reaction, user) + def setup(bot): bot.add_cog(EventCog(bot)) diff --git a/cogs/ReactionCog.py b/cogs/ReactionCog.py deleted file mode 100644 index d3f21bf..0000000 --- a/cogs/ReactionCog.py +++ /dev/null @@ -1,51 +0,0 @@ -from discord.ext import commands - -from utils import emojiToCommand - -class ReactionCog(commands.Cog): - def __init__(self, bot): - """Listens for reactions.""" - self.bot = bot - - @commands.Cog.listener() - async def on_reaction_add(self, reaction, user): - if user.bot == False: - message = reaction.message - channel = message.channel - self.bot.log(f"{user.display_name} reacted to a message",str(channel.id)) - try: - connectFourTheirTurn, piece = self.bot.databaseFuncs.connectFourReactionTest(channel,message,"#"+str(user.id)) - except: - connectFourTheirTurn = False - - bedreNetflixMessage, addMovie, imdbIds = self.bot.databaseFuncs.bedreNetflixReactionTest(channel, message) - - if connectFourTheirTurn: - column = emojiToCommand(reaction.emoji) - await self.bot.games.connectFour.placePiece(message, f"#{user.id}", column-1) - elif bedreNetflixMessage and addMovie: - moviePick = emojiToCommand(reaction.emoji) - await message.delete() - if moviePick == "none": - imdbID = None - else: - imdbID = imdbIds[moviePick-1] - await self.bot.other.bedreNetflix.addMovie(channel,imdbID) - elif bedreNetflixMessage and not addMovie: - showPick = emojiToCommand(reaction.emoji) - await message.delete() - if showPick == "none": - imdbName = None - else: - imdbName = imdbIds[showPick-1] - await self.bot.other.bedreNetflix.addShow(channel,imdbName) - elif self.bot.databaseFuncs.hangmanReactionTest(channel, message, f"#{user.id}"): - self.bot.log("They reacted to the hangman message") - if ord(reaction.emoji) in range(127462,127488): - guess = chr(ord(reaction.emoji)-127397) - await self.bot.games.hangman.guess(message, f"#{user.id}", guess) - else: - self.bot.log("Bot they didn't react with a valid guess") - -def setup(bot): - bot.add_cog(ReactionCog(bot)) diff --git a/utils/eventHandlers.py b/utils/eventHandlers.py index 50bfbe2..1d2de31 100644 --- a/utils/eventHandlers.py +++ b/utils/eventHandlers.py @@ -1,6 +1,8 @@ import discord, traceback, discord_slash, sys from discord.ext import commands +from .utilFunctions import emojiToCommand + class EventHandler(): def __init__(self, bot): self.bot = bot @@ -21,6 +23,45 @@ class EventHandler(): game = discord.Game("Use /help for commands") await self.bot.change_presence(activity=game, status = discord.Status.online) + async def on_reaction_add(self, reaction, user): + if user.bot == False: + message = reaction.message + channel = message.channel + self.bot.log(f"{user.display_name} reacted to a message",str(channel.id)) + try: + connectFourTheirTurn, piece = self.bot.databaseFuncs.connectFourReactionTest(channel,message,"#"+str(user.id)) + except: + connectFourTheirTurn = False + + bedreNetflixMessage, addMovie, imdbIds = self.bot.databaseFuncs.bedreNetflixReactionTest(channel, message) + + if connectFourTheirTurn: + column = emojiToCommand(reaction.emoji) + await self.bot.games.connectFour.placePiece(message, f"#{user.id}", column-1) + elif bedreNetflixMessage and addMovie: + moviePick = emojiToCommand(reaction.emoji) + await message.delete() + if moviePick == "none": + imdbID = None + else: + imdbID = imdbIds[moviePick-1] + await self.bot.other.bedreNetflix.addMovie(channel,imdbID) + elif bedreNetflixMessage and not addMovie: + showPick = emojiToCommand(reaction.emoji) + await message.delete() + if showPick == "none": + imdbName = None + else: + imdbName = imdbIds[showPick-1] + await self.bot.other.bedreNetflix.addShow(channel,imdbName) + elif self.bot.databaseFuncs.hangmanReactionTest(channel, message, f"#{user.id}"): + self.bot.log("They reacted to the hangman message") + if ord(reaction.emoji) in range(127462,127488): + guess = chr(ord(reaction.emoji)-127397) + await self.bot.games.hangman.guess(message, f"#{user.id}", guess) + else: + self.bot.log("Bot they didn't react with a valid guess") + class ErrorHandler(): def __init__(self, bot): self.bot = bot