Skip to content

Commit

Permalink
Add DM notifications and migrate commands into command groups (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostopheles authored Jun 27, 2024
2 parents e450129 + e425668 commit b373977
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 59 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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.

36 changes: 22 additions & 14 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import discord

from time import time
from discord.ext import bridge, commands

logger = logging.getLogger("discord.admin")
Expand All @@ -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."""

Expand Down Expand Up @@ -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()
Expand All @@ -69,14 +75,25 @@ 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")
await ctx.defer()
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,
Expand All @@ -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))
16 changes: 11 additions & 5 deletions cogs/nux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -43,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

Expand Down
74 changes: 43 additions & 31 deletions cogs/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -96,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}`"
Expand Down Expand Up @@ -506,10 +514,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,
Expand Down Expand Up @@ -589,10 +600,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,
Expand Down Expand Up @@ -623,10 +633,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."""
Expand All @@ -646,10 +653,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(
Expand All @@ -669,10 +679,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,
Expand Down Expand Up @@ -707,9 +714,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):
Expand Down Expand Up @@ -744,9 +757,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):
Expand Down Expand Up @@ -783,10 +798,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."""
Expand Down

0 comments on commit b373977

Please sign in to comment.