✨ Made the plex functions use buttons
This commit is contained in:
@ -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():
|
||||
"""
|
||||
|
@ -6,7 +6,6 @@ Contains classes used for utilities.
|
||||
DatabaseFuncs()
|
||||
"""
|
||||
import os # Used to test if files exist
|
||||
import json # Used to read the data about add_movie/add_show
|
||||
import time # Used to test how long it's been since commands were synced
|
||||
|
||||
import re # Used in get_id
|
||||
@ -206,45 +205,6 @@ class DatabaseFuncs():
|
||||
|
||||
return game_message
|
||||
|
||||
def plex_reaction_test(self, message: discord.Message):
|
||||
"""
|
||||
Test if the given message is the response to a plex request.
|
||||
|
||||
*Parameters*
|
||||
------------
|
||||
message: discord.Message
|
||||
The message to test.
|
||||
|
||||
*Returns*
|
||||
---------
|
||||
: bool
|
||||
Whether the message is the response to a plex request.
|
||||
: bool
|
||||
Whether it was a movie request (false for a show
|
||||
request)
|
||||
: list
|
||||
A list of ids or names of the shows or movies that
|
||||
Gwendolyn presented after the request.
|
||||
"""
|
||||
channel = message.channel
|
||||
old_messages_path = "gwendolyn/resources/plex/"
|
||||
file_path = old_messages_path + f"old_message{str(channel.id)}"
|
||||
if os.path.isfile(file_path):
|
||||
with open(file_path, "r") as file_pointer:
|
||||
data = json.load(file_pointer)
|
||||
else:
|
||||
return (False, None, None)
|
||||
|
||||
if data["message_id"] != message.id:
|
||||
return (False, None, None)
|
||||
|
||||
if "imdb_ids" in data:
|
||||
return_data = (True, True, data["imdb_ids"])
|
||||
else:
|
||||
return_data = (True, False, data["imdb_names"])
|
||||
|
||||
return return_data
|
||||
|
||||
async def imdb_commands(self):
|
||||
"""Sync the slash commands with the discord API."""
|
||||
collection = self.bot.database["last synced"]
|
||||
|
Reference in New Issue
Block a user