From a2327b32f6207c1a10db1758470171ee19531fa8 Mon Sep 17 00:00:00 2001 From: Myned Date: Tue, 16 Aug 2022 13:57:50 -0500 Subject: [PATCH] Add comments --- commands/info.py | 6 +++++- tasks/activity.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/commands/info.py b/commands/info.py index 31b6601..b3d9304 100644 --- a/commands/info.py +++ b/commands/info.py @@ -9,17 +9,19 @@ from tools import components plugin = lightbulb.Plugin("info", default_enabled_guilds=c.config["guild"]) -# Get list of inactive members +# Get list of members not in activity database @plugin.command @lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD)) @lightbulb.command("limbo", "List members not in activity database", ephemeral=True) @lightbulb.implements(lightbulb.SlashCommand) async def limbo(context): + # Embed builder def build(index, content): return hikari.Embed( title="Limbo", description=content, color=context.get_guild().get_my_member().get_top_role().color ).set_footer(f"{len(limbo)} members") + # Get, sort, and filter list of members if not a bot, without excluded role, and not in db limbo = { snowflake: member for snowflake, member in sorted( @@ -30,12 +32,14 @@ async def limbo(context): and snowflake not in c.db } + # Build paginator paginator = lightbulb.utils.EmbedPaginator() paginator.set_embed_factory(build) for snowflake, member in limbo.items(): paginator.add_line(f"{member.mention} {snowflake}") pages = [page for page in paginator.build_pages()] + # Send paginator if len(pages) > 1: navigator = nav.NavigatorView( pages=pages, diff --git a/tasks/activity.py b/tasks/activity.py index cc9ce87..54f6fcc 100644 --- a/tasks/activity.py +++ b/tasks/activity.py @@ -15,14 +15,17 @@ async def check_activity(): for author_id, timestamp in c.db.items(): if dt.datetime.now(dt.timezone.utc) - timestamp >= dt.timedelta(seconds=c.config["duration"]): try: + # Acquire member object member = plugin.bot.cache.get_member( c.config["guild"], author_id ) or await plugin.bot.rest.fetch_member(c.config["guild"], author_id) + # Enforce activity roles if c.config["active"] and c.config["active"] in member.role_ids: await member.remove_role(c.config["active"]) if c.config["inactive"] and c.config["inactive"] not in member.role_ids: await member.add_role(c.config["inactive"]) + # Delete member from db if not found except hikari.NotFoundError: del c.db[author_id] @@ -36,11 +39,14 @@ async def on_ready(event): # Listener for guild messages @plugin.listener(hikari.GuildMessageCreateEvent) async def on_message(event): + # Exclude bots, unselected guild, and excluded role if event.is_bot or event.guild_id != c.config["guild"] or c.config["exclude"] in event.member.role_ids: return + # Insert current timestamp into db c.db[event.author_id] = dt.datetime.now(dt.timezone.utc) # or event.message.timestamp + # Toggle activity roles if c.config["active"] and c.config["active"] not in event.member.role_ids: await event.member.add_role(c.config["active"]) if c.config["inactive"] and c.config["inactive"] in event.member.role_ids: @@ -50,6 +56,7 @@ async def on_message(event): # Listener for voice state @plugin.listener(hikari.VoiceStateUpdateEvent) async def on_voice(event): + # Exclude bots, unselected guild, and excluded role if ( event.state.member.is_bot or event.guild_id != c.config["guild"] @@ -57,8 +64,10 @@ async def on_voice(event): ): return - c.db[event.state.user_id] = dt.datetime.now(dt.timezone.utc) + # Insert current timestamp into db + c.db[event.state.user_id] = dt.datetime.now(dt.timezone.utc) # or event.message.timestamp + # Toggle activity roles if c.config["active"] and c.config["active"] not in event.state.member.role_ids: await event.state.member.add_role(c.config["active"]) if c.config["inactive"] and c.config["inactive"] in event.state.member.role_ids: