From 9517f16e6d862bc0e83619306af6cadbc9e61b71 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 17:12:07 +0100 Subject: Adding mandatory unwatch reason for both bb and talent-pool --- bot/cogs/alias.py | 10 ++++------ bot/cogs/bigbrother.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py index 0e6b3a7c6..23562ad25 100644 --- a/bot/cogs/alias.py +++ b/bot/cogs/alias.py @@ -74,20 +74,18 @@ class Alias: self, ctx: Context, user: User, *, reason: str ): """ - Alias for invoking bigbrother watch user [text_channel]. + Alias for invoking bigbrother watch user reason. """ await self.invoke(ctx, "bigbrother watch", user, reason=reason) @command(name="unwatch", hidden=True) - async def bigbrother_unwatch_alias(self, ctx, user: User): + async def bigbrother_unwatch_alias(self, ctx, user: User, *, reason: str): """ - Alias for invoking bigbrother unwatch user. - - user: discord.User - A user instance to unwatch + Alias for invoking bigbrother unwatch user reason. """ - await self.invoke(ctx, "bigbrother unwatch", user) + await self.invoke(ctx, "bigbrother unwatch", user, reason=reason) @command(name="home", hidden=True) async def site_home_alias(self, ctx): diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index f07289985..caf194b4c 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -355,8 +355,12 @@ class BigBrother: @bigbrother_group.command(name='unwatch', aliases=('uw',)) @with_role(Roles.owner, Roles.admin, Roles.moderator) - async def unwatch_command(self, ctx: Context, user: User): - """Stop relaying messages by the given `user`.""" + async def unwatch_command(self, ctx: Context, user: User, *, reason: str): + """ + Stop relaying messages by the given `user`. + + A `reason` for unwatching is required, which will be added as a note to the user. + """ url = f"{URLs.site_bigbrother_api}?user_id={user.id}" async with self.bot.http_session.delete(url, headers=self.HEADERS) as response: @@ -364,14 +368,20 @@ class BigBrother: await ctx.send(f":ok_hand: will no longer relay messages sent by {user}") if user.id in self.watched_users: + channel = self.watched_users[user.id] + del self.watched_users[user.id] if user.id in self.channel_queues: del self.channel_queues[user.id] if user.id in self.watch_reasons: del self.watch_reasons[user.id] else: + channel = None log.warning(f"user {user.id} was unwatched but was not found in the cache") + reason = f"Unwatched ({channel.name if channel else 'unknown channel'}): {reason}" + await post_infraction(ctx, user, type="warning", reason=reason, hidden=True) + else: data = await response.json() reason = data.get('error_message', "no message provided") -- cgit v1.2.3 From 6a3a54a83d0f01064615353364d475e875cbde64 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 17:33:38 +0100 Subject: Adding method to update watched cache so it's reusable --- bot/cogs/bigbrother.py | 55 ++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index caf194b4c..36fd90ce9 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -73,6 +73,16 @@ class BigBrother: data = await response.json() self.update_cache(data) + async def update_watched_users(self): + async with self.bot.http_session.get(URLs.site_bigbrother_api, headers=self.HEADERS) as response: + if response.status == 200: + data = await response.json() + self.update_cache(data) + log.trace("Updated watch list cache") + return True + else: + return False + async def get_watch_information(self, user_id: int) -> WatchInformation: """ Fetches and returns the latest watch reason for a user using the infraction API """ @@ -309,35 +319,22 @@ class BigBrother: By default, the users are returned from the cache. If this is not desired, `from_cache` can be given as a falsy value, e.g. e.g. 'no'. """ - - if from_cache: - lines = tuple( - f"• <@{user_id}> in <#{self.watched_users[user_id].id}>" - for user_id in self.watched_users - ) - await LinePaginator.paginate( - lines or ("There's nothing here yet.",), - ctx, - Embed(title="Watched users (cached)", color=Color.blue()), - empty=False - ) - - else: - async with self.bot.http_session.get(URLs.site_bigbrother_api, headers=self.HEADERS) as response: - if response.status == 200: - data = await response.json() - self.update_cache(data) - lines = tuple(f"• <@{entry['user_id']}> in <#{entry['channel_id']}>" for entry in data) - - await LinePaginator.paginate( - lines or ("There's nothing here yet.",), - ctx, - Embed(title="Watched users", color=Color.blue()), - empty=False - ) - - else: - await ctx.send(f":x: got non-200 response from the API") + if not from_cache: + updated = await self.update_watched_users() + if not updated: + await ctx.send(f":x: Failed to update cache: non-200 response from the API") + return + + lines = tuple( + f"• <@{user_id}> in <#{self.watched_users[user_id].id}>" + for user_id in self.watched_users + ) + await LinePaginator.paginate( + lines or ("There's nothing here yet.",), + ctx, + Embed(title="Watched users (cached)", color=Color.blue()), + empty=False + ) @bigbrother_group.command(name='watch', aliases=('w',)) @with_role(Roles.owner, Roles.admin, Roles.moderator) -- cgit v1.2.3 From 0172818d123f9d884f1cd07207beb272da7f59e1 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:26:50 +0100 Subject: Adding improvements to the watch prefix so reasons don't get overwritten --- bot/cogs/bigbrother.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 36fd90ce9..919d2252f 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -40,6 +40,7 @@ class BigBrother: self.last_log = [None, None, 0] # [user_id, channel_id, message_count] self.consuming = False self.infraction_watch_prefix = "bb watch: " # Please do not change or we won't be able to find old reasons + self.nomination_prefix = "Nomination: " self.bot.loop.create_task(self.get_watched_users()) @@ -83,10 +84,10 @@ class BigBrother: else: return False - async def get_watch_information(self, user_id: int) -> WatchInformation: + async def get_watch_information(self, user_id: int, prefix: str) -> WatchInformation: """ Fetches and returns the latest watch reason for a user using the infraction API """ - re_bb_watch = rf"^{self.infraction_watch_prefix}" + re_bb_watch = rf"^{prefix}" user_id = str(user_id) try: @@ -114,7 +115,7 @@ class BigBrother: date = latest_reason_infraction["inserted_at"] # Get the latest reason without the prefix - latest_reason = latest_reason_infraction['reason'][len(self.infraction_watch_prefix):] + latest_reason = latest_reason_infraction['reason'][len(prefix):] log.trace(f"The latest bb watch reason for {user_id}: {latest_reason}") return WatchInformation(reason=latest_reason, actor_id=actor_id, inserted_at=date) @@ -214,7 +215,11 @@ class BigBrother: # Retrieve watch reason from API if it's not already in the cache if message.author.id not in self.watch_reasons: log.trace(f"No watch information for {message.author.id} found in cache; retrieving from API") - user_watch_information = await self.get_watch_information(message.author.id) + if destination == self.bot.get_channel(Channels.talent_pool): + prefix = self.nomination_prefix + else: + prefix = self.infraction_watch_prefix + user_watch_information = await self.get_watch_information(message.author.id, prefix) self.watch_reasons[message.author.id] = user_watch_information self.last_log = [message.author.id, message.channel.id, 0] @@ -297,7 +302,6 @@ class BigBrother: self.watched_users[user.id] = channel # Add a note (shadow warning) with the reason for watching - reason = f"{self.infraction_watch_prefix}{reason}" await post_infraction(ctx, user, type="warning", reason=reason, hidden=True) else: data = await response.json() @@ -346,8 +350,18 @@ class BigBrother: note (aka: shadow warning) """ + # Update cache to avoid double watching of a user + await self.update_watched_users() + + if user.id in self.watched_users: + message = f":x: User is already being watched in {self.watched_users[user.id].name}" + await ctx.send(message) + return + channel_id = Channels.big_brother_logs + reason = f"{self.infraction_watch_prefix}{reason}" + await self._watch_user(ctx, user, reason, channel_id) @bigbrother_group.command(name='unwatch', aliases=('uw',)) @@ -400,6 +414,21 @@ class BigBrother: channel_id = Channels.talent_pool + # Update watch cache to avoid overwriting active nomination reason + await self.update_watched_users() + + if user.id in self.watched_users: + if self.watched_users[user.id].id == Channels.talent_pool: + prefix = "Additional nomination: " + else: + # If the user is being watched in big-brother, don't add them to talent-pool + await ctx.send(f":x: Can't add {user.mention} to the talent-pool at this moment") + return + else: + prefix = self.nomination_prefix + + reason = f"{prefix}{reason}" + await self._watch_user(ctx, user, reason, channel_id) -- cgit v1.2.3 From 7fd83ab0176842886dabe9669c35d4401a68a910 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:36:15 +0100 Subject: Updating watched user embed title to include cache status --- bot/cogs/bigbrother.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 919d2252f..421f68ba7 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -328,6 +328,9 @@ class BigBrother: if not updated: await ctx.send(f":x: Failed to update cache: non-200 response from the API") return + title = "Watched users (updated cache)" + else: + title = "Watched users (from cache)" lines = tuple( f"• <@{user_id}> in <#{self.watched_users[user_id].id}>" @@ -336,7 +339,7 @@ class BigBrother: await LinePaginator.paginate( lines or ("There's nothing here yet.",), ctx, - Embed(title="Watched users (cached)", color=Color.blue()), + Embed(title=title, color=Color.blue()), empty=False ) -- cgit v1.2.3 From b7ab0ab8a2cf622cc44e879e219fcb168324712c Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 18:46:50 +0100 Subject: Adding watch time delta to big-brother header embed --- bot/cogs/bigbrother.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 421f68ba7..779660327 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -246,6 +246,13 @@ class BigBrother: # Adding nomination info to author_field author_field = f"{author_field} (nominated {time_delta} by {actor})" + else: + if inserted_at: + # Get time delta since insertion + date_time = parse_rfc1123(inserted_at).replace(tzinfo=None) + time_delta = time_since(date_time, precision="minutes", max_units=1) + + author_field = f"{author_field} (added {time_delta})" embed = Embed(description=f"{message.author.mention} in [#{message.channel.name}]({message.jump_url})") embed.set_author(name=author_field, icon_url=message.author.avatar_url) -- cgit v1.2.3 From be984bc93082f37ae5956f30e293bd2fa6273c48 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 8 Feb 2019 19:20:01 +0100 Subject: Adding current staff member check for nomination and updating prefix according to issue --- bot/cogs/bigbrother.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 779660327..e64a8ee6d 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -9,7 +9,10 @@ from aiohttp import ClientError from discord import Color, Embed, Guild, Member, Message, TextChannel, User from discord.ext.commands import Bot, Context, command, group -from bot.constants import BigBrother as BigBrotherConfig, Channels, Emojis, Guild as GuildConfig, Keys, Roles, URLs +from bot.constants import ( + BigBrother as BigBrotherConfig, Channels, Emojis, Guild as GuildConfig, + Keys, Roles, STAFF_ROLES, URLs, +) from bot.decorators import with_role from bot.pagination import LinePaginator from bot.utils import messages @@ -40,7 +43,7 @@ class BigBrother: self.last_log = [None, None, 0] # [user_id, channel_id, message_count] self.consuming = False self.infraction_watch_prefix = "bb watch: " # Please do not change or we won't be able to find old reasons - self.nomination_prefix = "Nomination: " + self.nomination_prefix = "Helper nomination: " self.bot.loop.create_task(self.get_watched_users()) @@ -422,6 +425,12 @@ class BigBrother: # !nominate command does not show up under "BigBrother" in the help embed, but under # the header HelperNomination for users with the helper role. + member = ctx.guild.get_member(user.id) + + if member and any(role.id in STAFF_ROLES for role in member.roles): + await ctx.send(f":x: {user.mention} is already a staff member!") + return + channel_id = Channels.talent_pool # Update watch cache to avoid overwriting active nomination reason -- cgit v1.2.3 From 9fa9bc922f5211a3af9b8d8e236e3b3ff022e520 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Sat, 9 Feb 2019 11:56:19 +0100 Subject: Changing negative bot response in nominate command to be more explicit about current bb-status of nominated user --- bot/cogs/bigbrother.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index e64a8ee6d..0dc55609e 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -441,7 +441,11 @@ class BigBrother: prefix = "Additional nomination: " else: # If the user is being watched in big-brother, don't add them to talent-pool - await ctx.send(f":x: Can't add {user.mention} to the talent-pool at this moment") + message = ( + f":x: {user.mention} can't be added to the talent-pool " + "as they are currently being watched in big-brother." + ) + await ctx.send(message) return else: prefix = self.nomination_prefix -- cgit v1.2.3 From 56327b624236e6befa8cbb1dbc2131f068f18831 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Fri, 22 Feb 2019 14:15:48 +0100 Subject: Clarifying log.trace message to include context Co-Authored-By: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> --- bot/cogs/bigbrother.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/bigbrother.py b/bot/cogs/bigbrother.py index 0dc55609e..6e95b2e33 100644 --- a/bot/cogs/bigbrother.py +++ b/bot/cogs/bigbrother.py @@ -82,7 +82,7 @@ class BigBrother: if response.status == 200: data = await response.json() self.update_cache(data) - log.trace("Updated watch list cache") + log.trace("Updated Big Brother watchlist cache") return True else: return False -- cgit v1.2.3 From 4ce2e4ec912ce7ef81b4cb840a878e80feedb8b5 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 22 Feb 2019 14:24:53 +0100 Subject: Adding square brackets to signal it's an argument, not a subcommand --- bot/cogs/alias.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py index bf59b6d15..313d66c95 100644 --- a/bot/cogs/alias.py +++ b/bot/cogs/alias.py @@ -74,7 +74,7 @@ class Alias: self, ctx: Context, user: User, *, reason: str ): """ - Alias for invoking bigbrother watch user reason. + Alias for invoking bigbrother watch user [reason]. """ await self.invoke(ctx, "bigbrother watch", user, reason=reason) @@ -82,7 +82,7 @@ class Alias: @command(name="unwatch", hidden=True) async def bigbrother_unwatch_alias(self, ctx, user: User, *, reason: str): """ - Alias for invoking bigbrother unwatch user reason. + Alias for invoking bigbrother unwatch user [reason]. """ await self.invoke(ctx, "bigbrother unwatch", user, reason=reason) @@ -106,7 +106,7 @@ class Alias: @command(name="reload", hidden=True) async def cogs_reload_alias(self, ctx, *, cog_name: str): """ - Alias for invoking cogs reload cog_name. + Alias for invoking cogs reload [cog_name]. cog_name: str - name of the cog to be reloaded. """ -- cgit v1.2.3 From 41439ffe7d0ad6d7eb88ef82632cb6322a009049 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Fri, 22 Feb 2019 14:35:51 +0100 Subject: Adding square brackets to user argument as well --- bot/cogs/alias.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py index 313d66c95..bf40fe409 100644 --- a/bot/cogs/alias.py +++ b/bot/cogs/alias.py @@ -74,7 +74,7 @@ class Alias: self, ctx: Context, user: User, *, reason: str ): """ - Alias for invoking bigbrother watch user [reason]. + Alias for invoking bigbrother watch [user] [reason]. """ await self.invoke(ctx, "bigbrother watch", user, reason=reason) @@ -82,7 +82,7 @@ class Alias: @command(name="unwatch", hidden=True) async def bigbrother_unwatch_alias(self, ctx, user: User, *, reason: str): """ - Alias for invoking bigbrother unwatch user [reason]. + Alias for invoking bigbrother unwatch [user] [reason]. """ await self.invoke(ctx, "bigbrother unwatch", user, reason=reason) -- cgit v1.2.3