[V3 Downloader] Don't do 3rd party agreement without command args (#1821)

This commit is contained in:
Tobotimus
2018-06-09 10:18:51 +10:00
committed by Will
parent 94a64d8fae
commit e15815cd97
2 changed files with 29 additions and 38 deletions

View File

@@ -1,9 +1,9 @@
import asyncio
import discord
from discord.ext import commands
from redbot.core import commands
__all__ = ["install_agreement"]
__all__ = ["do_install_agreement"]
REPO_INSTALL_MSG = (
"You're about to add a 3rd party repository. The creator of Red"
@@ -16,32 +16,21 @@ REPO_INSTALL_MSG = (
)
def install_agreement():
async def pred(ctx: commands.Context):
downloader = ctx.command.instance
if downloader is None:
return True
elif downloader.already_agreed:
return True
elif ctx.invoked_subcommand is None or isinstance(ctx.invoked_subcommand, commands.Group):
return True
def does_agree(msg: discord.Message):
return (
ctx.author == msg.author
and ctx.channel == msg.channel
and msg.content == "I agree"
)
await ctx.send(REPO_INSTALL_MSG)
try:
await ctx.bot.wait_for("message", check=does_agree, timeout=30)
except asyncio.TimeoutError:
await ctx.send("Your response has timed out, please try again.")
return False
downloader.already_agreed = True
async def do_install_agreement(ctx: commands.Context):
downloader = ctx.cog
if downloader is None or downloader.already_agreed:
return True
return commands.check(pred)
def does_agree(msg: discord.Message):
return ctx.author == msg.author and ctx.channel == msg.channel and msg.content == "I agree"
await ctx.send(REPO_INSTALL_MSG)
try:
await ctx.bot.wait_for("message", check=does_agree, timeout=30)
except asyncio.TimeoutError:
await ctx.send("Your response has timed out, please try again.")
return False
downloader.already_agreed = True
return True