mirror of https://github.com/stijndcl/didier
Improve help messages
parent
c5317b5d27
commit
9c36f59e04
|
@ -43,23 +43,22 @@ class Discord(commands.Cog):
|
||||||
self.client.tree.remove_command(self._bookmark_ctx_menu.name, type=self._bookmark_ctx_menu.type)
|
self.client.tree.remove_command(self._bookmark_ctx_menu.name, type=self._bookmark_ctx_menu.type)
|
||||||
self.client.tree.remove_command(self._pin_ctx_menu.name, type=self._pin_ctx_menu.type)
|
self.client.tree.remove_command(self._pin_ctx_menu.name, type=self._pin_ctx_menu.type)
|
||||||
|
|
||||||
@commands.group(name="Birthday", aliases=["Bd", "Birthdays"], case_insensitive=True, invoke_without_command=True)
|
@commands.group(name="birthday", aliases=["bd", "birthdays"], case_insensitive=True, invoke_without_command=True)
|
||||||
async def birthday(self, ctx: commands.Context, user: discord.User = None):
|
async def birthday(self, ctx: commands.Context, user: discord.User = None):
|
||||||
"""Command to check the birthday of a user"""
|
"""Command to check the birthday of a user"""
|
||||||
user_id = (user and user.id) or ctx.author.id
|
user_id = (user and user.id) or ctx.author.id
|
||||||
async with self.client.postgres_session as session:
|
async with self.client.postgres_session as session:
|
||||||
birthday = await birthdays.get_birthday_for_user(session, user_id)
|
birthday = await birthdays.get_birthday_for_user(session, user_id)
|
||||||
|
|
||||||
name = "Your" if user is None else f"{user.display_name}'s"
|
name: Optional[str] = user and f"{user.display_name}'s"
|
||||||
|
|
||||||
if birthday is None:
|
if birthday is None:
|
||||||
return await ctx.reply(f"I don't know {name} birthday.", mention_author=False)
|
return await ctx.reply(f"I don't know {name or 'your'} birthday.", mention_author=False)
|
||||||
|
|
||||||
day, month = leading("0", str(birthday.birthday.day)), leading("0", str(birthday.birthday.month))
|
day, month = leading("0", str(birthday.birthday.day)), leading("0", str(birthday.birthday.month))
|
||||||
|
return await ctx.reply(f"{name or 'Your'} birthday is set to **{day}/{month}**.", mention_author=False)
|
||||||
|
|
||||||
return await ctx.reply(f"{name} birthday is set to **{day}/{month}**.", mention_author=False)
|
@birthday.command(name="set", aliases=["config"])
|
||||||
|
|
||||||
@birthday.command(name="Set", aliases=["Config"])
|
|
||||||
async def birthday_set(self, ctx: commands.Context, date_str: str):
|
async def birthday_set(self, ctx: commands.Context, date_str: str):
|
||||||
"""Command to set your birthday"""
|
"""Command to set your birthday"""
|
||||||
try:
|
try:
|
||||||
|
@ -77,7 +76,7 @@ class Discord(commands.Cog):
|
||||||
await birthdays.add_birthday(session, ctx.author.id, date)
|
await birthdays.add_birthday(session, ctx.author.id, date)
|
||||||
await self.client.confirm_message(ctx.message)
|
await self.client.confirm_message(ctx.message)
|
||||||
|
|
||||||
@commands.group(name="Bookmark", aliases=["Bm", "Bookmarks"], case_insensitive=True, invoke_without_command=True)
|
@commands.group(name="bookmark", aliases=["bm", "bookmarks"], case_insensitive=True, invoke_without_command=True)
|
||||||
async def bookmark(self, ctx: commands.Context, *, label: Optional[str] = None):
|
async def bookmark(self, ctx: commands.Context, *, label: Optional[str] = None):
|
||||||
"""Post a bookmarked message"""
|
"""Post a bookmarked message"""
|
||||||
# No label: shortcut to display bookmarks
|
# No label: shortcut to display bookmarks
|
||||||
|
@ -92,7 +91,7 @@ class Discord(commands.Cog):
|
||||||
)
|
)
|
||||||
await ctx.reply(result.jump_url, mention_author=False)
|
await ctx.reply(result.jump_url, mention_author=False)
|
||||||
|
|
||||||
@bookmark.command(name="Create", aliases=["New"])
|
@bookmark.command(name="create", aliases=["new"])
|
||||||
async def bookmark_create(self, ctx: commands.Context, label: str, message: Optional[discord.Message]):
|
async def bookmark_create(self, ctx: commands.Context, label: str, message: Optional[discord.Message]):
|
||||||
"""Create a new bookmark"""
|
"""Create a new bookmark"""
|
||||||
# If no message was passed, allow replying to the message that should be bookmarked
|
# If no message was passed, allow replying to the message that should be bookmarked
|
||||||
|
@ -116,7 +115,7 @@ class Discord(commands.Cog):
|
||||||
# Label isn't allowed
|
# Label isn't allowed
|
||||||
return await ctx.reply(f"Bookmarks cannot be named `{label}`.", mention_author=False)
|
return await ctx.reply(f"Bookmarks cannot be named `{label}`.", mention_author=False)
|
||||||
|
|
||||||
@bookmark.command(name="Delete", aliases=["Rm"])
|
@bookmark.command(name="delete", aliases=["rm"])
|
||||||
async def bookmark_delete(self, ctx: commands.Context, bookmark_id: str):
|
async def bookmark_delete(self, ctx: commands.Context, bookmark_id: str):
|
||||||
"""Delete a bookmark by its id"""
|
"""Delete a bookmark by its id"""
|
||||||
# The bookmarks are displayed with a hashtag in front of the id
|
# The bookmarks are displayed with a hashtag in front of the id
|
||||||
|
@ -138,7 +137,7 @@ class Discord(commands.Cog):
|
||||||
|
|
||||||
return await ctx.reply(f"Successfully deleted bookmark `#{bookmark_id_int}`.", mention_author=False)
|
return await ctx.reply(f"Successfully deleted bookmark `#{bookmark_id_int}`.", mention_author=False)
|
||||||
|
|
||||||
@bookmark.command(name="Search", aliases=["List", "Ls"])
|
@bookmark.command(name="search", aliases=["list", "ls"])
|
||||||
async def bookmark_search(self, ctx: commands.Context, *, query: Optional[str] = None):
|
async def bookmark_search(self, ctx: commands.Context, *, query: Optional[str] = None):
|
||||||
"""Search through the list of bookmarks"""
|
"""Search through the list of bookmarks"""
|
||||||
async with self.client.postgres_session as session:
|
async with self.client.postgres_session as session:
|
||||||
|
@ -160,13 +159,13 @@ class Discord(commands.Cog):
|
||||||
modal = CreateBookmark(self.client, message.jump_url)
|
modal = CreateBookmark(self.client, message.jump_url)
|
||||||
await interaction.response.send_modal(modal)
|
await interaction.response.send_modal(modal)
|
||||||
|
|
||||||
@commands.command(name="Join", usage="[Thread]")
|
@commands.command(name="join", usage="[Thread]")
|
||||||
async def join(self, ctx: commands.Context, thread: discord.Thread):
|
async def join(self, ctx: commands.Context, thread: discord.Thread):
|
||||||
"""Make Didier join a thread"""
|
"""Make Didier join a thread"""
|
||||||
if thread.me is not None:
|
if thread.me is not None:
|
||||||
return await ctx.reply()
|
return await ctx.reply()
|
||||||
|
|
||||||
@commands.command(name="Pin", usage="[Message]")
|
@commands.command(name="pin", usage="[Message]")
|
||||||
async def pin(self, ctx: commands.Context, message: Optional[discord.Message] = None):
|
async def pin(self, ctx: commands.Context, message: Optional[discord.Message] = None):
|
||||||
"""Pin a message in the current channel"""
|
"""Pin a message in the current channel"""
|
||||||
# If no message was passed, allow replying to the message that should be pinned
|
# If no message was passed, allow replying to the message that should be pinned
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Fun(commands.Cog):
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="dadjoke",
|
name="dadjoke",
|
||||||
aliases=["Dad", "Dj"],
|
aliases=["dad", "dj"],
|
||||||
description="Why does Yoda's code always crash? Because there is no try.",
|
description="Why does Yoda's code always crash? Because there is no try.",
|
||||||
)
|
)
|
||||||
async def dad_joke(self, ctx: commands.Context):
|
async def dad_joke(self, ctx: commands.Context):
|
||||||
|
@ -40,14 +40,14 @@ class Fun(commands.Cog):
|
||||||
joke = await get_random_dad_joke(session)
|
joke = await get_random_dad_joke(session)
|
||||||
return await ctx.reply(joke.joke, mention_author=False)
|
return await ctx.reply(joke.joke, mention_author=False)
|
||||||
|
|
||||||
@commands.group(name="Memegen", aliases=["Meme", "Memes"], invoke_without_command=True, case_insensitive=True)
|
@commands.group(name="memegen", aliases=["meme", "memes"], invoke_without_command=True, case_insensitive=True)
|
||||||
async def memegen_msg(self, ctx: commands.Context, meme_name: str, *, fields: str):
|
async def memegen_msg(self, ctx: commands.Context, meme_name: str, *, fields: str):
|
||||||
"""Command group for meme-related commands"""
|
"""Command group for meme-related commands"""
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
meme = await self._do_generate_meme(meme_name, shlex.split(fields))
|
meme = await self._do_generate_meme(meme_name, shlex.split(fields))
|
||||||
return await ctx.reply(meme, mention_author=False)
|
return await ctx.reply(meme, mention_author=False)
|
||||||
|
|
||||||
@memegen_msg.command(name="Preview", aliases=["P"])
|
@memegen_msg.command(name="preview", aliases=["p"])
|
||||||
async def memegen_preview_msg(self, ctx: commands.Context, meme_name: str):
|
async def memegen_preview_msg(self, ctx: commands.Context, meme_name: str):
|
||||||
"""Generate a preview for a meme, to see how the fields are structured"""
|
"""Generate a preview for a meme, to see how the fields are structured"""
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
|
|
|
@ -9,9 +9,10 @@ from didier.utils.discord.colours import error_red
|
||||||
|
|
||||||
|
|
||||||
class CustomHelpCommand(commands.MinimalHelpCommand):
|
class CustomHelpCommand(commands.MinimalHelpCommand):
|
||||||
"""Customised Help command to override the default implementation
|
"""Customised Help command that overrides the default implementation
|
||||||
|
|
||||||
The default is ugly as hell, so we do some fiddling with it
|
The default is ugly as hell, so we do some fiddling with it and put everything
|
||||||
|
in fancy embeds
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@overrides
|
@overrides
|
||||||
|
@ -154,6 +155,14 @@ class CustomHelpCommand(commands.MinimalHelpCommand):
|
||||||
|
|
||||||
async def setup(client: Didier):
|
async def setup(client: Didier):
|
||||||
"""Load the cog"""
|
"""Load the cog"""
|
||||||
attributes = {"aliases": ["h", "man"]}
|
help_str = (
|
||||||
|
"Shows the help page for a category or command. "
|
||||||
|
"`/commands` are not included, as they already have built-in descriptions in the UI."
|
||||||
|
"\n\nThe command signatures follow the POSIX-standard format for help messages:"
|
||||||
|
"\n- `required_positional_argument`"
|
||||||
|
"\n- `[optional_positional_argument]`"
|
||||||
|
)
|
||||||
|
|
||||||
|
attributes = {"aliases": ["h", "man"], "usage": "[category or command]", "help": help_str}
|
||||||
|
|
||||||
client.help_command = CustomHelpCommand(command_attrs=attributes)
|
client.help_command = CustomHelpCommand(command_attrs=attributes)
|
||||||
|
|
|
@ -8,21 +8,24 @@ from didier import Didier
|
||||||
|
|
||||||
|
|
||||||
class Meta(commands.Cog):
|
class Meta(commands.Cog):
|
||||||
"""Cog for Didier-related commands"""
|
"""Commands related to Didier himself."""
|
||||||
|
|
||||||
client: Didier
|
client: Didier
|
||||||
|
|
||||||
def __init__(self, client: Didier):
|
def __init__(self, client: Didier):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
@commands.command(name="Marco")
|
@commands.command(name="marco")
|
||||||
async def marco(self, ctx: commands.Context):
|
async def marco(self, ctx: commands.Context):
|
||||||
"""Ping command to get the delay of the bot"""
|
"""Ping command to get Didier's latency."""
|
||||||
return await ctx.reply(f"Polo! {round(self.client.latency * 1000)}ms", mention_author=False)
|
return await ctx.reply(f"Polo! {round(self.client.latency * 1000)}ms", mention_author=False)
|
||||||
|
|
||||||
@commands.command(name="Source", aliases=["Src"])
|
@commands.command(name="source", aliases=["src"])
|
||||||
async def source(self, ctx: commands.Context, *, command_name: Optional[str] = None):
|
async def source(self, ctx: commands.Context, *, command_name: Optional[str] = None):
|
||||||
"""Command to get links to the source code of Didier"""
|
"""Get a link to the source code of Didier.
|
||||||
|
|
||||||
|
If a value for `command_name` is passed, the source for `command_name` is shown instead.
|
||||||
|
"""
|
||||||
repo_home = "https://github.com/stijndcl/didier"
|
repo_home = "https://github.com/stijndcl/didier"
|
||||||
|
|
||||||
if command_name is None:
|
if command_name is None:
|
||||||
|
@ -38,12 +41,12 @@ class Meta(commands.Cog):
|
||||||
filename = src.co_filename
|
filename = src.co_filename
|
||||||
|
|
||||||
if command is None:
|
if command is None:
|
||||||
return await ctx.reply(f"Geen commando gevonden voor ``{command_name}``.", mention_author=False)
|
return await ctx.reply(f"Found no command named `{command_name}`.", mention_author=False)
|
||||||
|
|
||||||
lines, first_line = inspect.getsourcelines(src)
|
lines, first_line = inspect.getsourcelines(src)
|
||||||
|
|
||||||
if filename is None:
|
if filename is None:
|
||||||
return await ctx.reply(f"Geen code gevonden voor ``{command_name}``.", mention_author=False)
|
return await ctx.reply(f"Found no source file for `{command_name}`.", mention_author=False)
|
||||||
|
|
||||||
file_location = os.path.relpath(filename).replace("\\", "/")
|
file_location = os.path.relpath(filename).replace("\\", "/")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue