Make command usage in help for required arguments consistent (#4589)

* Make command usage in help for required arguments consistent

* Bob 3

* Bob 1

* Docstring updates

* Address Flame's review

* Update cog guides in docs
This commit is contained in:
jack1142
2020-12-22 20:14:47 +01:00
committed by GitHub
parent 59e1e31634
commit b36a702e62
9 changed files with 109 additions and 214 deletions

View File

@@ -478,7 +478,7 @@ class Downloader(commands.Cog):
for page in pagify(content):
await target.send(page)
@commands.command()
@commands.command(require_var_positional=True)
@checks.is_owner()
async def pipinstall(self, ctx: commands.Context, *deps: str) -> None:
"""
@@ -492,11 +492,8 @@ class Downloader(commands.Cog):
**Arguments**
- `[deps...]` The package or packages you wish to install.
- `<deps...>` The package or packages you wish to install.
"""
if not deps:
await ctx.send_help()
return
repo = Repo("", "", "", "", Path.cwd())
async with ctx.typing():
success = await repo.install_raw_requirements(deps, self.LIB_PATH)
@@ -582,7 +579,7 @@ class Downloader(commands.Cog):
if repo.install_msg:
await ctx.send(repo.install_msg.replace("[p]", ctx.clean_prefix))
@repo.command(name="delete", aliases=["remove", "del"], usage="<repo_name>")
@repo.command(name="delete", aliases=["remove", "del"])
async def _repo_del(self, ctx: commands.Context, repo: Repo) -> None:
"""
Remove a repo and its files.
@@ -592,7 +589,7 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The name of an already added repo
- `<repo>` The name of an already added repo
"""
await self._repo_manager.delete_repo(repo.name)
@@ -612,7 +609,7 @@ class Downloader(commands.Cog):
for page in pagify(joined, ["\n"], shorten_by=16):
await ctx.send(box(page.lstrip(" "), lang="diff"))
@repo.command(name="info", usage="<repo_name>")
@repo.command(name="info")
async def _repo_info(self, ctx: commands.Context, repo: Repo) -> None:
"""Show information about a repo.
@@ -621,7 +618,7 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The name of the repo to show info about.
- `<repo>` The name of the repo to show info about.
"""
made_by = ", ".join(repo.author) or _("Missing from info.json")
@@ -737,7 +734,7 @@ class Downloader(commands.Cog):
)
)
@cog.command(name="install", usage="<repo_name> <cogs>")
@cog.command(name="install", usage="<repo> <cogs...>", require_var_positional=True)
async def _cog_install(self, ctx: commands.Context, repo: Repo, *cog_names: str) -> None:
"""Install a cog from the given repo.
@@ -747,14 +744,16 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The name of the repo to install cogs from.
- `<cogs>` The cog or cogs to install.
- `<repo>` The name of the repo to install cogs from.
- `<cogs...>` The cog or cogs to install.
"""
await self._cog_installrev(ctx, repo, None, cog_names)
@cog.command(name="installversion", usage="<repo_name> <revision> <cogs>")
@cog.command(
name="installversion", usage="<repo> <revision> <cogs...>", require_var_positional=True
)
async def _cog_installversion(
self, ctx: commands.Context, repo: Repo, rev: str, *cog_names: str
self, ctx: commands.Context, repo: Repo, revision: str, *cog_names: str
) -> None:
"""Install a cog from the specified revision of given repo.
@@ -768,18 +767,15 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The name of the repo to install cogs from.
- `<repo>` The name of the repo to install cogs from.
- `<revision>` The revision to install from.
- `<cogs>` The cog or cogs to install.
- `<cogs...>` The cog or cogs to install.
"""
await self._cog_installrev(ctx, repo, rev, cog_names)
await self._cog_installrev(ctx, repo, revision, cog_names)
async def _cog_installrev(
self, ctx: commands.Context, repo: Repo, rev: Optional[str], cog_names: Iterable[str]
) -> None:
if not cog_names:
await ctx.send_help()
return
commit = None
async with ctx.typing():
if rev is not None:
@@ -859,8 +855,8 @@ class Downloader(commands.Cog):
"\nYou can load them using {command_1}."
" To see end user data statements, you can use {command_2}."
).format(
command_1=inline(f"{ctx.clean_prefix}load <cogs>"),
command_2=inline(f"{ctx.clean_prefix}cog info <repo_name> <cog_name>"),
command_1=inline(f"{ctx.clean_prefix}load <cogs...>"),
command_2=inline(f"{ctx.clean_prefix}cog info <repo> <cog>"),
)
+ message
)
@@ -870,7 +866,7 @@ class Downloader(commands.Cog):
if cog.install_msg:
await ctx.send(cog.install_msg.replace("[p]", ctx.clean_prefix))
@cog.command(name="uninstall", usage="<cogs>")
@cog.command(name="uninstall", require_var_positional=True)
async def _cog_uninstall(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
"""Uninstall cogs.
@@ -883,11 +879,8 @@ class Downloader(commands.Cog):
**Arguments**
- `<cogs>` The cog or cogs to uninstall.
- `<cogs...>` The cog or cogs to uninstall.
"""
if not cogs:
await ctx.send_help()
return
async with ctx.typing():
uninstalled_cogs = []
failed_cogs = []
@@ -923,7 +916,7 @@ class Downloader(commands.Cog):
)
await self.send_pagified(ctx, message)
@cog.command(name="pin", usage="<cogs>")
@cog.command(name="pin", require_var_positional=True)
async def _cog_pin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
"""Pin cogs - this will lock cogs on their current version.
@@ -933,11 +926,8 @@ class Downloader(commands.Cog):
**Arguments**
- `<cogs>` The cog or cogs to pin. Must already be installed.
- `<cogs...>` The cog or cogs to pin. Must already be installed.
"""
if not cogs:
await ctx.send_help()
return
already_pinned = []
pinned = []
for cog in set(cogs):
@@ -955,7 +945,7 @@ class Downloader(commands.Cog):
message += _("\nThese cogs were already pinned: ") + humanize_list(already_pinned)
await self.send_pagified(ctx, message)
@cog.command(name="unpin", usage="<cogs>")
@cog.command(name="unpin", require_var_positional=True)
async def _cog_unpin(self, ctx: commands.Context, *cogs: InstalledCog) -> None:
"""Unpin cogs - this will remove the update lock from those cogs.
@@ -965,10 +955,7 @@ class Downloader(commands.Cog):
**Arguments**
- `<cogs>` The cog or cogs to unpin. Must already be installed and pinned."""
if not cogs:
await ctx.send_help()
return
- `<cogs...>` The cog or cogs to unpin. Must already be installed and pinned."""
not_pinned = []
unpinned = []
for cog in set(cogs):
@@ -1062,7 +1049,7 @@ class Downloader(commands.Cog):
"""
await self._cog_update_logic(ctx, cogs=cogs)
@cog.command(name="updateallfromrepos", usage="<repos>")
@cog.command(name="updateallfromrepos", require_var_positional=True)
async def _cog_updateallfromrepos(self, ctx: commands.Context, *repos: Repo) -> None:
"""Update all cogs from repos of your choosing.
@@ -1072,16 +1059,13 @@ class Downloader(commands.Cog):
**Arguments**
- `<repos>` The repo or repos to update all cogs from.
- `<repos...>` The repo or repos to update all cogs from.
"""
if not repos:
await ctx.send_help()
return
await self._cog_update_logic(ctx, repos=repos)
@cog.command(name="updatetoversion", usage="<repo_name> <revision> [cogs]")
@cog.command(name="updatetoversion")
async def _cog_updatetoversion(
self, ctx: commands.Context, repo: Repo, rev: str, *cogs: InstalledCog
self, ctx: commands.Context, repo: Repo, revision: str, *cogs: InstalledCog
) -> None:
"""Update all cogs, or ones of your choosing to chosen revision of one repo.
@@ -1096,11 +1080,11 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The repo or repos to update all cogs from.
- `<repo>` The repo or repos to update all cogs from.
- `<revision>` The revision to update to.
- `[cogs]` The cog or cogs to update.
- `[cogs...]` The cog or cogs to update.
"""
await self._cog_update_logic(ctx, repo=repo, rev=rev, cogs=cogs)
await self._cog_update_logic(ctx, repo=repo, rev=revision, cogs=cogs)
async def _cog_update_logic(
self,
@@ -1219,7 +1203,7 @@ class Downloader(commands.Cog):
if updates_available and updated_cognames:
await self._ask_for_cog_reload(ctx, updated_cognames)
@cog.command(name="list", usage="<repo_name>")
@cog.command(name="list")
async def _cog_list(self, ctx: commands.Context, repo: Repo) -> None:
"""List all available cogs from a single repo.
@@ -1228,7 +1212,7 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The repo to list cogs from.
- `<repo>` The repo to list cogs from.
"""
installed = await self.installed_cogs()
installed_str = ""
@@ -1251,7 +1235,7 @@ class Downloader(commands.Cog):
for page in pagify(cogs, ["\n"], shorten_by=16):
await ctx.send(box(page.lstrip(" "), lang="diff"))
@cog.command(name="info", usage="<repo_name> <cog_name>")
@cog.command(name="info", usage="<repo> <cog>")
async def _cog_info(self, ctx: commands.Context, repo: Repo, cog_name: str) -> None:
"""List information about a single cog.
@@ -1260,8 +1244,8 @@ class Downloader(commands.Cog):
**Arguments**
- `<repo_name>` The repo to get cog info from.
- `<cog_name>` The cog to get info on.
- `<repo>` The repo to get cog info from.
- `<cog>` The cog to get info on.
"""
cog = discord.utils.get(repo.available_cogs, name=cog_name)
if cog is None:
@@ -1490,7 +1474,7 @@ class Downloader(commands.Cog):
_("\nEnd user data statements of these cogs have changed: ")
+ humanize_list(tuple(map(inline, cogs_with_changed_eud_statement)))
+ _("\nYou can use {command} to see the updated statements.\n").format(
command=inline(f"{ctx.clean_prefix}cog info <repo_name> <cog_name>")
command=inline(f"{ctx.clean_prefix}cog info <repo> <cog>")
)
)
if failed_cogs:

