From ab730013407de966f765bea31a0f13123b6b39ab Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sat, 13 Mar 2021 17:48:18 -0500 Subject: [PATCH 1/5] Made help command use the invocation prefix Fixes #338 --- CHANGELOG.md | 1 + exts/base.py | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71a4f04..df66b78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Renamed `?cond` to `?solar`. ### Fixed - Weird image caching situation for `?greyline` on Discord's side. +- The help command was not using the prefix it was invoked with. ### Deprecated - `?ungrid`. - Deprecated old `?solar` aliases (`?cond`, etc). diff --git a/exts/base.py b/exts/base.py index 970373b..9f58854 100644 --- a/exts/base.py +++ b/exts/base.py @@ -18,13 +18,12 @@ import discord.ext.commands as commands import info import common as cmn -import data.options as opt - class QrmHelpCommand(commands.HelpCommand): def __init__(self): super().__init__(command_attrs={"help": "Shows help about qrm or a command", "aliases": ["h"]}) self.verify_checks = True + self.context: commands.Context async def get_bot_mapping(self): bot = self.context.bot @@ -46,9 +45,9 @@ class QrmHelpCommand(commands.HelpCommand): if parent: fmt = f"{parent} {fmt}" alias = fmt - return f"{opt.display_prefix}{alias} {command.signature}\n *Aliases:* {aliases}" + return f"{self.context.prefix}{alias} {command.signature}\n *Aliases:* {aliases}" alias = command.name if not parent else f"{parent} {command.name}" - return f"{opt.display_prefix}{alias} {command.signature}" + return f"{self.context.prefix}{alias} {command.signature}" async def send_error_message(self, error): embed = cmn.embed_factory(self.context) @@ -60,7 +59,7 @@ class QrmHelpCommand(commands.HelpCommand): async def send_bot_help(self, mapping): embed = cmn.embed_factory(self.context) embed.title = "qrm Help" - embed.description = (f"For command-specific help and usage, use `{opt.display_prefix}help [command name]`." + embed.description = (f"For command-specific help and usage, use `{self.context.prefix}help [command name]`." " Many commands have shorter aliases.") mapping = await mapping From 78e34dff6329c658d0a9ca6716a78b6135e568b1 Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sat, 13 Mar 2021 18:16:58 -0500 Subject: [PATCH 2/5] Added list of available prexifes to ?help - Only shows when more then one is available. Fixes #353 --- CHANGELOG.md | 1 + exts/base.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df66b78..ac5da15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added - MUF and foF2 maps from [prop.kc2g.com](https://prop.kc2g.com/). +- The list of available prefixes to `?help` when there is more than one. ### Changed - New colour theme for `?greyline`. - Moved great circle distance and bearing calculation from `?ungrid` to `?griddistance`. diff --git a/exts/base.py b/exts/base.py index 9f58854..3ac48a6 100644 --- a/exts/base.py +++ b/exts/base.py @@ -61,6 +61,9 @@ class QrmHelpCommand(commands.HelpCommand): embed.title = "qrm Help" embed.description = (f"For command-specific help and usage, use `{self.context.prefix}help [command name]`." " Many commands have shorter aliases.") + if isinstance(self.context.bot.command_prefix, list): + embed.description += (" All of the following prefixes work with the bot: `" + + "`, `".join(self.context.bot.command_prefix) + "`.") mapping = await mapping for cat, cmds in mapping.items(): From fa826104694c71ac5d75b39af5b402944b9133ad Mon Sep 17 00:00:00 2001 From: Abigail G Date: Tue, 16 Mar 2021 20:04:05 -0400 Subject: [PATCH 3/5] add donate command fixes #355 --- CHANGELOG.md | 1 + exts/base.py | 16 ++++++++++++++++ templates/data/options.py | 1 + 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a5cf83..5ed496b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - The ability to select an element of a pool in `?hamstudy`. - The ability to answer ❓ to a HamStudy question to get the answer. - The list of available prefixes to `?help` when there is more than one. +- `?donate` command to show ways to support qrm's development. ### Changed - New colour theme for `?greyline`. - Moved great circle distance and bearing calculation from `?ungrid` to `?griddistance`. diff --git a/exts/base.py b/exts/base.py index ebf6627..e787095 100644 --- a/exts/base.py +++ b/exts/base.py @@ -18,6 +18,7 @@ import discord.ext.commands as commands import info import common as cmn +from data import options as opt class QrmHelpCommand(commands.HelpCommand): @@ -120,6 +121,10 @@ class BaseCog(commands.Cog): self.commit = bf.readline().strip()[:7] else: self.commit = "" + self.donation_links = { + "Ko-Fi": "https://ko-fi.com/miaowware", + "LiberaPay": "https://liberapay.com/miaowware", + } @commands.command(name="info", aliases=["about"]) async def _info(self, ctx: commands.Context): @@ -196,6 +201,17 @@ class BaseCog(commands.Cog): [miaowware/qrm-resources](https://github.com/miaowware/qrm-resources/issues).""" await ctx.send(embed=embed) + @commands.command(name="donate") + async def _donate(self, ctx: commands.Context): + """Shows ways to help support development of the bot via donations.""" + embed = cmn.embed_factory(ctx) + embed.title = "Help Support qrm's Development!" + embed.description = ("Donations are always appreciated, and help with server and infrastructure costs." + "\nThank you for your support!") + for title, url in self.donation_links.items(): + embed.add_field(name=title, value=url, inline=False) + await ctx.send(embed=embed) + @commands.command(name="echo", aliases=["e"], category=cmn.cat.admin) @commands.check(cmn.check_if_owner) async def _echo(self, ctx: commands.Context, diff --git a/templates/data/options.py b/templates/data/options.py index e4d66f7..c9ca65e 100644 --- a/templates/data/options.py +++ b/templates/data/options.py @@ -46,6 +46,7 @@ exts = [ "propagation", ] + # Either "time", "random", or "fixed" (first item in statuses) status_mode = "fixed" From df8d258446c11836f42457ede9ad4be47676f93d Mon Sep 17 00:00:00 2001 From: Abigail G Date: Tue, 16 Mar 2021 20:33:45 -0400 Subject: [PATCH 4/5] add ?invite command fixes #356 --- CHANGELOG.md | 1 + exts/base.py | 10 ++++++++++ templates/data/options.py | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed496b..7598096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - The ability to answer ❓ to a HamStudy question to get the answer. - The list of available prefixes to `?help` when there is more than one. - `?donate` command to show ways to support qrm's development. +- `?invite` command to invite qrm to your server. ### Changed - New colour theme for `?greyline`. - Moved great circle distance and bearing calculation from `?ungrid` to `?griddistance`. diff --git a/exts/base.py b/exts/base.py index e787095..5e2c6d5 100644 --- a/exts/base.py +++ b/exts/base.py @@ -125,6 +125,8 @@ class BaseCog(commands.Cog): "Ko-Fi": "https://ko-fi.com/miaowware", "LiberaPay": "https://liberapay.com/miaowware", } + self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}" + f"&scope=bot&permissions={opt.invite_perms}") @commands.command(name="info", aliases=["about"]) async def _info(self, ctx: commands.Context): @@ -212,6 +214,14 @@ class BaseCog(commands.Cog): embed.add_field(name=title, value=url, inline=False) await ctx.send(embed=embed) + @commands.command(name="invite", enabled=opt.enable_invite_cmd) + async def _invite(self, ctx: commands.Context): + """Generates a link to invite the bot to a server.""" + embed = cmn.embed_factory(ctx) + embed.title = "Invite qrm to Your Server!" + embed.description = self.bot_invite + await ctx.send(embed=embed) + @commands.command(name="echo", aliases=["e"], category=cmn.cat.admin) @commands.check(cmn.check_if_owner) async def _echo(self, ctx: commands.Context, diff --git a/templates/data/options.py b/templates/data/options.py index c9ca65e..1a19563 100644 --- a/templates/data/options.py +++ b/templates/data/options.py @@ -46,6 +46,12 @@ exts = [ "propagation", ] +# enable a command that provides a link to add the bot to a server +enable_invite_cmd = True + +# the default permissions for the bot, to be included in the invite link for ?invite +# this probably does not need to be changed +invite_perms = 67488832 # Either "time", "random", or "fixed" (first item in statuses) status_mode = "fixed" From c6581841ab23bafa39fa3fff1fcadfb838602eb6 Mon Sep 17 00:00:00 2001 From: Abigail G Date: Tue, 16 Mar 2021 20:56:52 -0400 Subject: [PATCH 5/5] add donation and invite links to ?info fixes #357 --- exts/base.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exts/base.py b/exts/base.py index 5e2c6d5..9d14cf2 100644 --- a/exts/base.py +++ b/exts/base.py @@ -125,8 +125,16 @@ class BaseCog(commands.Cog): "Ko-Fi": "https://ko-fi.com/miaowware", "LiberaPay": "https://liberapay.com/miaowware", } - self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}" - f"&scope=bot&permissions={opt.invite_perms}") + self.bot_invite = None + if self.bot.user: + self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}" + f"&scope=bot&permissions={opt.invite_perms}") + + @commands.Cog.listener() + async def on_ready(self): + if not self.bot_invite: + self.bot_invite = (f"https://discordapp.com/oauth2/authorize?client_id={self.bot.user.id}" + f"&scope=bot&permissions={opt.invite_perms}") @commands.command(name="info", aliases=["about"]) async def _info(self, ctx: commands.Context): @@ -139,6 +147,10 @@ class BaseCog(commands.Cog): embed.add_field(name="Version", value=f"v{info.release} {'(`' + self.commit + '`)' if self.commit else ''}") embed.add_field(name="Contributing", value=info.contributing, inline=False) embed.add_field(name="Official Server", value=info.bot_server, inline=False) + embed.add_field(name="Donate", value="\n".join(f"{k}: {v}" for k, v in self.donation_links.items()), + inline=False) + if opt.enable_invite_cmd: + embed.add_field(name="Invite qrm to Your Server", value=self.bot_invite, inline=False) embed.set_thumbnail(url=str(self.bot.user.avatar_url)) await ctx.send(embed=embed)