From 8a9d94f0752a9a077e419fe3ec21c14239011b79 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sat, 7 Jul 2018 13:56:21 +0200 Subject: Add a `otname.list` command. --- bot/cogs/off_topic_names.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 2a3cb2aa7..603bd4993 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -2,10 +2,12 @@ import asyncio import logging from datetime import datetime, timedelta +from discord import Colour, Embed from discord.ext.commands import BadArgument, Bot, Context, Converter, command from bot.constants import Channels, Keys, Roles, URLs from bot.decorators import with_role +from bot.pagination import LinePaginator CHANNELS = (Channels.off_topic_0, Channels.off_topic_1, Channels.off_topic_2) @@ -104,6 +106,32 @@ class OffTopicNames: error_reason = response.get('message', "No reason provided.") await ctx.send(f":warning: got non-200 from the API: {error_reason}") + @command(name='otname.list()', aliases=['otname.list']) + @with_role(Roles.owner, Roles.admin, Roles.moderator) + async def otname_list(self, ctx): + """ + Lists all currently known off-topic channel names in a paginator. + Restricted to Moderator and above to not spoil the surprise. + """ + + result = await self.bot.http_session.get( + URLs.site_off_topic_names_api, + headers=self.headers + ) + response = await result.json() + + embed = Embed( + title=f"Known off-topic names (`{len(response)}` total)", + colour=Colour.blue() + ) + await LinePaginator.paginate( + sorted(response), + ctx, + embed, + max_size=400, + empty=False + ) + def setup(bot: Bot): bot.add_cog(OffTopicNames(bot)) -- cgit v1.2.3 From 6d372c622f5a88ffa909ac40b75eb88f19277832 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sat, 7 Jul 2018 19:56:38 +0200 Subject: Add bullet points. --- bot/cogs/off_topic_names.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index 603bd4993..dbaa43db9 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -119,18 +119,13 @@ class OffTopicNames: headers=self.headers ) response = await result.json() + lines = sorted(f"• {name}" for name in response) embed = Embed( title=f"Known off-topic names (`{len(response)}` total)", colour=Colour.blue() ) - await LinePaginator.paginate( - sorted(response), - ctx, - embed, - max_size=400, - empty=False - ) + await LinePaginator.paginate(lines, ctx, embed, max_size=400, empty=False) def setup(bot: Bot): -- cgit v1.2.3