From 783b56c526360c66290295db14424ca107c0ed57 Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 08:53:30 -0500 Subject: [PATCH 1/6] Move commands into command groups --- cogs/watcher.py | 64 +++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/cogs/watcher.py b/cogs/watcher.py index 44b6d55..b7d9a0c 100644 --- a/cogs/watcher.py +++ b/cogs/watcher.py @@ -20,7 +20,7 @@ from .utils import get_discord_timestamp from .api.twitter import Twitter -START_LOOPS = True +START_LOOPS = False logger = logging.getLogger("discord.cdn.watcher") @@ -42,6 +42,8 @@ DELETE_AFTER = 120 COOLDOWN = 5 +ADMIN_ONLY_PERM = discord.Permissions(administrator=True) + class CDNCog(commands.Cog): """This is the actual Cog that gets added to the Discord bot.""" @@ -506,10 +508,13 @@ async def cdn_branches(self, ctx: bridge.BridgeApplicationContext): message, ephemeral=True, delete_after=DELETE_AFTER ) - @bridge.bridge_command( - name="addtowatchlist", - default_member_permissions=discord.Permissions(administrator=True), - guild_only=True, + watchlist_commands = discord.SlashCommandGroup( + name="watchlist", description="Watchlist commands", guild_only=True + ) + + @watchlist_commands.command( + name="add", + default_member_permissions=ADMIN_ONLY_PERM, input_type=str, min_length=3, max_length=500, @@ -589,10 +594,9 @@ async def cdn_add_to_watchlist( delete_after=DELETE_AFTER, ) - @bridge.bridge_command( - name="removefromwatchlist", - default_member_permissions=discord.Permissions(administrator=True), - guild_only=True, + @watchlist_commands.command( + name="remove", + default_member_permissions=ADMIN_ONLY_PERM, input_type=str, min_length=3, max_length=500, @@ -623,10 +627,7 @@ async def cdn_remove_from_watchlist( delete_after=DELETE_AFTER, ) - @bridge.bridge_command( - name="watchlist", - guild_only=True, - ) + @watchlist_commands.command(name="view") @commands.cooldown(1, COOLDOWN, commands.BucketType.user) async def cdn_watchlist(self, ctx: bridge.BridgeApplicationContext): """Returns the watchlist for your guild.""" @@ -646,10 +647,13 @@ async def cdn_watchlist(self, ctx: bridge.BridgeApplicationContext): message, ephemeral=True, delete_after=DELETE_AFTER ) - @bridge.bridge_command( - name="setchannel", - default_member_permissions=discord.Permissions(administrator=True), - guild_only=True, + channel_commands = discord.SlashCommandGroup( + name="channel", description="Notification channel commands", guild_only=True + ) + + @channel_commands.command( + name="set", + default_member_permissions=ADMIN_ONLY_PERM, ) @commands.cooldown(1, 5, commands.BucketType.user) async def cdn_set_channel( @@ -669,10 +673,7 @@ async def cdn_set_channel( delete_after=DELETE_AFTER, ) - @bridge.bridge_command( - name="getchannel", - guild_only=True, - ) + @channel_commands.command(name="get") @commands.cooldown(1, COOLDOWN, commands.BucketType.user) async def cdn_get_channel( self, @@ -707,9 +708,15 @@ async def cdn_last_update(self, ctx: bridge.BridgeApplicationContext): delete_after=DELETE_AFTER, ) - @bridge.bridge_command( + dm_commands = discord.SlashCommandGroup( + name="dm", description="DM notification commands" + ) + + @dm_commands.command( name="subscribe", - guild_ids=TEST_GUILDS, + input_type=str, + min_length=3, + max_length=500, ) @commands.cooldown(1, COOLDOWN, commands.BucketType.user) async def user_subscribe(self, ctx: bridge.BridgeApplicationContext, branch: str): @@ -744,9 +751,11 @@ async def user_subscribe(self, ctx: bridge.BridgeApplicationContext, branch: str message, ephemeral=True, delete_after=DELETE_AFTER ) - @bridge.bridge_command( + @dm_commands.command( name="unsubscribe", - guild_ids=TEST_GUILDS, + input_type=str, + min_length=3, + max_length=500, ) @commands.cooldown(1, COOLDOWN, commands.BucketType.user) async def user_unsubscribe(self, ctx: bridge.BridgeApplicationContext, branch: str): @@ -783,10 +792,7 @@ async def user_unsubscribe(self, ctx: bridge.BridgeApplicationContext, branch: s message, ephemeral=True, delete_after=DELETE_AFTER ) - @bridge.bridge_command( - name="subscribed", - guild_ids=TEST_GUILDS, - ) + @dm_commands.command(name="view") @commands.cooldown(1, COOLDOWN, commands.BucketType.user) async def user_subscribed(self, ctx: bridge.BridgeApplicationContext): """View all branches you're receiving DM updates for.""" From 09b2c1a0b76e578e3a604f8b2c2860936f05192c Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 09:34:55 -0500 Subject: [PATCH 2/6] Move admin commands into a group --- cogs/admin.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index 6b0cf21..bed1562 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -2,7 +2,6 @@ import logging import discord -from time import time from discord.ext import bridge, commands logger = logging.getLogger("discord.admin") @@ -14,15 +13,22 @@ 1144396478840844439, ] -HOME_GUILD = 318246001309646849 +HOME_GUILD = [318246001309646849] class AdminCog(commands.Cog): def __init__(self, bot: bridge.Bot): self.bot = bot + admin_commands = discord.SlashCommandGroup( + name="admin", + description="Administration commands", + guild_only=True, + guild_ids=HOME_GUILD, + ) + @commands.is_owner() - @bridge.bridge_command(name="reload", guild_ids=[HOME_GUILD], guild_only=True) + @admin_commands.command(name="reload") async def reload_cog(self, ctx: bridge.BridgeApplicationContext, cog_name: str): """Reloads a currently loaded cog.""" @@ -51,7 +57,7 @@ async def reload_cog(self, ctx: bridge.BridgeApplicationContext, cog_name: str): ) @commands.is_owner() - @bridge.bridge_command(name="guilds", guild_ids=[HOME_GUILD], guild_only=True) + @admin_commands.command(name="guilds") async def get_all_guilds(self, ctx: bridge.BridgeApplicationContext): """Dumps details for all guilds Algalon is a part of.""" await ctx.defer() @@ -69,7 +75,7 @@ async def get_all_guilds(self, ctx: bridge.BridgeApplicationContext): message_bytes.close() @commands.is_owner() - @bridge.bridge_command(name="forceupdate", guild_ids=[HOME_GUILD], guild_only=True) + @admin_commands.command(name="forceupdate") async def force_update_check(self, ctx: bridge.BridgeApplicationContext): """Forces a CDN check.""" watcher = self.bot.get_cog("CDNCog") @@ -77,6 +83,17 @@ async def force_update_check(self, ctx: bridge.BridgeApplicationContext): await watcher.cdn_auto_refresh() await ctx.respond("Updates complete.", ephemeral=True, delete_after=300) + @commands.is_owner() + @admin_commands.command(name="nuxtest") + async def nuxtest(self, ctx: bridge.BridgeApplicationContext): + guild = ctx.guild + nux_cog = self.bot.get_cog("GuildNUX") + message = await nux_cog.get_nux_message(guild) + + await ctx.respond(message, ephemeral=True, delete_after=300) + + # funni commands + @bridge.bridge_command( name="alien", guild_ids=DEBUG_GUILDS, @@ -102,15 +119,6 @@ async def Perceive( await message.add_reaction(emoji) await ctx.respond("gottem", ephemeral=True, delete_after=5) - @commands.is_owner() - @bridge.bridge_command(name="nuxtest", guild_ids=[HOME_GUILD], guild_only=True) - async def nuxtest(self, ctx: bridge.BridgeApplicationContext): - guild = ctx.guild - nux_cog = self.bot.get_cog("GuildNUX") - message = nux_cog.get_nux_message(guild) - - await ctx.respond(message, ephemeral=True, delete_after=300) - def setup(bot): bot.add_cog(AdminCog(bot)) From ecea12141ccd469139308b919e510ec14eaa84ca Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 09:35:27 -0500 Subject: [PATCH 3/6] Update NUX message --- cogs/nux.py | 14 ++++++++++---- cogs/watcher.py | 12 +++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cogs/nux.py b/cogs/nux.py index d512a7e..2b720ee 100644 --- a/cogs/nux.py +++ b/cogs/nux.py @@ -18,11 +18,17 @@ async def get_nux_message( self, guild: discord.Guild, ) -> str: - cmd_link_set_channel = self.watcher.get_command_link("setchannel") - cmd_link_get_watchlist = self.watcher.get_command_link("watchlist") - cmd_link_add_to_watchlist = self.watcher.get_command_link("addtowatchlist") + cmd_link_set_channel = self.watcher.get_command_link( + "channel set", self.watcher.channel_commands + ) + cmd_link_get_watchlist = self.watcher.get_command_link( + "watchlist view", self.watcher.watchlist_commands + ) + cmd_link_add_to_watchlist = self.watcher.get_command_link( + "watchlist add", self.watcher.watchlist_commands + ) cmd_link_rm_from_watchlist = self.watcher.get_command_link( - "removefromwatchlist" + "watchlist remove", self.watcher.watchlist_commands ) cmd_link_data = self.watcher.get_command_link("cdndata") diff --git a/cogs/watcher.py b/cogs/watcher.py index b7d9a0c..6c58874 100644 --- a/cogs/watcher.py +++ b/cogs/watcher.py @@ -98,15 +98,21 @@ async def integrity_check(self): logger.info("Cache configuration check complete") - def get_command_link(self, command: str): - all_cmds = self.get_commands() + def get_command_link( + self, command: str, cmd_group: Optional[discord.SlashCommandGroup] = None + ): + if cmd_group is not None and isinstance(cmd_group, discord.SlashCommandGroup): + all_cmds = cmd_group.subcommands + else: + all_cmds = self.get_commands() + for cmd in all_cmds: if isinstance(cmd, bridge.BridgeCommand): slash = cmd.slash_variant if slash and slash.name == command: return slash.mention elif isinstance(cmd, discord.SlashCommand): - if cmd.name == command and cmd.id is not None: + if cmd.qualified_name == command: return cmd.mention return f"`/{command}`" From cb80beeffb1b3b83c027cda2ea3f6cefc534cbfb Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 09:45:19 -0500 Subject: [PATCH 4/6] Update nux link --- cogs/nux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/nux.py b/cogs/nux.py index 2b720ee..2b2e66d 100644 --- a/cogs/nux.py +++ b/cogs/nux.py @@ -49,7 +49,7 @@ async def get_nux_message( :blue_heart: Thanks for trying out Algalon! :blue_heart: -If you have any questions, concerns, or suggestions, please reach out to {owner_mention} here on Discord, or open a GitHub issue [here](https://github.com/Ghostopheles/better-algalon). +If you have any questions, concerns, or suggestions, please reach out to {owner_mention} here on Discord, or open a GitHub issue [here](https://github.ghst.tools/better-algalon). """ return nux_message From 1d6b3f3a0cb4dcf37f44b7be808e21c2061c23d4 Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 09:57:42 -0500 Subject: [PATCH 5/6] Update changelog and readme --- CHANGELOG.md | 11 +++++++++++ README.md | 18 +++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d54a4c2..d54c447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Changelog v1.9.2 - Gallium + +## Added +- DM notifications have been enabled frfr on all server Algalon is a part of. + +## Changed +- Commands have been restructured. + - Watchlist commands have been moved to `/watchlist {add|remove|view}` + - Channel commands have been moved to `/channel {set|get}` + - DM commands have been moved to `/dm {subscribe|unsubscribe|view}` + # Changelog v1.9 - Yttrium ## Added diff --git a/README.md b/README.md index 004e8f5..cc4e096 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # better-algalon [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![LastUpdate](https://img.shields.io/github/last-commit/Ghostamoose/better-algalon?style=flat-square) [![Docker](https://github.com/Ghostamoose/better-algalon/actions/workflows/docker-publish.yml/badge.svg)](https://github.com/Ghostamoose/better-algalon/actions/workflows/docker-publish.yml) -v1.9 - Yttrium +v1.9.2 - Gallium A bot that watches Blizzard's CDN and automatically posts new build updates to specified Discord channels. @@ -82,23 +82,23 @@ Algalon provides a number of commands to control your guild's (server) watchlist #### Watchlist Controls -`/addtowatchlist`*: Adds a specific branch to your guild's watchlist. Specify multiple branches at once by separating them with a comma. +`/watchlist add`*: Adds a specific branch to your guild's watchlist. Specify multiple branches at once by separating them with a comma. -`/removefromwatchlist`*: Removes a specific branch to your guild's watchlist. +`/watchlist remove`*: Removes a specific branch to your guild's watchlist. -`/watchlist`: Returns your guild's current watchlist. +`/watchlist view`: Returns your guild's current watchlist. #### Notification Channel Controls -`/setchannel`*: Sets the channel in which it's invoked as the notification channel for your guild. Optionally, specify a game to set the notification channel for that game. Defaults to Warcraft. +`/channel set`*: Sets the channel in which it's invoked as the notification channel for your guild. Optionally, specify a game to set the notification channel for that game. Defaults to Warcraft. -`/getchannel`: Returns the current notification channel for your guild. Optionally, specify a game to get the notification channel for that game. Defaults to Warcraft. +`/channel get`: Returns the current notification channel for your guild. Optionally, specify a game to get the notification channel for that game. Defaults to Warcraft. #### User DM Updates -`/subscribe`: Subscribes the user to DM updates for the given branches. Supports comma-delimited input. +`/dm subscribe`: Subscribes the user to DM updates for the given branches. Supports comma-delimited input. -`/unsubscribe`: Unsubscribes the user from DM updates for the given branches. Supports comma-delimited input. +`/dm unsubscribe`: Unsubscribes the user from DM updates for the given branches. Supports comma-delimited input. -`/subscribed`: Returns all the branches you're currently subscribed to. +`/dm view`: Returns all the branches you're currently subscribed to. From e4256686b7d7df9806ed306344042f3a80871d37 Mon Sep 17 00:00:00 2001 From: Ghostopheles Date: Tue, 25 Jun 2024 10:00:20 -0500 Subject: [PATCH 6/6] haha reenable loops --- cogs/watcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/watcher.py b/cogs/watcher.py index 6c58874..eb0d04c 100644 --- a/cogs/watcher.py +++ b/cogs/watcher.py @@ -20,7 +20,7 @@ from .utils import get_discord_timestamp from .api.twitter import Twitter -START_LOOPS = False +START_LOOPS = True logger = logging.getLogger("discord.cdn.watcher")