aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2021-08-30 23:47:52 +0200
committerGravatar Numerlor <[email protected]>2021-08-30 23:47:52 +0200
commit1b04bdfec2ebf1399c93bf43b9bce735b47a8279 (patch)
treec3cdb9727b41ce74a55cd3984a508f8d195f6744
parentMerge pull request #1791 from python-discord/dmrelay-mod-channel (diff)
Make the base_url argument in doc set optional
-rw-r--r--bot/exts/info/doc/_cog.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py
index fb9b2584a..a2119a53d 100644
--- a/bot/exts/info/doc/_cog.py
+++ b/bot/exts/info/doc/_cog.py
@@ -150,6 +150,8 @@ class DocCog(commands.Cog):
self.update_or_reschedule_inventory(api_package_name, base_url, inventory_url),
)
else:
+ if not base_url:
+ base_url = self.base_url_from_inventory_url(inventory_url)
self.update_single(api_package_name, base_url, package)
def ensure_unique_symbol_name(self, package_name: str, group_name: str, symbol_name: str) -> str:
@@ -352,6 +354,11 @@ class DocCog(commands.Cog):
msg = await ctx.send(embed=doc_embed)
await wait_for_deletion(msg, (ctx.author.id,))
+ @staticmethod
+ def base_url_from_inventory_url(inventory_url: str) -> str:
+ """Get a base url from the url to an objects inventory by removing the last path segment."""
+ return inventory_url.removesuffix("/").rsplit("/", maxsplit=1)[0] + "/"
+
@docs_group.command(name="setdoc", aliases=("s",))
@commands.has_any_role(*MODERATION_ROLES)
@lock(NAMESPACE, COMMAND_LOCK_SINGLETON, raise_error=True)
@@ -359,21 +366,21 @@ class DocCog(commands.Cog):
self,
ctx: commands.Context,
package_name: PackageName,
- base_url: ValidURL,
inventory: Inventory,
+ base_url: ValidURL = "",
) -> None:
"""
Adds a new documentation metadata object to the site's database.
The database will update the object, should an existing item with the specified `package_name` already exist.
+ If the base url is not specified, a default created by removing the last segment of the inventory url is used.
Example:
!docs setdoc \
python \
- https://docs.python.org/3/ \
https://docs.python.org/3/objects.inv
"""
- if not base_url.endswith("/"):
+ if base_url and not base_url.endswith("/"):
raise commands.BadArgument("The base url must end with a slash.")
inventory_url, inventory_dict = inventory
body = {
@@ -388,6 +395,8 @@ class DocCog(commands.Cog):
+ "\n".join(f"{key}: {value}" for key, value in body.items())
)
+ if not base_url:
+ base_url = self.base_url_from_inventory_url(inventory_url)
self.update_single(package_name, base_url, inventory_dict)
await ctx.send(f"Added the package `{package_name}` to the database and updated the inventories.")