From 387355af7e0a129e3d53990a270a71001d6d414a Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sat, 7 Dec 2019 11:38:34 -0500 Subject: [PATCH 01/13] Extention control commands - Extctl: live load/reload/unload/list of extensions. - Added helper to create error embeds. - Added status emojis to common.py. Fixes #82 Fixes #88 --- CHANGELOG.md | 1 + common.py | 31 +++++++++++++++++++++++++ main.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f44c0cb..38a60a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Rich lookup for QRZ, if a QRZ subscription is present - Timestamp and requester username and avatar are now shown on embeds - Current and 3-Day Forecast terrestrial weather conditions lookup commands +- Extension control commands. - Changelog command ### Changed - Rewrote code to take advantage of discord.py's cogs diff --git a/common.py b/common.py index 9005238..11d5842 100644 --- a/common.py +++ b/common.py @@ -12,8 +12,19 @@ General Public License, version 2. `cat`: Category names for the HelpCommand. """ + +import traceback +from datetime import datetime from types import SimpleNamespace +import discord +import discord.ext.commands as commands + + +__all__ = ["colours", "cat", "emojis", "error_embed_factory"] + + +# --- Common values --- colours = SimpleNamespace(good=0x43B581, neutral=0x7289DA, @@ -25,3 +36,23 @@ cat = SimpleNamespace(lookup='Information Lookup', ref='Reference', study='Exam Study', weather='Land and Space Weather') + +emojis = SimpleNamespace(good='✅', + bad='❌') + + +# --- Helper functions --- + +def error_embed_factory(ctx: commands.Context, exception: Exception, debug_mode: bool) -> discord.Embed: + """Creates an Error embed.""" + if debug_mode: + fmtd_ex = traceback.format_exception(exception.__class__, exception, exception.__traceback__) + else: + fmtd_ex = traceback.format_exception_only(exception.__class__, exception) + embed = discord.Embed(title="Error", + timestamp=datetime.utcnow(), + colour=colours.bad) + embed.set_footer(text=ctx.author, + icon_url=str(ctx.author.avatar_url)) + embed.description = "```\n" + '\n'.join(fmtd_ex) + "```" + return embed diff --git a/main.py b/main.py index 9a9ef0b..449dc4a 100644 --- a/main.py +++ b/main.py @@ -8,9 +8,13 @@ This file is part of discord-qrmbot and is released under the terms of the GNU General Public License, version 2. """ + +from datetime import datetime + import discord from discord.ext import commands, tasks +import common as cmn import info from data import options as opt @@ -21,6 +25,8 @@ from data import keys exit_code = 1 # The default exit code. ?shutdown and ?restart will change it accordingly (fail-safe) +ext_dir = "cogs" # The name of the directory where extensions are located. + debug_mode = opt.debug # Separate assignement in-case we define an override (ternary operator goes here) @@ -37,7 +43,7 @@ async def add_react(msg: discord.Message, react: str): try: await msg.add_reaction(react) except discord.Forbidden: - print(f"!! Missing permissions to add reaction in '{msg.guild.id}/{msg.channel.id}'!") + print(f"[!!] Missing permissions to add reaction in '{msg.guild.id}/{msg.channel.id}'!") # --- Checks --- @@ -45,7 +51,7 @@ async def add_react(msg: discord.Message, react: str): async def check_if_owner(ctx: commands.Context): if ctx.author.id in opt.owners_uids: return True - await add_react(ctx.message, "❌") + await add_react(ctx.message, cmn.emojis.bad) return False @@ -56,7 +62,7 @@ async def check_if_owner(ctx: commands.Context): async def _restart_bot(ctx: commands.Context): """Restarts the bot.""" global exit_code - await add_react(ctx.message, "✅") + await add_react(ctx.message, cmn.emojis.good) exit_code = 42 # Signals to the wrapper script that the bot needs to be restarted. await bot.logout() @@ -66,11 +72,61 @@ async def _restart_bot(ctx: commands.Context): async def _shutdown_bot(ctx: commands.Context): """Shuts down the bot.""" global exit_code - await add_react(ctx.message, "✅") + await add_react(ctx.message, cmn.emojis.good) exit_code = 0 # Signals to the wrapper script that the bot should not be restarted. await bot.logout() +@bot.group(name="extctl", hidden=True) +@commands.check(check_if_owner) +async def _extctl(ctx: commands.Context): + """Extension control commands. + Defaults to `list` if no subcommand specified""" + if ctx.invoked_subcommand is None: + cmd = bot.get_command("extctl list") + await ctx.invoke(cmd) + + +@_extctl.command(name="list") +async def _extctl_list(ctx: commands.Context): + """Lists Extensions.""" + embed = discord.Embed(title="Loaded Extensions", + colour=cmn.colours.neutral, + timestamp=datetime.utcnow()) + embed.description = "\n".join(["‣ " + x.split(".")[1] for x in bot.extensions.keys()]) + await ctx.send(embed=embed) + + +@_extctl.command(name="load") +async def _extctl_load(ctx: commands.Context, extension: str): + try: + bot.load_extension(ext_dir + "." + extension) + await add_react(ctx.message, cmn.emojis.good) + except commands.ExtensionError as ex: + embed = cmn.error_embed_factory(ctx, ex, debug_mode) + await ctx.send(embed=embed) + + +@_extctl.command(name="reload") +async def _extctl_reload(ctx: commands.Context, extension: str): + try: + bot.reload_extension(ext_dir + "." + extension) + await add_react(ctx.message, cmn.emojis.good) + except commands.ExtensionError as ex: + embed = cmn.error_embed_factory(ctx, ex, debug_mode) + await ctx.send(embed=embed) + + +@_extctl.command(name="unload") +async def _extctl_unload(ctx: commands.Context, extension: str): + try: + bot.unload_extension(ext_dir + "." + extension) + await add_react(ctx.message, cmn.emojis.good) + except commands.ExtensionError as ex: + embed = cmn.error_embed_factory(ctx, ex, debug_mode) + await ctx.send(embed=embed) + + # --- Events --- @bot.event From aee64ce2357d3d54a6b4847c18e375d54011b9f9 Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sat, 7 Dec 2019 13:26:49 -0500 Subject: [PATCH 02/13] Fixed wttr embeds for unicode locations Fixes #90 --- cogs/weathercog.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cogs/weathercog.py b/cogs/weathercog.py index 5c1faab..4be5317 100644 --- a/cogs/weathercog.py +++ b/cogs/weathercog.py @@ -90,13 +90,10 @@ See help for weather command for possible location types. Add a `-c` or `-f` to embed.colour = cmn.colours.bad else: data = io.BytesIO(await resp.read()) - loc = loc.replace('+', '') - loc = loc.replace('@', '') - loc = loc.replace('~', '') - embed.set_image(url=f'attachment://{loc}_{units}pnFQ.png') + embed.set_image(url=f'attachment://wttr_forecast.png') embed.set_footer(text=ctx.author.name, icon_url=str(ctx.author.avatar_url)) - await ctx.send(embed=embed, file=discord.File(data, f'{loc}_{units}pnFQ.png')) + await ctx.send(embed=embed, file=discord.File(data, f'wttr_forecast.png')) @_weather_conditions.command(name='now', aliases=['n'], category=cmn.cat.weather) async def _weather_conditions_now(self, ctx: commands.Context, *, location: str): @@ -128,13 +125,10 @@ See help for weather command for possible location types. Add a `-c` or `-f` to embed.colour = cmn.colours.bad else: data = io.BytesIO(await resp.read()) - loc = loc.replace('+', '') - loc = loc.replace('@', '') - loc = loc.replace('~', '') - embed.set_image(url=f'attachment://{loc}_0{units}pnFQ.png') + embed.set_image(url=f'attachment://wttr_now.png') embed.set_footer(text=ctx.author.name, icon_url=str(ctx.author.avatar_url)) - await ctx.send(embed=embed, file=discord.File(data, f'{loc}_0{units}pnFQ.png')) + await ctx.send(embed=embed, file=discord.File(data, 'wttr_now.png')) def setup(bot: commands.Bot): From 521c99a6147ec708716d0978ce37c5e9d654aa8f Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sat, 7 Dec 2019 17:13:06 -0500 Subject: [PATCH 03/13] fix imports. Fixes #85 --- cogs/basecog.py | 2 +- cogs/hamcog.py | 4 ++-- cogs/qrzcog.py | 2 +- main.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cogs/basecog.py b/cogs/basecog.py index 290a8cd..65c2d16 100644 --- a/cogs/basecog.py +++ b/cogs/basecog.py @@ -17,7 +17,7 @@ import discord.ext.commands as commands import info -from data import options as opt +import data.options as opt import common as cmn diff --git a/cogs/hamcog.py b/cogs/hamcog.py index 58ede8e..90113e1 100644 --- a/cogs/hamcog.py +++ b/cogs/hamcog.py @@ -84,7 +84,7 @@ class HamCog(commands.Cog): if country.lower() not in callsign_info.options: embed = discord.Embed(title=f'{country} not found!', description=f'Valid countries: {", ".join(callsign_info.options.keys())}', - colour=self.gs.colours.bad, + colour=cmn.colours.bad, timestamp=datetime.utcnow()) embed.set_footer(text=ctx.author.name, icon_url=str(ctx.author.avatar_url)) @@ -92,7 +92,7 @@ class HamCog(commands.Cog): return embed = discord.Embed(title=callsign_info.options[country.lower()][0], description=callsign_info.options[country.lower()][1], - colour=self.gs.colours.good, + colour=cmn.colours.good, timestamp=datetime.utcnow()) embed.set_footer(text=ctx.author.name, icon_url=str(ctx.author.avatar_url)) diff --git a/cogs/qrzcog.py b/cogs/qrzcog.py index 1a18a94..caaf530 100644 --- a/cogs/qrzcog.py +++ b/cogs/qrzcog.py @@ -17,7 +17,7 @@ import aiohttp from lxml import etree import common as cmn -import keys +import data.keys as keys class QRZCog(commands.Cog): diff --git a/main.py b/main.py index 449dc4a..65c2a16 100644 --- a/main.py +++ b/main.py @@ -17,8 +17,8 @@ from discord.ext import commands, tasks import common as cmn import info -from data import options as opt -from data import keys +import data.options as opt +import data.keys as keys # --- Settings --- From 7f169ad3eb564a6508ac0460b36d217fb4f269e3 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sat, 7 Dec 2019 17:26:55 -0500 Subject: [PATCH 04/13] rename "cogs" to extensions (more accurate!) --- cogs/ae7qcog.py => exts/ae7qext.py | 2 +- cogs/basecog.py => exts/baseext.py | 2 +- cogs/funcog.py => exts/funext.py | 2 +- cogs/gridcog.py => exts/gridext.py | 2 +- cogs/hamcog.py => exts/hamext.py | 2 +- cogs/imagecog.py => exts/imageext.py | 2 +- cogs/morsecog.py => exts/morseext.py | 2 +- cogs/qrzcog.py => exts/qrzext.py | 2 +- cogs/studycog.py => exts/studyext.py | 2 +- cogs/weathercog.py => exts/weatherext.py | 2 +- main.py | 7 +++---- templates/data/options.py | 6 +++--- 12 files changed, 16 insertions(+), 17 deletions(-) rename cogs/ae7qcog.py => exts/ae7qext.py (99%) rename cogs/basecog.py => exts/baseext.py (99%) rename cogs/funcog.py => exts/funext.py (97%) rename cogs/gridcog.py => exts/gridext.py (99%) rename cogs/hamcog.py => exts/hamext.py (99%) rename cogs/imagecog.py => exts/imageext.py (99%) rename cogs/morsecog.py => exts/morseext.py (99%) rename cogs/qrzcog.py => exts/qrzext.py (99%) rename cogs/studycog.py => exts/studyext.py (99%) rename cogs/weathercog.py => exts/weatherext.py (99%) diff --git a/cogs/ae7qcog.py b/exts/ae7qext.py similarity index 99% rename from cogs/ae7qcog.py rename to exts/ae7qext.py index 8e94690..015808c 100644 --- a/cogs/ae7qcog.py +++ b/exts/ae7qext.py @@ -1,5 +1,5 @@ """ -ae7q cog for qrm +ae7q extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/basecog.py b/exts/baseext.py similarity index 99% rename from cogs/basecog.py rename to exts/baseext.py index 290a8cd..875058b 100644 --- a/cogs/basecog.py +++ b/exts/baseext.py @@ -1,5 +1,5 @@ """ -Base cog for qrm +Base extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/funcog.py b/exts/funext.py similarity index 97% rename from cogs/funcog.py rename to exts/funext.py index 5662b0f..f7352ba 100644 --- a/cogs/funcog.py +++ b/exts/funext.py @@ -1,5 +1,5 @@ """ -Fun cog for qrm +Fun extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/gridcog.py b/exts/gridext.py similarity index 99% rename from cogs/gridcog.py rename to exts/gridext.py index 5e5f9dd..e8ca466 100644 --- a/cogs/gridcog.py +++ b/exts/gridext.py @@ -1,5 +1,5 @@ """ -Grid cog for qrm +Grid extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/hamcog.py b/exts/hamext.py similarity index 99% rename from cogs/hamcog.py rename to exts/hamext.py index 58ede8e..22b979d 100644 --- a/cogs/hamcog.py +++ b/exts/hamext.py @@ -1,5 +1,5 @@ """ -Ham cog for qrm +Ham extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/imagecog.py b/exts/imageext.py similarity index 99% rename from cogs/imagecog.py rename to exts/imageext.py index 51d4d7b..1056957 100644 --- a/cogs/imagecog.py +++ b/exts/imageext.py @@ -1,5 +1,5 @@ """ -Image cog for qrm +Image extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/morsecog.py b/exts/morseext.py similarity index 99% rename from cogs/morsecog.py rename to exts/morseext.py index 0ba8ab0..4b84ff4 100644 --- a/cogs/morsecog.py +++ b/exts/morseext.py @@ -1,5 +1,5 @@ """ -Morse Code cog for qrm +Morse Code extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/qrzcog.py b/exts/qrzext.py similarity index 99% rename from cogs/qrzcog.py rename to exts/qrzext.py index 1a18a94..7267edd 100644 --- a/cogs/qrzcog.py +++ b/exts/qrzext.py @@ -1,5 +1,5 @@ """ -QRZ cog for qrm +QRZ extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/studycog.py b/exts/studyext.py similarity index 99% rename from cogs/studycog.py rename to exts/studyext.py index b72348c..e19b12d 100644 --- a/cogs/studycog.py +++ b/exts/studyext.py @@ -1,5 +1,5 @@ """ -Study cog for qrm +Study extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/cogs/weathercog.py b/exts/weatherext.py similarity index 99% rename from cogs/weathercog.py rename to exts/weatherext.py index 4be5317..a72e806 100644 --- a/cogs/weathercog.py +++ b/exts/weatherext.py @@ -1,5 +1,5 @@ """ -Weather cog for qrm +Weather extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c diff --git a/main.py b/main.py index 449dc4a..62cbf68 100644 --- a/main.py +++ b/main.py @@ -25,7 +25,7 @@ from data import keys exit_code = 1 # The default exit code. ?shutdown and ?restart will change it accordingly (fail-safe) -ext_dir = "cogs" # The name of the directory where extensions are located. +ext_dir = "exts" # The name of the directory where extensions are located. debug_mode = opt.debug # Separate assignement in-case we define an override (ternary operator goes here) @@ -149,9 +149,8 @@ async def _before_ensure_activity(): # --- Run --- -# bot.add_cog(GlobalSettings(bot)) -for cog in opt.cogs: - bot.load_extension(f"cogs.{cog}") +for ext in opt.exts: + bot.load_extension(f"exts.{ext}") _ensure_activity.start() diff --git a/templates/data/options.py b/templates/data/options.py index 8c60b01..c3a7351 100644 --- a/templates/data/options.py +++ b/templates/data/options.py @@ -26,9 +26,9 @@ debug = False # ! This MUST be a tuple of integers. Single element tuple: `(123,)` owners_uids = (200102491231092736,) -# The cogs to load when running the bot. -cogs = ['basecog', 'morsecog', 'funcog', 'gridcog', 'hamcog', 'imagecog', - 'studycog', 'ae7qcog', 'qrzcog', 'weathercog'] +# The extensions to load when running the bot. +exts = ['ae7qext', 'baseext', 'funext', 'gridext', 'hamext', 'imageext', + 'morseext', 'qrzext', 'studyext', 'weatherext'] # The text to put in the "playing" status. game = 'with lids on 7.200' From fe39822dd51c6561a37c3753c6a9184b911eab78 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 8 Dec 2019 03:10:30 -0500 Subject: [PATCH 05/13] remove ext from filenames --- exts/{ae7qext.py => ae7q.py} | 0 exts/{baseext.py => base.py} | 0 exts/{funext.py => fun.py} | 0 exts/{gridext.py => grid.py} | 0 exts/{hamext.py => ham.py} | 0 exts/{imageext.py => image.py} | 0 exts/{morseext.py => morse.py} | 0 exts/{qrzext.py => qrz.py} | 0 exts/{studyext.py => study.py} | 0 exts/{weatherext.py => weather.py} | 0 templates/data/options.py | 3 +-- 11 files changed, 1 insertion(+), 2 deletions(-) rename exts/{ae7qext.py => ae7q.py} (100%) rename exts/{baseext.py => base.py} (100%) rename exts/{funext.py => fun.py} (100%) rename exts/{gridext.py => grid.py} (100%) rename exts/{hamext.py => ham.py} (100%) rename exts/{imageext.py => image.py} (100%) rename exts/{morseext.py => morse.py} (100%) rename exts/{qrzext.py => qrz.py} (100%) rename exts/{studyext.py => study.py} (100%) rename exts/{weatherext.py => weather.py} (100%) diff --git a/exts/ae7qext.py b/exts/ae7q.py similarity index 100% rename from exts/ae7qext.py rename to exts/ae7q.py diff --git a/exts/baseext.py b/exts/base.py similarity index 100% rename from exts/baseext.py rename to exts/base.py diff --git a/exts/funext.py b/exts/fun.py similarity index 100% rename from exts/funext.py rename to exts/fun.py diff --git a/exts/gridext.py b/exts/grid.py similarity index 100% rename from exts/gridext.py rename to exts/grid.py diff --git a/exts/hamext.py b/exts/ham.py similarity index 100% rename from exts/hamext.py rename to exts/ham.py diff --git a/exts/imageext.py b/exts/image.py similarity index 100% rename from exts/imageext.py rename to exts/image.py diff --git a/exts/morseext.py b/exts/morse.py similarity index 100% rename from exts/morseext.py rename to exts/morse.py diff --git a/exts/qrzext.py b/exts/qrz.py similarity index 100% rename from exts/qrzext.py rename to exts/qrz.py diff --git a/exts/studyext.py b/exts/study.py similarity index 100% rename from exts/studyext.py rename to exts/study.py diff --git a/exts/weatherext.py b/exts/weather.py similarity index 100% rename from exts/weatherext.py rename to exts/weather.py diff --git a/templates/data/options.py b/templates/data/options.py index c3a7351..81ecc8b 100644 --- a/templates/data/options.py +++ b/templates/data/options.py @@ -27,8 +27,7 @@ debug = False owners_uids = (200102491231092736,) # The extensions to load when running the bot. -exts = ['ae7qext', 'baseext', 'funext', 'gridext', 'hamext', 'imageext', - 'morseext', 'qrzext', 'studyext', 'weatherext'] +exts = ['ae7q', 'base', 'fun', 'grid', 'ham', 'image', 'morse', 'qrz', 'study', 'weather'] # The text to put in the "playing" status. game = 'with lids on 7.200' From cc7e95caff49be701732544692aa65e8756f18ed Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 8 Dec 2019 03:24:14 -0500 Subject: [PATCH 06/13] oopsie whoopsie --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 56717b0..2440950 100644 --- a/main.py +++ b/main.py @@ -150,7 +150,7 @@ async def _before_ensure_activity(): # --- Run --- for ext in opt.exts: - bot.load_extension(f"exts.{ext}") + bot.load_extension(extdir + '.' + ext) _ensure_activity.start() From 51a396e04997354505cae27536ac458d4e04c526 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 8 Dec 2019 03:26:04 -0500 Subject: [PATCH 07/13] a little fucky-wucky --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2440950..8edf832 100644 --- a/main.py +++ b/main.py @@ -150,7 +150,7 @@ async def _before_ensure_activity(): # --- Run --- for ext in opt.exts: - bot.load_extension(extdir + '.' + ext) + bot.load_extension(ext_dir + '.' + ext) _ensure_activity.start() From bb8cb1eff54ff52107afdcc14a775e11740a4e9c Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sun, 8 Dec 2019 04:10:19 -0500 Subject: [PATCH 08/13] Moved checks and helpers to common.py Fixes #87 --- common.py | 21 ++++++++++++++++++++- main.py | 34 ++++++++-------------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/common.py b/common.py index 11d5842..0ed3731 100644 --- a/common.py +++ b/common.py @@ -21,7 +21,10 @@ import discord import discord.ext.commands as commands -__all__ = ["colours", "cat", "emojis", "error_embed_factory"] +import data.options as opt + + +__all__ = ["colours", "cat", "emojis", "error_embed_factory", "add_react", "check_if_owner"] # --- Common values --- @@ -56,3 +59,19 @@ def error_embed_factory(ctx: commands.Context, exception: Exception, debug_mode: icon_url=str(ctx.author.avatar_url)) embed.description = "```\n" + '\n'.join(fmtd_ex) + "```" return embed + + +async def add_react(msg: discord.Message, react: str): + try: + await msg.add_reaction(react) + except discord.Forbidden: + print(f"[!!] Missing permissions to add reaction in '{msg.guild.id}/{msg.channel.id}'!") + + +# --- Checks --- + +async def check_if_owner(ctx: commands.Context): + if ctx.author.id in opt.owners_uids: + return True + await add_react(ctx.message, emojis.bad) + return False diff --git a/main.py b/main.py index 8edf832..43a8a8d 100644 --- a/main.py +++ b/main.py @@ -37,48 +37,30 @@ bot = commands.Bot(command_prefix=opt.prefix, help_command=commands.MinimalHelpCommand()) -# --- Helper functions --- - -async def add_react(msg: discord.Message, react: str): - try: - await msg.add_reaction(react) - except discord.Forbidden: - print(f"[!!] Missing permissions to add reaction in '{msg.guild.id}/{msg.channel.id}'!") - - -# --- Checks --- - -async def check_if_owner(ctx: commands.Context): - if ctx.author.id in opt.owners_uids: - return True - await add_react(ctx.message, cmn.emojis.bad) - return False - - # --- Commands --- @bot.command(name="restart", hidden=True) -@commands.check(check_if_owner) +@commands.check(cmn.check_if_owner) async def _restart_bot(ctx: commands.Context): """Restarts the bot.""" global exit_code - await add_react(ctx.message, cmn.emojis.good) + await cmn.add_react(ctx.message, cmn.emojis.good) exit_code = 42 # Signals to the wrapper script that the bot needs to be restarted. await bot.logout() @bot.command(name="shutdown", hidden=True) -@commands.check(check_if_owner) +@commands.check(cmn.check_if_owner) async def _shutdown_bot(ctx: commands.Context): """Shuts down the bot.""" global exit_code - await add_react(ctx.message, cmn.emojis.good) + await cmn.add_react(ctx.message, cmn.emojis.good) exit_code = 0 # Signals to the wrapper script that the bot should not be restarted. await bot.logout() @bot.group(name="extctl", hidden=True) -@commands.check(check_if_owner) +@commands.check(cmn.check_if_owner) async def _extctl(ctx: commands.Context): """Extension control commands. Defaults to `list` if no subcommand specified""" @@ -101,7 +83,7 @@ async def _extctl_list(ctx: commands.Context): async def _extctl_load(ctx: commands.Context, extension: str): try: bot.load_extension(ext_dir + "." + extension) - await add_react(ctx.message, cmn.emojis.good) + await cmn.add_react(ctx.message, cmn.emojis.good) except commands.ExtensionError as ex: embed = cmn.error_embed_factory(ctx, ex, debug_mode) await ctx.send(embed=embed) @@ -111,7 +93,7 @@ async def _extctl_load(ctx: commands.Context, extension: str): async def _extctl_reload(ctx: commands.Context, extension: str): try: bot.reload_extension(ext_dir + "." + extension) - await add_react(ctx.message, cmn.emojis.good) + await cmn.add_react(ctx.message, cmn.emojis.good) except commands.ExtensionError as ex: embed = cmn.error_embed_factory(ctx, ex, debug_mode) await ctx.send(embed=embed) @@ -121,7 +103,7 @@ async def _extctl_reload(ctx: commands.Context, extension: str): async def _extctl_unload(ctx: commands.Context, extension: str): try: bot.unload_extension(ext_dir + "." + extension) - await add_react(ctx.message, cmn.emojis.good) + await cmn.add_react(ctx.message, cmn.emojis.good) except commands.ExtensionError as ex: embed = cmn.error_embed_factory(ctx, ex, debug_mode) await ctx.send(embed=embed) From 5ab7a816042299b3918ea53afcddb589e936d2e5 Mon Sep 17 00:00:00 2001 From: Abigail Gold <5366828+classabbyamp@users.noreply.github.com> Date: Sun, 8 Dec 2019 04:27:50 -0500 Subject: [PATCH 09/13] Add issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 32 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..53c1e4c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,32 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**System (please complete the following information if applicable):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 12dc87ae9b7f09ee1c96abc0069a5e3404f6894c Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 8 Dec 2019 15:35:58 -0500 Subject: [PATCH 10/13] changed all references of qrmbot to qrm2. Fixes #96 --- README-DOCKER.md | 4 ++-- README.md | 2 +- common.py | 2 +- docker-compose.yml | 2 +- exts/ae7q.py | 2 +- exts/base.py | 4 ++-- exts/fun.py | 2 +- exts/grid.py | 2 +- exts/ham.py | 2 +- exts/image.py | 2 +- exts/morse.py | 2 +- exts/qrz.py | 4 ++-- exts/study.py | 2 +- exts/weather.py | 2 +- info.py | 4 ++-- main.py | 2 +- 16 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README-DOCKER.md b/README-DOCKER.md index 45b19d7..ce62610 100644 --- a/README-DOCKER.md +++ b/README-DOCKER.md @@ -4,8 +4,8 @@ A sample `docker-compose.yml` file: version: '3' services: bot: - image: "classabbyamp/discord-qrm-bot:latest" - container_name: "qrmbot" + image: "classabbyamp/discord-qrm2:latest" + container_name: "discord-qrm2" volumes: - "./data:/app/data:rw" ``` diff --git a/README.md b/README.md index b3bfa1d..3671116 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Discord QRM Bot +# qrm, a Bot for Discord A discord bot with ham radio functionalities. diff --git a/common.py b/common.py index 0ed3731..bb0e052 100644 --- a/common.py +++ b/common.py @@ -3,7 +3,7 @@ Common tools for the bot. --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. --- diff --git a/docker-compose.yml b/docker-compose.yml index 183d669..14ae78d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,6 @@ version: '3' services: bot: build: . - container_name: "qrmbot" + container_name: "discord-qrm2" volumes: - "./data:/app/data:rw" diff --git a/exts/ae7q.py b/exts/ae7q.py index 015808c..0cb9457 100644 --- a/exts/ae7q.py +++ b/exts/ae7q.py @@ -3,7 +3,7 @@ ae7q extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. --- Test callsigns: diff --git a/exts/base.py b/exts/base.py index 2bcf9eb..4adb6cb 100644 --- a/exts/base.py +++ b/exts/base.py @@ -3,7 +3,7 @@ Base extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ @@ -142,7 +142,7 @@ class BaseCog(commands.Cog): """Show what has changed in recent bot versions.""" embed = discord.Embed(title="qrm Changelog", description=("For a full listing, visit [Github](https://" - "github.com/classabbyamp/discord-qrm-bot/blob/master/CHANGELOG.md)."), + "github.com/classabbyamp/discord-qrm2/blob/master/CHANGELOG.md)."), colour=cmn.colours.neutral, timestamp=datetime.utcnow()) embed.set_footer(text=ctx.author.name, diff --git a/exts/fun.py b/exts/fun.py index f7352ba..d90d99e 100644 --- a/exts/fun.py +++ b/exts/fun.py @@ -3,7 +3,7 @@ Fun extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/exts/grid.py b/exts/grid.py index e8ca466..76f4d8e 100644 --- a/exts/grid.py +++ b/exts/grid.py @@ -3,7 +3,7 @@ Grid extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/exts/ham.py b/exts/ham.py index 2f14eda..f48872e 100644 --- a/exts/ham.py +++ b/exts/ham.py @@ -3,7 +3,7 @@ Ham extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ import json diff --git a/exts/image.py b/exts/image.py index 1056957..e1014b5 100644 --- a/exts/image.py +++ b/exts/image.py @@ -3,7 +3,7 @@ Image extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/exts/morse.py b/exts/morse.py index 4b84ff4..8222518 100644 --- a/exts/morse.py +++ b/exts/morse.py @@ -3,7 +3,7 @@ Morse Code extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/exts/qrz.py b/exts/qrz.py index 07db40c..c09d863 100644 --- a/exts/qrz.py +++ b/exts/qrz.py @@ -3,7 +3,7 @@ QRZ extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ from collections import OrderedDict @@ -101,7 +101,7 @@ class QRZCog(commands.Cog): async def qrz_login(user: str, passwd: str, session: aiohttp.ClientSession): - url = f'http://xmldata.qrz.com/xml/current/?username={user};password={passwd};agent=qrmbot' + url = f'http://xmldata.qrz.com/xml/current/?username={user};password={passwd};agent=discord-qrm2' async with session.get(url) as resp: if resp.status != 200: raise ConnectionError(f'Unable to connect to QRZ (HTTP Error {resp.status})') diff --git a/exts/study.py b/exts/study.py index e19b12d..8b85eaa 100644 --- a/exts/study.py +++ b/exts/study.py @@ -3,7 +3,7 @@ Study extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/exts/weather.py b/exts/weather.py index a72e806..f7aed05 100644 --- a/exts/weather.py +++ b/exts/weather.py @@ -3,7 +3,7 @@ Weather extension for qrm --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ diff --git a/info.py b/info.py index 3ca279b..20a174d 100644 --- a/info.py +++ b/info.py @@ -3,7 +3,7 @@ Static info about the bot. --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. --- @@ -23,5 +23,5 @@ General Public License, version 2. authors = ("@ClassAbbyAmplifier#2229", "@0x5c#0639") description = """A bot with various useful ham radio-related functions, written in Python.""" license = "Released under the GNU General Public License v2" -contributing = "Check out the source on GitHub, contributions welcome: https://github.com/classabbyamp/discord-qrm-bot" +contributing = "Check out the source on GitHub, contributions welcome: https://github.com/classabbyamp/discord-qrm2" release = '1.0.0' diff --git a/main.py b/main.py index 43a8a8d..308099d 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ qrm, a bot for Discord --- Copyright (C) 2019 Abigail Gold, 0x5c -This file is part of discord-qrmbot and is released under the terms of the GNU +This file is part of discord-qrm2 and is released under the terms of the GNU General Public License, version 2. """ From 9bbe71a67dc2799ffe1a6d277876d570bcc5fd20 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 8 Dec 2019 16:02:09 -0500 Subject: [PATCH 11/13] add shutdown/restart console messages. Fixes #89 --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index 43a8a8d..9b4199c 100644 --- a/main.py +++ b/main.py @@ -45,6 +45,7 @@ async def _restart_bot(ctx: commands.Context): """Restarts the bot.""" global exit_code await cmn.add_react(ctx.message, cmn.emojis.good) + print(f"[**] Restarting! Requested by {ctx.author}.") exit_code = 42 # Signals to the wrapper script that the bot needs to be restarted. await bot.logout() @@ -55,6 +56,7 @@ async def _shutdown_bot(ctx: commands.Context): """Shuts down the bot.""" global exit_code await cmn.add_react(ctx.message, cmn.emojis.good) + print(f"[**] Shutting down! Requested by {ctx.author}.") exit_code = 0 # Signals to the wrapper script that the bot should not be restarted. await bot.logout() From 8c3fdd9b90d28e1f8c8fbfda8a29116d5f139f29 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Mon, 9 Dec 2019 02:17:06 -0500 Subject: [PATCH 12/13] add space = slash in CW resources file. fixes #102 --- resources/morse.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/morse.json b/resources/morse.json index d43c9a2..51f7a79 100644 --- a/resources/morse.json +++ b/resources/morse.json @@ -8,5 +8,5 @@ "?": "..--..", "'": ".----.", "!": "-.-.--", "/": "-..-.", "(": "-.--.", ")": "-.--.-", "&": ".-...", ":": "---...", ";": "-.-.-.", "=": "-...-", "+": ".-.-.", "-": "-....-", "\"": ".-..-.", "@": ".--.-.", "Ä": ".-.-", "Å": ".-.-", "Ą": ".-.-", "Æ": ".-.-", -"É": "..-..", "Ñ": "--.--", "Ö": "---.", "Ü": "..--", "Š": "----" +"É": "..-..", "Ñ": "--.--", "Ö": "---.", "Ü": "..--", "Š": "----", " ": "/" } From e2fa7713befb61e547bc974db0c31ffc67e91db2 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 9 Dec 2019 23:50:01 -0500 Subject: [PATCH 13/13] update issue templates to make more sense --- .github/ISSUE_TEMPLATE/bug_report.md | 15 ++++++--------- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 53c1e4c..2888487 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,6 @@ --- name: Bug report -about: Create a report to help us improve +about: Report a bug to help us improve qrm title: '' labels: bug assignees: '' @@ -12,10 +12,8 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error +1. Run command '...' with input '...' +2. See error **Expected behavior** A clear and concise description of what you expected to happen. @@ -23,10 +21,9 @@ A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. -**System (please complete the following information if applicable):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] +**System (include if related to running the bot):** + - OS: [e.g. Linux, Docker] + - Version: [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 11fc491..abd211f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,6 +1,6 @@ --- name: Feature request -about: Suggest an idea for this project +about: Suggest an idea for qrm title: '' labels: enhancement assignees: ''