Made the plex functions use buttons

This commit is contained in:
NikolajDanger
2021-08-18 21:12:32 +02:00
parent ae71ff631d
commit 3819e56cd6
6 changed files with 305 additions and 307 deletions

View File

@ -15,7 +15,7 @@ import discord # Used to init discord.Game and discord.Status, as well
from discord.ext import commands # Used to compare errors with command
# errors
from discord_slash.context import SlashContext
from discord_slash.context import SlashContext, ComponentContext
from gwendolyn.utils.util_functions import emoji_to_command
@ -72,13 +72,6 @@ class EventHandler():
channel = message.channel
reacted_message = f"{user.display_name} reacted to a message"
self.bot.log(reacted_message, str(channel.id))
plex_data = tests.plex_reaction_test(message)
# plex_data is a list containing 3 elements: whether it was
# the add_show/add_movie command message the reaction was to
# (bool), whether it's a movie (bool) (if false, it's a
# show), and the imdb ids/names for the for the movies or
# shows listed in the message (list).
reaction_test_parameters = [message, f"#{str(user.id)}"]
if tests.connect_four_reaction_test(*reaction_test_parameters):
@ -86,34 +79,6 @@ class EventHandler():
params = [message, f"#{user.id}", column-1]
await self.bot.games.connect_four.place_piece(*params)
if plex_data[0]:
plex_functions = self.bot.other.plex
if plex_data[1]:
movie_pick = emoji_to_command(reaction.emoji)
if movie_pick == "none":
imdb_id = None
else:
imdb_id = plex_data[2][movie_pick-1]
if isinstance(channel, discord.DMChannel):
await message.delete()
await plex_functions.add_movie(message, imdb_id, False)
else:
await message.clear_reactions()
await plex_functions.add_movie(message, imdb_id)
else:
show_pick = emoji_to_command(reaction.emoji)
if show_pick == "none":
imdb_name = None
else:
imdb_name = plex_data[2][show_pick-1]
if isinstance(channel, discord.DMChannel):
await message.delete()
await plex_functions.add_show(message, imdb_name, False)
else:
await message.clear_reactions()
await plex_functions.add_show(message, imdb_name)
elif tests.hangman_reaction_test(*reaction_test_parameters):
self.bot.log("They reacted to the hangman message")
@ -126,6 +91,25 @@ class EventHandler():
else:
self.bot.log("Bot they didn't react with a valid guess")
async def on_component(self, ctx: ComponentContext):
info = ctx.custom_id.split(":")
channel = ctx.origin_message.channel
if info[0] == "plex":
if info[1] == "movie":
await self.bot.other.plex.add_movie(
ctx.origin_message,
info[2],
not isinstance(channel, discord.DMChannel)
)
if info[1] == "show":
await self.bot.other.plex.add_show(
ctx.origin_message,
info[2],
not isinstance(channel, discord.DMChannel)
)
class ErrorHandler():
"""