View File

@@ -176,14 +176,8 @@ class Image(commands.Cog):
@commands.guild_only()
@commands.command()
async def gif(self, ctx, *keywords):
async def gif(self, ctx, *, keywords):
"""Retrieve the first search result from Giphy."""
if keywords:
keywords = "+".join(keywords)
else:
await ctx.send_help()
return
giphy_api_key = (await ctx.bot.get_shared_api_tokens("GIPHY")).get("api_key")
if not giphy_api_key:
await ctx.send(
@@ -193,11 +187,8 @@ class Image(commands.Cog):
)
return
url = "http://api.giphy.com/v1/gifs/search?&api_key={}&q={}".format(
giphy_api_key, keywords
)
async with self.session.get(url) as r:
url = "http://api.giphy.com/v1/gifs/search"
async with self.session.get(url, params={"api_key": giphy_api_key, "q": keywords}) as r:
result = await r.json()
if r.status == 200:
if result["data"]:
@@ -209,14 +200,8 @@ class Image(commands.Cog):
@commands.guild_only()
@commands.command()
async def gifr(self, ctx, *keywords):
async def gifr(self, ctx, *, keywords):
"""Retrieve a random GIF from a Giphy search."""
if keywords:
keywords = "+".join(keywords)
else:
await ctx.send_help()
return
giphy_api_key = (await ctx.bot.get_shared_api_tokens("GIPHY")).get("api_key")
if not giphy_api_key:
await ctx.send(
@@ -226,11 +211,8 @@ class Image(commands.Cog):
)
return
url = "http://api.giphy.com/v1/gifs/random?&api_key={}&tag={}".format(
giphy_api_key, keywords
)
async with self.session.get(url) as r:
url = "http://api.giphy.com/v1/gifs/random"
async with self.session.get(url, params={"api_key": giphy_api_key, "tag": keywords}) as r:
result = await r.json()
if r.status == 200:
if result["data"]:

