aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris <[email protected]>2021-04-19 18:08:39 +0100
committerGravatar Chris <[email protected]>2021-04-19 18:08:39 +0100
commit90ed28f4cb31b5b41f7a395abfe61f4f9e49e091 (patch)
tree63a496603867bf4b69cdff7613d770a7b8038b3d
parentRequire a mod role for stream commands (diff)
Add command to list users with streaming perms
This is useful to audit users who still have the permission to stream. I have chosen to also sort and paginate the embed to make it easier to read. The sorting is based on how long until the user's streaming permissions are revoked, with permanent streamers at the end.
-rw-r--r--bot/exts/moderation/stream.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/bot/exts/moderation/stream.py b/bot/exts/moderation/stream.py
index 7ea7f635b..5f3820748 100644
--- a/bot/exts/moderation/stream.py
+++ b/bot/exts/moderation/stream.py
@@ -1,5 +1,6 @@
import logging
from datetime import timedelta, timezone
+from operator import itemgetter
import arrow
import discord
@@ -8,8 +9,9 @@ from async_rediscache import RedisCache
from discord.ext import commands
from bot.bot import Bot
-from bot.constants import Colours, Emojis, Guild, MODERATION_ROLES, Roles, VideoPermission
+from bot.constants import Colours, Emojis, Guild, MODERATION_ROLES, Roles, STAFF_ROLES, VideoPermission
from bot.converters import Expiry
+from bot.pagination import LinePaginator
from bot.utils.scheduling import Scheduler
from bot.utils.time import format_infraction_with_duration
@@ -173,6 +175,46 @@ class Stream(commands.Cog):
await ctx.send(f"{Emojis.cross_mark} This member doesn't have video permissions to remove!")
log.debug(f"{member} ({member.id}) didn't have the streaming permission to remove!")
+ @commands.command(aliases=('lstream',))
+ @commands.has_any_role(*MODERATION_ROLES)
+ async def liststream(self, ctx: commands.Context) -> None:
+ """Lists all non-staff users who have permission to stream."""
+ non_staff_members_with_stream = [
+ _member
+ for _member in ctx.guild.get_role(Roles.video).members
+ if not any(role.id in STAFF_ROLES for role in _member.roles)
+ ]
+
+ # List of tuples (UtcPosixTimestamp, str)
+ # This is so that we can sort before outputting to the paginator
+ streamer_info = []
+ for member in non_staff_members_with_stream:
+ if revoke_time := await self.task_cache.get(member.id):
+ # Member only has temporary streaming perms
+ revoke_delta = Arrow.utcfromtimestamp(revoke_time).humanize()
+ message = f"{member.mention} will have stream permissions revoked {revoke_delta}."
+ else:
+ message = f"{member.mention} has permanent streaming permissions."
+
+ # If revoke_time is None use max timestamp to force sort to put them at the end
+ streamer_info.append(
+ (revoke_time or Arrow.max.timestamp(), message)
+ )
+
+ if streamer_info:
+ # Sort based on duration left of streaming perms
+ streamer_info.sort(key=itemgetter(0))
+
+ # Only output the message in the pagination
+ lines = [line[1] for line in streamer_info]
+ embed = discord.Embed(
+ title=f"Members who can stream (`{len(lines)}` total)",
+ colour=Colours.soft_green
+ )
+ await LinePaginator.paginate(lines, ctx, embed, max_size=400, empty=False)
+ else:
+ await ctx.send("No members with stream permissions found.")
+
def setup(bot: Bot) -> None:
"""Loads the Stream cog."""