(LCtx): Refactor utility wrapping.

This commit is contained in:
2022-01-20 07:48:13 +02:00
parent 6f8748a722
commit ef81ab7afe
3 changed files with 91 additions and 88 deletions

View File

@@ -461,41 +461,3 @@ async def ask(ctx, msg, timeout=30, use_msg=None, del_on_timeout=False):
if result in ["n", "no"]:
return 0
return 1
# this reply() will be overide baseContext's reply with LionContext's, whcih can
# hook pre_execution of any util.
# Using this system, Module now have much power to change Context's utils
@LionContext.util
async def reply(ctx, content=None, allow_everyone=False, **kwargs):
"""
Helper function to reply in the current channel.
"""
if not allow_everyone:
if content:
content = lib.sterilise_content(content)
message = await ctx.ch.send(content=content, **kwargs)
ctx.sent_messages.append(message)
return message
# this reply() will be overide baseContext's reply
@LionContext.util
async def error_reply(ctx, error_str):
"""
Notify the user of a user level error.
Typically, this will occur in a red embed, posted in the command channel.
"""
embed = discord.Embed(
colour=discord.Colour.red(),
description=error_str,
timestamp=datetime.datetime.utcnow()
)
try:
message = await ctx.ch.send(embed=embed)
ctx.sent_messages.append(message)
return message
except discord.Forbidden:
message = await ctx.reply(error_str)
ctx.sent_messages.append(message)
return message