Improved error handling; Introduced i18n for /register, /unregister and /guess
This commit is contained in:
@@ -4,6 +4,7 @@ from discord.utils import basic_autocomplete
|
||||
from libbot.i18n import _, in_every_locale
|
||||
|
||||
from classes import PycordEvent, PycordGuild, PycordUser
|
||||
from classes.errors import EventNotFoundError, GuildNotFoundError
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autocomplete_user_registered_events, is_operation_confirmed
|
||||
|
||||
@@ -39,13 +40,16 @@ class CogUnregister(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
|
||||
|
||||
try:
|
||||
pycord_event: PycordEvent = await self.bot.find_event(event_id=event)
|
||||
except (InvalidId, RuntimeError):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Event was not found.")
|
||||
except (InvalidId, EventNotFoundError):
|
||||
await ctx.respond(self.bot._("event_not_found", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
if not guild.is_configured():
|
||||
@@ -55,22 +59,18 @@ class CogUnregister(Cog):
|
||||
user: PycordUser = await self.bot.find_user(ctx.author, ctx.guild)
|
||||
|
||||
if user.is_jailed:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond(
|
||||
"You are jailed and cannot interact with events. Please, contact the administrator."
|
||||
)
|
||||
await ctx.respond(self.bot._("jailed_error", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
if pycord_event._id not in user.registered_event_ids:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("You are not registered for this event.")
|
||||
await ctx.respond(self.bot._("unregister_not_registered", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
await user.event_unregister(pycord_event._id, cache=self.bot.cache)
|
||||
|
||||
# TODO Text channel must be locked and updated
|
||||
|
||||
await ctx.respond("You are no longer registered for this event.")
|
||||
await ctx.respond(self.bot._("unregister_unregistered", "messages", locale=ctx.locale))
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
|
Reference in New Issue
Block a user