✨
This commit is contained in:
@@ -3,15 +3,15 @@ Classes used to handle bot events and errors.
|
||||
|
||||
*Classes*
|
||||
---------
|
||||
EventHandler
|
||||
ErrorHandler
|
||||
EventHandler
|
||||
ErrorHandler
|
||||
"""
|
||||
import traceback # Used to get the traceback of errors
|
||||
|
||||
import discord # Used to init discord.Game and discord.Status, as well
|
||||
# as compare errors to discord errors and as typehints
|
||||
# as compare errors to discord errors and as typehints
|
||||
from discord.ext import commands # Used to compare errors with command
|
||||
# errors
|
||||
# errors
|
||||
|
||||
from interactions import SlashContext, ComponentContext
|
||||
from gwendolyn_old.utils.util_functions import decode_id
|
||||
@@ -19,88 +19,88 @@ from gwendolyn_old.exceptions import InvalidInteraction
|
||||
|
||||
|
||||
class EventHandler():
|
||||
"""
|
||||
Handles bot events.
|
||||
"""
|
||||
Handles bot events.
|
||||
|
||||
*Methods*
|
||||
---------
|
||||
on_ready()
|
||||
on_slash_command(ctx: interactions.SlashContext)
|
||||
on_reaction_add(ctx: interactions.SlashContext)
|
||||
"""
|
||||
*Methods*
|
||||
---------
|
||||
on_ready()
|
||||
on_slash_command(ctx: interactions.SlashContext)
|
||||
on_reaction_add(ctx: interactions.SlashContext)
|
||||
"""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the handler."""
|
||||
self.bot = bot
|
||||
def __init__(self, bot):
|
||||
"""Initialize the handler."""
|
||||
self.bot = bot
|
||||
|
||||
async def on_ready(self):
|
||||
"""Log and sets status when it logs in."""
|
||||
await self.bot.database_funcs.imdb_commands()
|
||||
name = self.bot.user.name
|
||||
userid = str(self.bot.user.id)
|
||||
logged_in_message = f"Logged in as {name}, {userid}"
|
||||
self.bot.log(logged_in_message, level=25)
|
||||
game = discord.Game("Use /help for commands")
|
||||
async def on_ready(self):
|
||||
"""Log and sets status when it logs in."""
|
||||
await self.bot.database_funcs.imdb_commands()
|
||||
name = self.bot.user.name
|
||||
userid = str(self.bot.user.id)
|
||||
logged_in_message = f"Logged in as {name}, {userid}"
|
||||
self.bot.log(logged_in_message, level=25)
|
||||
game = discord.Game("Use /help for commands")
|
||||
|
||||
online_status = discord.Status.online
|
||||
await self.bot.change_presence(activity=game, status=online_status)
|
||||
online_status = discord.Status.online
|
||||
await self.bot.change_presence(activity=game, status=online_status)
|
||||
|
||||
async def on_slash_command(self, ctx: SlashContext):
|
||||
"""Log when a slash command is given."""
|
||||
if ctx.subcommand_name is not None:
|
||||
subcommand = f" {ctx.subcommand_name} "
|
||||
else:
|
||||
subcommand = " "
|
||||
async def on_slash_command(self, ctx: SlashContext):
|
||||
"""Log when a slash command is given."""
|
||||
if ctx.subcommand_name is not None:
|
||||
subcommand = f" {ctx.subcommand_name} "
|
||||
else:
|
||||
subcommand = " "
|
||||
|
||||
if ctx.subcommand_group is not None:
|
||||
sub_command_group = f"{ctx.subcommand_group} "
|
||||
else:
|
||||
sub_command_group = ""
|
||||
if ctx.subcommand_group is not None:
|
||||
sub_command_group = f"{ctx.subcommand_group} "
|
||||
else:
|
||||
sub_command_group = ""
|
||||
|
||||
args = " ".join([str(i) for i in ctx.args])
|
||||
full_command = f"/{ctx.command}{subcommand}{sub_command_group}{args}"
|
||||
log_message = f"{ctx.author.display_name} ran {full_command}"
|
||||
self.bot.log(log_message, str(ctx.channel_id), level=25)
|
||||
args = " ".join([str(i) for i in ctx.args])
|
||||
full_command = f"/{ctx.command}{subcommand}{sub_command_group}{args}"
|
||||
log_message = f"{ctx.author.display_name} ran {full_command}"
|
||||
self.bot.log(log_message, str(ctx.channel_id), level=25)
|
||||
|
||||
async def on_component(self, ctx: ComponentContext):
|
||||
"""Handle component interaction."""
|
||||
info = decode_id(ctx.custom_id)
|
||||
self.bot.log(f"Component action with info {info}")
|
||||
channel = ctx.channel
|
||||
author = str(ctx.author_id)
|
||||
async def on_component(self, ctx: ComponentContext):
|
||||
"""Handle component interaction."""
|
||||
info = decode_id(ctx.custom_id)
|
||||
self.bot.log(f"Component action with info {info}")
|
||||
channel = ctx.channel
|
||||
author = str(ctx.author_id)
|
||||
|
||||
if info[0].lower() == "plex":
|
||||
if info[1].lower() == "movie":
|
||||
await self.bot.other.plex.add_movie(
|
||||
ctx.origin_message,
|
||||
info[2],
|
||||
not isinstance(channel, discord.DMChannel)
|
||||
)
|
||||
return
|
||||
if info[0].lower() == "plex":
|
||||
if info[1].lower() == "movie":
|
||||
await self.bot.other.plex.add_movie(
|
||||
ctx.origin_message,
|
||||
info[2],
|
||||
not isinstance(channel, discord.DMChannel)
|
||||
)
|
||||
return
|
||||
|
||||
elif info[1].lower() == "show":
|
||||
await self.bot.other.plex.add_show(
|
||||
ctx.origin_message,
|
||||
info[2],
|
||||
not isinstance(channel, discord.DMChannel)
|
||||
)
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
elif info[1].lower() == "show":
|
||||
await self.bot.other.plex.add_show(
|
||||
ctx.origin_message,
|
||||
info[2],
|
||||
not isinstance(channel, discord.DMChannel)
|
||||
)
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
|
||||
elif info[0].lower() == "hangman" and author == info[2]:
|
||||
if info[1].lower() == "guess":
|
||||
await self.bot.games.hangman.guess(ctx, *info[3:])
|
||||
elif info[1].lower() == "end":
|
||||
await self.bot.games.hangman.stop(ctx, *info[3:])
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
elif info[0].lower() == "connectfour":
|
||||
connect_four = self.bot.games.connect_four
|
||||
if info[1].lower() == "place" and author == info[2]:
|
||||
await connect_four.place_piece(
|
||||
ctx,
|
||||
info[3],
|
||||
int(info[4]),
|
||||
elif info[0].lower() == "hangman" and author == info[2]:
|
||||
if info[1].lower() == "guess":
|
||||
await self.bot.games.hangman.guess(ctx, *info[3:])
|
||||
elif info[1].lower() == "end":
|
||||
await self.bot.games.hangman.stop(ctx, *info[3:])
|
||||
else:
|
||||
raise InvalidInteraction(ctx.custom_id, info)
|
||||
elif info[0].lower() == "connectfour":
|
||||
connect_four = self.bot.games.connect_four
|
||||
if info[1].lower() == "place" and author == info[2]:
|
||||
await connect_four.place_piece(
|
||||
ctx,
|
||||
info[3],
|
||||
int(info[4]),
|
||||
[int(info[5]), int(info[6])],
|
||||
int(info[7]),
|
||||
ctx.author_id,
|
||||
|
||||
Reference in New Issue
Block a user