diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/watchchannels/bigbrother.py | 43 | 
1 files changed, 23 insertions, 20 deletions
| diff --git a/bot/cogs/watchchannels/bigbrother.py b/bot/cogs/watchchannels/bigbrother.py index 5e1f2c30b..55805cf87 100644 --- a/bot/cogs/watchchannels/bigbrother.py +++ b/bot/cogs/watchchannels/bigbrother.py @@ -1,15 +1,14 @@  import logging  from collections import ChainMap +from typing import Union  from discord import Color, Embed, User  from discord.ext.commands import Context, group -from bot.constants import ( -    Channels, Roles -) +from bot.constants import Channels, Roles, Webhooks  from bot.decorators import with_role  from bot.utils.moderation import post_infraction -from .watchchannel import WatchChannel +from .watchchannel import WatchChannel, proxy_user  log = logging.getLogger(__name__) @@ -19,43 +18,51 @@ class BigBrother(WatchChannel):      def __init__(self, bot):          super().__init__(bot) -        self.log = log +        self.log = log  # to ensure logs created in the super() get the name of this file          self.destination = Channels.big_brother_logs -        self.webhook_id = 569096053333164052 +        self.webhook_id = Webhooks.big_brother          self.api_endpoint = 'bot/infractions' -        self.api_default_params = {'active': 'true', 'type': 'watch'} +        self.api_default_params = { +            'active': 'true', 'type': 'watch', 'ordering': '-inserted_at' +        }      @group(name='bigbrother', aliases=('bb',), invoke_without_command=True)      @with_role(Roles.owner, Roles.admin, Roles.moderator)      async def bigbrother_group(self, ctx: Context) -> None:          """Monitors users by relaying their messages to the BigBrother watch channel""" -          await ctx.invoke(self.bot.get_command("help"), "bigbrother") -    @bigbrother_group.command(name='watched', aliases=('all',)) +    @bigbrother_group.command(name='watched', aliases=('all', 'list'))      @with_role(Roles.owner, Roles.admin, Roles.moderator) -    async def watched_command(self, ctx: Context, update_cache: bool = False) -> None: +    async def watched_command(self, ctx: Context, update_cache: bool = True) -> None:          """          Shows the users that are currently being monitored in BigBrother.          The optional kwarg `update_cache` can be used to update the user          cache using the API before listing the users.          """ -          await self.list_watched_users(ctx, update_cache)      @bigbrother_group.command(name='watch', aliases=('w',))      @with_role(Roles.owner, Roles.admin, Roles.moderator) -    async def watch_command(self, ctx: Context, user: User, *, reason: str) -> None: +    async def watch_command(self, ctx: Context, user: Union[User, proxy_user], *, reason: str) -> None:          """          Relay messages sent by the given `user` to the `#big-brother-logs` channel.          A `reason` for adding the user to BigBrother is required and will displayed          in the header when relaying messages of this user to the watchchannel.          """ +        if user.bot: +            e = Embed( +                description=f":x: **I'm sorry {ctx.author}, I'm afraid I can't do that. I only watch humans.**", +                color=Color.red() +            ) +            return await ctx.send(embed=e) -        await self.fetch_user_cache() +        if not await self.fetch_user_cache(): +            log.error("Failed to update user cache; can't watch user {user}") +            return          if user.id in self.watched_users:              e = Embed( @@ -77,9 +84,8 @@ class BigBrother(WatchChannel):      @bigbrother_group.command(name='unwatch', aliases=('uw',))      @with_role(Roles.owner, Roles.admin, Roles.moderator) -    async def unwatch_command(self, ctx: Context, user: User, *, reason: str) -> None: +    async def unwatch_command(self, ctx: Context, user: Union[User, proxy_user], *, reason: str) -> None:          """Stop relaying messages by the given `user`.""" -          active_watches = await self.bot.api_client.get(              self.api_endpoint,              params=ChainMap( @@ -89,7 +95,6 @@ class BigBrother(WatchChannel):          )          if active_watches:              [infraction] = active_watches -            log.trace(infraction)              await self.bot.api_client.patch(                  f"{self.api_endpoint}/{infraction['id']}",                  json={'active': False} @@ -101,10 +106,8 @@ class BigBrother(WatchChannel):                  description=f":white_check_mark: **Messages sent by {user} will no longer be relayed**",                  color=Color.green()              ) -            return await ctx.send(embed=e) -            self.watched_users.pop(str(user.id), None) -            self.message_queue.pop(str(user.id), None) -            self.consumption_queue.pop(str(user.id), None) +            await ctx.send(embed=e) +            self._remove_user(user.id)          else:              e = Embed(                  description=":x: **The specified user is currently not being watched**", | 
