diff --git a/src/extensions/channels.py b/src/extensions/channels.py index dc1a34d..b45c623 100644 --- a/src/extensions/channels.py +++ b/src/extensions/channels.py @@ -5,8 +5,9 @@ Loading this file via `commands.Bot.load_extension` will add `ChannelCog` to the import logging +from sqlalchemy.orm import aliased from sqlalchemy import select, insert, delete, and_ -from discord import Interaction, TextChannel +from discord import Interaction, TextChannel, Embed, Colour from discord.ext import commands from discord.app_commands import Group, Choice, autocomplete @@ -77,7 +78,7 @@ class ChannelCog(commands.Cog): # All RSS commands belong to this group. channel_group = Group( - name="channel", + name="channels", description="Commands for channel assignment.", guild_only=True # These commands belong to channels of ) @@ -152,6 +153,37 @@ class ChannelCog(commands.Cog): await followup(inter, "I've removed this item (placeholder response)") + @channel_group.command(name="list") + async def list_feeds(self, inter: Interaction): + # """""" + + await inter.response.defer() + + async with DatabaseManager() as database: + whereclause = and_(FeedChannelModel.discord_server_id == inter.guild_id) + query = ( + select(FeedChannelModel) + .where(whereclause) + .order_by(FeedChannelModel.search_name) + ) + result = await database.session.execute(query) + + feed_channels = result.scalars().all() + + if not feed_channels: + await followup(inter, "It looks like there are no feed channels available.") + return + + output = "\n".join([f"{i}. <#{feed.discord_channel_id}> ยท {feed.search_name}" for i, feed in enumerate(feed_channels)]) + + embed = Embed( + title="Saved Feed Channels", + description=f"placeholder, add rss hyperlink for each item using a sql join\n\n{output}", + colour=Colour.lighter_grey() + ) + + await followup(inter, embed=embed) + async def setup(bot): """