Improved error handling; Introduced i18n for /register, /unregister and /guess
This commit is contained in:
@@ -7,6 +7,7 @@ from discord.utils import basic_autocomplete
|
||||
from libbot.i18n import _, in_every_locale
|
||||
|
||||
from classes import PycordEvent, PycordEventStage, PycordGuild
|
||||
from classes.errors import GuildNotFoundError, EventStageNotFoundError, EventNotFoundError
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import (
|
||||
autocomplete_active_events,
|
||||
@@ -76,7 +77,11 @@ class CogStage(Cog):
|
||||
answer: str,
|
||||
media: Attachment = None,
|
||||
) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
try:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
except (InvalidId, GuildNotFoundError):
|
||||
await ctx.respond(self.bot._("unexpected_error", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
|
||||
@@ -84,7 +89,7 @@ class CogStage(Cog):
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
except (InvalidId, EventStageNotFoundError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
@@ -186,7 +191,11 @@ class CogStage(Cog):
|
||||
media: Attachment = None,
|
||||
remove_media: bool = False,
|
||||
) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
try:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
except (InvalidId, GuildNotFoundError):
|
||||
await ctx.respond(self.bot._("unexpected_error", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
|
||||
@@ -194,7 +203,7 @@ class CogStage(Cog):
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
except (InvalidId, EventNotFoundError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
@@ -204,7 +213,7 @@ class CogStage(Cog):
|
||||
|
||||
try:
|
||||
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
||||
except (InvalidId, RuntimeError):
|
||||
except (InvalidId, EventStageNotFoundError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event stage was not found.")
|
||||
return
|
||||
@@ -267,7 +276,11 @@ class CogStage(Cog):
|
||||
if not (await is_operation_confirmed(ctx, confirm)):
|
||||
return
|
||||
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
try:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
except (InvalidId, GuildNotFoundError):
|
||||
await ctx.respond(self.bot._("unexpected_error", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
|
||||
@@ -275,7 +288,7 @@ class CogStage(Cog):
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
except (InvalidId, EventNotFoundError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
return
|
||||
@@ -285,7 +298,7 @@ class CogStage(Cog):
|
||||
|
||||
try:
|
||||
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
|
||||
except (InvalidId, RuntimeError):
|
||||
except (InvalidId, EventStageNotFoundError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event stage was not found.")
|
||||
return
|
||||
|
Reference in New Issue
Block a user