mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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:
parent
2cb6e98092
commit
e7b615d921
@ -33,6 +33,9 @@ class Cleanup(commands.Cog):
|
||||
Tries its best to cleanup after itself if the response is positive.
|
||||
"""
|
||||
|
||||
if ctx.assume_yes:
|
||||
return True
|
||||
|
||||
prompt = await ctx.send(
|
||||
_("Are you sure you want to delete {number} messages? (y/n)").format(number=number)
|
||||
)
|
||||
|
||||
@ -424,35 +424,39 @@ class Downloader(commands.Cog):
|
||||
return await ctx.send(
|
||||
_("None of the updated cogs were previously loaded. Update complete.")
|
||||
)
|
||||
message = _("Would you like to reload the updated cogs?")
|
||||
can_react = ctx.channel.permissions_for(ctx.me).add_reactions
|
||||
if not can_react:
|
||||
message += " (y/n)"
|
||||
query: discord.Message = await ctx.send(message)
|
||||
if can_react:
|
||||
# noinspection PyAsyncCall
|
||||
start_adding_reactions(query, ReactionPredicate.YES_OR_NO_EMOJIS, ctx.bot.loop)
|
||||
pred = ReactionPredicate.yes_or_no(query, ctx.author)
|
||||
event = "reaction_add"
|
||||
else:
|
||||
pred = MessagePredicate.yes_or_no(ctx)
|
||||
event = "message"
|
||||
try:
|
||||
await ctx.bot.wait_for(event, check=pred, timeout=30)
|
||||
except asyncio.TimeoutError:
|
||||
await query.delete()
|
||||
return
|
||||
|
||||
if pred.result is True:
|
||||
if not ctx.assume_yes:
|
||||
message = _("Would you like to reload the updated cogs?")
|
||||
can_react = ctx.channel.permissions_for(ctx.me).add_reactions
|
||||
if not can_react:
|
||||
message += " (y/n)"
|
||||
query: discord.Message = await ctx.send(message)
|
||||
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:
|
||||
await query.delete()
|
||||
# noinspection PyAsyncCall
|
||||
start_adding_reactions(query, ReactionPredicate.YES_OR_NO_EMOJIS, ctx.bot.loop)
|
||||
pred = ReactionPredicate.yes_or_no(query, ctx.author)
|
||||
event = "reaction_add"
|
||||
else:
|
||||
await ctx.send(_("OK then."))
|
||||
pred = MessagePredicate.yes_or_no(ctx)
|
||||
event = "message"
|
||||
try:
|
||||
await ctx.bot.wait_for(event, check=pred, timeout=30)
|
||||
except asyncio.TimeoutError:
|
||||
await query.delete()
|
||||
return
|
||||
|
||||
if not pred.result:
|
||||
if can_react:
|
||||
await query.delete()
|
||||
else:
|
||||
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>")
|
||||
async def _cog_list(self, ctx, repo: Repo):
|
||||
|
||||
@ -23,6 +23,7 @@ class Context(commands.Context):
|
||||
"""
|
||||
|
||||
def __init__(self, **attrs):
|
||||
self.assume_yes = attrs.pop("assume_yes", False)
|
||||
super().__init__(**attrs)
|
||||
self.permission_state: PermState = PermState.NORMAL
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user