From a71866ed6e2d003824f66053730d162c6fcc9d58 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Mon, 19 Aug 2024 21:21:21 +0100 Subject: [PATCH] command list tracked content --- src/extensions/cmds.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/extensions/cmds.py b/src/extensions/cmds.py index d64a941..1fa5fea 100644 --- a/src/extensions/cmds.py +++ b/src/extensions/cmds.py @@ -113,7 +113,7 @@ class CommandsCog(commands.Cog): channels = f"{item.channels_count}{' channels' if item.channels_count != 1 else ' channel'}" filters = f"{len(item.filters)}{' filters' if len(item.filters) != 1 else ' filter'}" notes = item.extra_notes[:25] + "..." if len(item.extra_notes) > 28 else item.extra_notes - links = f"[RSS URL]({item.url}) · [API URL]({API.API_EXTERNAL_ENDPOINT}subscription/{item.id}/)" + links = f"[RSS Link]({item.url}) · [API Link]({API.API_EXTERNAL_ENDPOINT}subscription/{item.id}/)" description = f"{channels}, {filters}\n" description += f"{notes}\n" if notes else "" @@ -145,6 +145,37 @@ class CommandsCog(commands.Cog): async def cmd_list_tracked(self, inter: Interaction): """List Tracked Content from this server, or a given sub""" + await inter.response.defer() + + def formatdata(index, item): + item = TrackedContent.from_dict(item) + sub = Subscription.from_dict(item.subscription) + + links = f"[Content Link]({item.url}) · [Message Link](https://discord.com/channels/{sub.guild_id}/{item.channel_id}/{item.message_id}/)" + description = f"Subscription: {sub.name}\n{links}" + + key = f"{index}. {item.title}" + return key, description + + async def getdata(page: int, pagesize: int): + async with aiohttp.ClientSession() as session: + api = API(self.bot.api_token, session) + return await api.get_tracked_content( + subscription__guild_id=inter.guild_id, page=page, page_size=pagesize + ) + + embed = Followup(f"Tracked Content in {inter.guild.name}").info()._embed + pagination = PaginationView( + self.bot, + inter=inter, + embed=embed, + getdata=getdata, + formatdata=formatdata, + pagesize=10, + initpage=1 + ) + await pagination.send() + # Group for test related commands test_group = Group( name="test",