1
0
Fork 0
mirror of https://github.com/myned/watcher.git synced 2024-11-01 12:22:38 +00:00
watcher/commands/info.py

62 lines
1.9 KiB
Python
Raw Normal View History

2022-07-05 22:19:59 +00:00
import hikari
import lightbulb
from miru.ext import nav
import config as c
from tools import components
plugin = lightbulb.Plugin("info", default_enabled_guilds=c.config["guild"])
2022-08-16 18:57:50 +00:00
# Get list of members not in activity database
2022-07-05 22:19:59 +00:00
@plugin.command
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
@lightbulb.command("limbo", "List members not in activity database", ephemeral=True)
2022-07-05 22:19:59 +00:00
@lightbulb.implements(lightbulb.SlashCommand)
async def limbo(context):
2022-08-16 18:57:50 +00:00
# Embed builder
2022-07-05 22:19:59 +00:00
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")
2022-07-05 22:19:59 +00:00
2022-08-16 18:57:50 +00:00
# Get, sort, and filter list of members if not a bot, without excluded role, and not in db
limbo = {
2022-07-05 22:19:59 +00:00
snowflake: member
for snowflake, member in sorted(
context.get_guild().get_members().items(), key=lambda item: item[1].display_name
)
if not member.is_bot
and c.config["exclude"] not in [role.id for role in member.get_roles()]
and snowflake not in c.db
2022-07-05 22:19:59 +00:00
}
2022-08-16 18:57:50 +00:00
# Build paginator
2022-07-05 22:19:59 +00:00
paginator = lightbulb.utils.EmbedPaginator()
paginator.set_embed_factory(build)
for snowflake, member in limbo.items():
2022-07-05 22:19:59 +00:00
paginator.add_line(f"{member.mention} {snowflake}")
pages = [page for page in paginator.build_pages()]
2022-08-16 18:57:50 +00:00
# Send paginator
2022-07-05 22:19:59 +00:00
if len(pages) > 1:
navigator = nav.NavigatorView(
pages=pages,
buttons=[components.Back(), components.Forward()],
timeout=600,
)
await navigator.send(context.interaction, ephemeral=True)
2023-01-04 17:47:05 +00:00
elif pages:
2022-07-05 22:19:59 +00:00
await context.respond(pages[0])
2023-01-04 17:47:05 +00:00
else:
await context.respond("***All members accounted for***")
2022-07-05 22:19:59 +00:00
def load(bot):
bot.add_plugin(plugin)
def unload(bot):
bot.remove_plugin(plugin)