diff options
| -rw-r--r-- | bot/cogs/bigbrother.py | 3 | ||||
| -rw-r--r-- | bot/cogs/nominations.py | 110 |
2 files changed, 111 insertions, 2 deletions
diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 126a108fc..a6962efea 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -146,7 +146,6 @@ class BigBrother: embeds from being automatically generated. :param message: the message to log - :param destination: the channel in which to log the message """ content = message.clean_content @@ -159,7 +158,7 @@ class BigBrother: await self.channel.send(content) - await messages.send_attachments(message, destination) + await messages.send_attachments(message, self.channel) @group(name='bigbrother', aliases=('bb',), invoke_without_command=True) @with_role(Roles.owner, Roles.admin, Roles.moderator) diff --git a/bot/cogs/nominations.py b/bot/cogs/nominations.py new file mode 100644 index 000000000..89fd0fba5 --- /dev/null +++ b/bot/cogs/nominations.py @@ -0,0 +1,110 @@ +import logging + +from discord import Color, Embed, User +from discord.ext.commands import Context, group + +from bot.cogs.bigbrother import BigBrother, Roles +from bot.constants import Channels +from bot.decorators import with_role +from bot.pagination import LinePaginator + + +log = logging.getLogger(__name__) + + +class Nominations(BigBrother): + """Monitor potential helpers, NSA-style.""" + + async def on_ready(self): + """Retrieve nominees from the API.""" + + self.channel = self.bot.get_channel(Channels.talent_pool) + if self.channel is None: + log.error("Cannot find talent pool channel. Cannot watch nominees.") + else: + nominations = await self.bot.api_client.get( + 'bot/nominations', + params={'active': 'true'} + ) + self.update_cache(nominations) + + async def on_member_ban(self, *_): + pass + + @group(name='nominations', aliases=('n',), invoke_without_command=True) + @with_role(Roles.owner, Roles.admin, Roles.moderator) + async def bigbrother_group(self, ctx: Context): + """Nominate helpers, NSA-style.""" + + await ctx.invoke(self.bot.get_command("help"), "nominations") + + @bigbrother_group.command(name='nominated', aliases=('nominees', 'all')) + @with_role(Roles.owner, Roles.admin, Roles.moderator) + async def watched_command(self, ctx: Context, from_cache: bool = True): + if from_cache: + lines = tuple(f"• <@{user_id}>" for user_id in self.watched_users) + + else: + active_nominations = await self.bot.api_client.get( + 'bot/nominations', + params={'active': 'true'} + ) + self.update_cache(active_nominations) + lines = tuple( + f"• <@{entry['user']}>: {entry['reason'] or '*no reason provided*'}" + for entry in active_nominations + ) + + await LinePaginator.paginate( + lines or ("There's nothing here yet.",), + ctx, + Embed( + title="Nominated users" + " (cached)" * from_cache, + color=Color.blue() + ), + empty=False + ) + + @bigbrother_group.command(name='nominate', aliases=('n',)) + @with_role(Roles.owner, Roles.admin, Roles.moderator) + async def watch_command(self, ctx: Context, user: User, *, reason: str): + """Talent pool the given `user`.""" + + await self.bot.api_client.patch( + 'bot/nominations', + json={ + 'active': True, + 'author': ctx.author.id, + 'reason': reason, + 'user': user.id + } + ) + self.watched_users.add(user.id) + await ctx.send(":ok_hand: user added to talent pool") + + @bigbrother_group.command(name='unnominate', aliases=('un',)) + @with_role(Roles.owner, Roles.admin, Roles.moderator) + async def unwatch_command(self, ctx: Context, user: User): + """Stop talent pooling the given `user`.""" + + nomination = await self.bot.api_client.get( + 'bot/nominations/' + str(user.id) + ) + + if not nomination['active']: + await ctx.send(":x: the nomination is already inactive") + + else: + await self.bot.api_client.patch( + 'bot/nominations/' + str(user.id), + json={'active': False} + ) + self.watched_users.remove(user.id) + if user.id in self.channel_queues: + del self.channel_queues[user.id] + await ctx.send(f":ok_hand: {user} is no longer part of the talent pool") + + +def setup(bot): + bot.add_cog(Nominations(bot)) + log.info("Cog loaded: Nominations") |