View File

@@ -362,7 +362,7 @@ class KickBanMixin(MixinMeta):
await ctx.send(message)
@commands.command(aliases=["hackban"])
@commands.command(aliases=["hackban"], usage="<user_ids...> [days] [reason]")
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)
@checks.admin_or_permissions(ban_members=True)

View File

@@ -374,9 +374,7 @@ class Permissions(commands.Cog):
await self._permissions_acl_set(ctx, guild_id=ctx.guild.id, update=True)
@checks.is_owner()
@permissions.command(
name="addglobalrule", usage="<allow_or_deny> <cog_or_command> <who_or_what>..."
)
@permissions.command(name="addglobalrule", require_var_positional=True)
async def permissions_addglobalrule(
self,
ctx: commands.Context,
@@ -391,11 +389,8 @@ class Permissions(commands.Cog):
`<cog_or_command>` is the cog or command to add the rule to.
This is case sensitive.
`<who_or_what>` is one or more users, channels or roles the rule is for.
`<who_or_what...>` is one or more users, channels or roles the rule is for.
"""
if not who_or_what:
await ctx.send_help()
return
for w in who_or_what:
await self._add_rule(
rule=cast(bool, allow_or_deny),
@@ -408,9 +403,7 @@ class Permissions(commands.Cog):
@commands.guild_only()
@checks.guildowner_or_permissions(administrator=True)
@permissions.command(
name="addserverrule",
usage="<allow_or_deny> <cog_or_command> <who_or_what>...",
aliases=["addguildrule"],
name="addserverrule", aliases=["addguildrule"], require_var_positional=True
)
async def permissions_addguildrule(
self,
@@ -426,11 +419,8 @@ class Permissions(commands.Cog):
`<cog_or_command>` is the cog or command to add the rule to.
This is case sensitive.
`<who_or_what>` is one or more users, channels or roles the rule is for.
`<who_or_what...>` is one or more users, channels or roles the rule is for.
"""
if not who_or_what:
await ctx.send_help()
return
for w in who_or_what:
await self._add_rule(
rule=cast(bool, allow_or_deny),
@@ -441,7 +431,7 @@ class Permissions(commands.Cog):
await ctx.send(_("Rule added."))
@checks.is_owner()
@permissions.command(name="removeglobalrule", usage="<cog_or_command> <who_or_what>...")
@permissions.command(name="removeglobalrule", require_var_positional=True)
async def permissions_removeglobalrule(
self,
ctx: commands.Context,
@@ -453,11 +443,8 @@ class Permissions(commands.Cog):
`<cog_or_command>` is the cog or command to remove the rule
from. This is case sensitive.
`<who_or_what>` is one or more users, channels or roles the rule is for.
`<who_or_what...>` is one or more users, channels or roles the rule is for.
"""
if not who_or_what:
await ctx.send_help()
return
for w in who_or_what:
await self._remove_rule(cog_or_cmd=cog_or_command, model_id=w.id, guild_id=GLOBAL)
await ctx.send(_("Rule removed."))
@@ -465,9 +452,7 @@ class Permissions(commands.Cog):
@commands.guild_only()
@checks.guildowner_or_permissions(administrator=True)
@permissions.command(
name="removeserverrule",
usage="<cog_or_command> <who_or_what>...",
aliases=["removeguildrule"],
name="removeserverrule", aliases=["removeguildrule"], require_var_positional=True
)
async def permissions_removeguildrule(
self,
@@ -480,11 +465,8 @@ class Permissions(commands.Cog):
`<cog_or_command>` is the cog or command to remove the rule
from. This is case sensitive.
`<who_or_what>` is one or more users, channels or roles the rule is for.
`<who_or_what...>` is one or more users, channels or roles the rule is for.
"""
if not who_or_what:
await ctx.send_help()
return
for w in who_or_what:
await self._remove_rule(
cog_or_cmd=cog_or_command, model_id=w.id, guild_id=ctx.guild.id

View File

@@ -299,12 +299,9 @@ class Streams(commands.Cog):
pass
@streamalert.group(name="twitch", invoke_without_command=True)
async def _twitch(self, ctx: commands.Context, channel_name: str = None):
async def _twitch(self, ctx: commands.Context, channel_name: str):
"""Manage Twitch stream notifications."""
if channel_name is not None:
await ctx.invoke(self.twitch_alert_channel, channel_name)
else:
await ctx.send_help()
await ctx.invoke(self.twitch_alert_channel, channel_name)
@_twitch.command(name="channel")
async def twitch_alert_channel(self, ctx: commands.Context, channel_name: str):
@@ -528,7 +525,7 @@ class Streams(commands.Cog):
@message.command(name="mention")
@commands.guild_only()
async def with_mention(self, ctx: commands.Context, *, message: str = None):
async def with_mention(self, ctx: commands.Context, *, message: str):
"""Set stream alert message when mentions are enabled.
Use `{mention}` in the message to insert the selected mentions.
@@ -536,28 +533,22 @@ class Streams(commands.Cog):
For example: `[p]streamset message mention {mention}, {stream} is live!`
"""
if message is not None:
guild = ctx.guild
await self.config.guild(guild).live_message_mention.set(message)
await ctx.send(_("Stream alert message set!"))
else:
await ctx.send_help()
guild = ctx.guild
await self.config.guild(guild).live_message_mention.set(message)
await ctx.send(_("Stream alert message set!"))
@message.command(name="nomention")
@commands.guild_only()
async def without_mention(self, ctx: commands.Context, *, message: str = None):
async def without_mention(self, ctx: commands.Context, *, message: str):
"""Set stream alert message when mentions are disabled.
Use `{stream}` in the message to insert the channel or user name.
For example: `[p]streamset message nomention {stream} is live!`
"""
if message is not None:
guild = ctx.guild
await self.config.guild(guild).live_message_nomention.set(message)
await ctx.send(_("Stream alert message set!"))
else:
await ctx.send_help()
guild = ctx.guild
await self.config.guild(guild).live_message_nomention.set(message)
await ctx.send(_("Stream alert message set!"))
@message.command(name="clear")
@commands.guild_only()

View File

@@ -279,7 +279,7 @@ class Trivia(commands.Cog):
else:
await ctx.send(_("Trivia file was not found."))
@commands.group(invoke_without_command=True)
@commands.group(invoke_without_command=True, require_var_positional=True)
@commands.guild_only()
async def trivia(self, ctx: commands.Context, *categories: str):
"""Start trivia session on the specified category.
@@ -287,9 +287,6 @@ class Trivia(commands.Cog):
You may list multiple categories, in which case the trivia will involve
questions from all of them.
"""
if not categories:
await ctx.send_help()
return
categories = [c.lower() for c in categories]
session = self._get_trivia_session(ctx.channel)
if session is not None: