Files
Gwendolyn/cogs/ReactionCog.py
2021-04-04 15:18:53 +02:00

52 lines
2.2 KiB
Python

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))