(LionModule): Improve startup handling.
Update `cmdClient` pointer for module launch updates. Implement module launch wait logic in `pre_command`. Add details to `SafeCancellation` calls in `pre_command`.
This commit is contained in:
@@ -13,7 +13,7 @@ class LionCommand(Command):
|
|||||||
"""
|
"""
|
||||||
Subclass to allow easy attachment of custom hooks and structure to commands.
|
Subclass to allow easy attachment of custom hooks and structure to commands.
|
||||||
"""
|
"""
|
||||||
...
|
allow_before_ready = False
|
||||||
|
|
||||||
|
|
||||||
class LionModule(Module):
|
class LionModule(Module):
|
||||||
@@ -72,25 +72,38 @@ class LionModule(Module):
|
|||||||
"""
|
"""
|
||||||
Lion pre-command hook.
|
Lion pre-command hook.
|
||||||
"""
|
"""
|
||||||
|
if not self.ready and not ctx.cmd.allow_before_ready:
|
||||||
|
try:
|
||||||
|
await ctx.embed_reply(
|
||||||
|
"I am currently restarting! Please try again in a couple of minutes."
|
||||||
|
)
|
||||||
|
except discord.HTTPException:
|
||||||
|
pass
|
||||||
|
raise SafeCancellation(details="Module '{}' is not ready.".format(self.name))
|
||||||
|
|
||||||
|
# Check that the channel and guild still exists
|
||||||
|
if not ctx.client.get_guild(ctx.guild.id) or not ctx.guild.get_channel(ctx.ch.id):
|
||||||
|
raise SafeCancellation(details='Command channel is no longer reachable.')
|
||||||
|
|
||||||
# Check global user blacklist
|
# Check global user blacklist
|
||||||
if ctx.author.id in ctx.client.objects['blacklisted_users']:
|
if ctx.author.id in ctx.client.objects['blacklisted_users']:
|
||||||
raise SafeCancellation
|
raise SafeCancellation(details='User is blacklisted.')
|
||||||
|
|
||||||
if ctx.guild:
|
if ctx.guild:
|
||||||
# Check global guild blacklist
|
# Check global guild blacklist
|
||||||
if ctx.guild.id in ctx.client.objects['blacklisted_guilds']:
|
if ctx.guild.id in ctx.client.objects['blacklisted_guilds']:
|
||||||
raise SafeCancellation
|
raise SafeCancellation(details='Guild is blacklisted.')
|
||||||
|
|
||||||
# Check guild's own member blacklist
|
# Check guild's own member blacklist
|
||||||
if ctx.author.id in ctx.client.objects['ignored_members'][ctx.guild.id]:
|
if ctx.author.id in ctx.client.objects['ignored_members'][ctx.guild.id]:
|
||||||
raise SafeCancellation
|
raise SafeCancellation(details='User is ignored in this guild.')
|
||||||
|
|
||||||
# Check channel permissions are sane
|
# Check channel permissions are sane
|
||||||
if not ctx.ch.permissions_for(ctx.guild.me).send_messages:
|
if not ctx.ch.permissions_for(ctx.guild.me).send_messages:
|
||||||
raise SafeCancellation
|
raise SafeCancellation(details='I cannot send messages in this channel.')
|
||||||
if not ctx.ch.permissions_for(ctx.guild.me).embed_links:
|
if not ctx.ch.permissions_for(ctx.guild.me).embed_links:
|
||||||
await ctx.reply("I need permission to send embeds in this channel before I can run any commands!")
|
await ctx.reply("I need permission to send embeds in this channel before I can run any commands!")
|
||||||
raise SafeCancellation
|
raise SafeCancellation(details='I cannot send embeds in this channel.')
|
||||||
|
|
||||||
# Start typing
|
# Start typing
|
||||||
await ctx.ch.trigger_typing()
|
await ctx.ch.trigger_typing()
|
||||||
|
|||||||
Submodule bot/cmdClient updated: 75410acc12...6eb4269034
Reference in New Issue
Block a user