[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 asyncio
import discord import discord
from discord.ext import commands from redbot.core import commands
__all__ = ["install_agreement"] __all__ = ["do_install_agreement"]
REPO_INSTALL_MSG = ( REPO_INSTALL_MSG = (
"You're about to add a 3rd party repository. The creator of Red" "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 do_install_agreement(ctx: commands.Context):
async def pred(ctx: commands.Context): downloader = ctx.cog
downloader = ctx.command.instance if downloader is None or downloader.already_agreed:
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
return True 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

View File

@ -15,7 +15,7 @@ from redbot.core.utils.chat_formatting import box, pagify
from redbot.core import commands from redbot.core import commands
from redbot.core.bot import Red from redbot.core.bot import Red
from .checks import install_agreement from .checks import do_install_agreement
from .converters import InstalledCog from .converters import InstalledCog
from .errors import CloningError, ExistingGitRepo from .errors import CloningError, ExistingGitRepo
from .installable import Installable from .installable import Installable
@ -214,7 +214,6 @@ class Downloader:
await ctx.send_help() await ctx.send_help()
@repo.command(name="add") @repo.command(name="add")
@install_agreement()
async def _repo_add(self, ctx, name: str, repo_url: str, branch: str = None): async def _repo_add(self, ctx, name: str, repo_url: str, branch: str = None):
""" """
Add a new repo to Downloader. Add a new repo to Downloader.
@ -222,6 +221,9 @@ class Downloader:
Name can only contain characters A-z, numbers and underscore Name can only contain characters A-z, numbers and underscore
Branch will default to master if not specified Branch will default to master if not specified
""" """
agreed = await do_install_agreement(ctx)
if not agreed:
return
try: try:
# noinspection PyTypeChecker # noinspection PyTypeChecker
repo = await self._repo_manager.add_repo(name=name, url=repo_url, branch=branch) repo = await self._repo_manager.add_repo(name=name, url=repo_url, branch=branch)