[Commands] Adds support for non interactive use (#2746)

Adds assume_yes to context
Changes cleanup's 100+ check
Changes cog update.
This commit is contained in:
DiscordLiz 2019-05-31 05:54:27 -04:00 committed by Michael H
parent 2cb6e98092
commit e7b615d921
3 changed files with 34 additions and 26 deletions

View File

@ -33,6 +33,9 @@ class Cleanup(commands.Cog):
Tries its best to cleanup after itself if the response is positive. Tries its best to cleanup after itself if the response is positive.
""" """
if ctx.assume_yes:
return True
prompt = await ctx.send( prompt = await ctx.send(
_("Are you sure you want to delete {number} messages? (y/n)").format(number=number) _("Are you sure you want to delete {number} messages? (y/n)").format(number=number)
) )

View File

@ -424,6 +424,8 @@ class Downloader(commands.Cog):
return await ctx.send( return await ctx.send(
_("None of the updated cogs were previously loaded. Update complete.") _("None of the updated cogs were previously loaded. Update complete.")
) )
if not ctx.assume_yes:
message = _("Would you like to reload the updated cogs?") message = _("Would you like to reload the updated cogs?")
can_react = ctx.channel.permissions_for(ctx.me).add_reactions can_react = ctx.channel.permissions_for(ctx.me).add_reactions
if not can_react: if not can_react:
@ -443,16 +445,18 @@ class Downloader(commands.Cog):
await query.delete() await query.delete()
return return
if pred.result is True: if not pred.result:
if can_react:
with contextlib.suppress(discord.Forbidden):
await query.clear_reactions()
await ctx.invoke(ctx.bot.get_cog("Core").reload, *cognames)
else:
if can_react: if can_react:
await query.delete() await query.delete()
else: else:
await ctx.send(_("OK then.")) await ctx.send(_("OK then."))
return
else:
if can_react:
with contextlib.suppress(discord.Forbidden):
await query.clear_reactions()
await ctx.invoke(ctx.bot.get_cog("Core").reload, *cognames)
@cog.command(name="list", usage="<repo_name>") @cog.command(name="list", usage="<repo_name>")
async def _cog_list(self, ctx, repo: Repo): async def _cog_list(self, ctx, repo: Repo):

View File

@ -23,6 +23,7 @@ class Context(commands.Context):
""" """
def __init__(self, **attrs): def __init__(self, **attrs):
self.assume_yes = attrs.pop("assume_yes", False)
super().__init__(**attrs) super().__init__(**attrs)
self.permission_state: PermState = PermState.NORMAL self.permission_state: PermState = PermState.NORMAL