Skip to content

Commit

Permalink
Support user installation (#20)
Browse files Browse the repository at this point in the history
* Use contexts and integration types

* Update bot.py

* Update nux.py

* Remove NUX test command

* Update contexts for admin cog

* Update admin.py
  • Loading branch information
Ghostopheles authored Jun 30, 2024
1 parent b1c5ca4 commit ff053ec
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@ invite.txt
*.bat
cogs/cache/
.vscode/
*.code-workspace
*.code-workspace
pycord/
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def send_message_to_owner(self, message: str):
debug_guilds = [int(os.getenv("DEBUG_GUILD_ID")), int(os.getenv("DEBUG_GUILD_ID2"))] # type: ignore
else: # is NOT debug mode
token = os.getenv("DISCORD_TOKEN")
debug_guilds = []
debug_guilds = None

bot = CDNBot(
command_prefix="!",
Expand Down
10 changes: 0 additions & 10 deletions cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, bot: bridge.Bot):
admin_commands = discord.SlashCommandGroup(
name="admin",
description="Administration commands",
guild_only=True,
guild_ids=HOME_GUILD,
)

Expand Down Expand Up @@ -83,15 +82,6 @@ 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(
Expand Down
4 changes: 2 additions & 2 deletions cogs/nux.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
logger = logging.getLogger("discord.nux")


class GuildNUX(commands.Cog):
class NUX(commands.Cog):
def __init__(self, bot: bridge.Bot):
self.bot = bot
self.guild_cfg = GuildCFG()
Expand Down Expand Up @@ -69,4 +69,4 @@ async def on_guild_join(self, guild: discord.Guild):


def setup(bot):
bot.add_cog(GuildNUX(bot))
bot.add_cog(NUX(bot))
32 changes: 27 additions & 5 deletions cogs/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,26 @@ async def handle_unk_command(self, ctx: discord.ApplicationContext):

# DISCORD COMMANDS

@bridge.bridge_command(name="cdndata")
@bridge.bridge_command(
name="cdndata",
contexts={
discord.InteractionContextType.guild,
discord.InteractionContextType.bot_dm,
},
)
async def cdn_data(self, ctx: bridge.BridgeApplicationContext):
"""Returns a paginator with the currently cached CDN data."""
logger.debug("Generating paginator to display CDN data...")
paginator = self.build_paginator_for_current_build_data()
await paginator.respond(ctx.interaction, ephemeral=True)

@bridge.bridge_command(name="branches")
@bridge.bridge_command(
name="branches",
contexts={
discord.InteractionContextType.guild,
discord.InteractionContextType.bot_dm,
},
)
@commands.cooldown(1, COOLDOWN, commands.BucketType.user)
async def cdn_branches(self, ctx: bridge.BridgeApplicationContext):
"""Returns all observable branches."""
Expand All @@ -541,7 +553,9 @@ async def cdn_branches(self, ctx: bridge.BridgeApplicationContext):
)

watchlist_commands = discord.SlashCommandGroup(
name="watchlist", description="Watchlist commands", guild_only=True
name="watchlist",
description="Watchlist commands",
contexts={discord.InteractionContextType.guild},
)

@watchlist_commands.command(
Expand Down Expand Up @@ -702,7 +716,9 @@ async def cdn_edit_watchlist(
await ctx.respond(message, view=menu, ephemeral=True, delete_after=DELETE_AFTER)

channel_commands = discord.SlashCommandGroup(
name="channel", description="Notification channel commands", guild_only=True
name="channel",
description="Notification channel commands",
contexts={discord.InteractionContextType.guild},
)

@channel_commands.command(
Expand Down Expand Up @@ -763,7 +779,13 @@ async def cdn_last_update(self, ctx: bridge.BridgeApplicationContext):
)

dm_commands = discord.SlashCommandGroup(
name="dm", description="DM notification commands"
name="dm",
description="DM notification commands",
contexts={
discord.InteractionContextType.private_channel,
discord.InteractionContextType.bot_dm,
},
integration_types={discord.IntegrationType.user_install},
)

@dm_commands.command(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
py-cord==2.5.0
py-cord[speed]==2.6.0
httpx[http2]==0.27.0
tweepy[async]==4.14.0
pyyaml==6.0.1

0 comments on commit ff053ec

Please sign in to comment.