mirror of
https://github.com/myned/watcher.git
synced 2024-12-24 21:17:28 +00:00
Add comments
This commit is contained in:
parent
38ab9e39d7
commit
a2327b32f6
2 changed files with 15 additions and 2 deletions
|
@ -9,17 +9,19 @@ from tools import components
|
||||||
plugin = lightbulb.Plugin("info", default_enabled_guilds=c.config["guild"])
|
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
|
@plugin.command
|
||||||
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
|
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
|
||||||
@lightbulb.command("limbo", "List members not in activity database", ephemeral=True)
|
@lightbulb.command("limbo", "List members not in activity database", ephemeral=True)
|
||||||
@lightbulb.implements(lightbulb.SlashCommand)
|
@lightbulb.implements(lightbulb.SlashCommand)
|
||||||
async def limbo(context):
|
async def limbo(context):
|
||||||
|
# Embed builder
|
||||||
def build(index, content):
|
def build(index, content):
|
||||||
return hikari.Embed(
|
return hikari.Embed(
|
||||||
title="Limbo", description=content, color=context.get_guild().get_my_member().get_top_role().color
|
title="Limbo", description=content, color=context.get_guild().get_my_member().get_top_role().color
|
||||||
).set_footer(f"{len(limbo)} members")
|
).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 = {
|
limbo = {
|
||||||
snowflake: member
|
snowflake: member
|
||||||
for snowflake, member in sorted(
|
for snowflake, member in sorted(
|
||||||
|
@ -30,12 +32,14 @@ async def limbo(context):
|
||||||
and snowflake not in c.db
|
and snowflake not in c.db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Build paginator
|
||||||
paginator = lightbulb.utils.EmbedPaginator()
|
paginator = lightbulb.utils.EmbedPaginator()
|
||||||
paginator.set_embed_factory(build)
|
paginator.set_embed_factory(build)
|
||||||
for snowflake, member in limbo.items():
|
for snowflake, member in limbo.items():
|
||||||
paginator.add_line(f"{member.mention} {snowflake}")
|
paginator.add_line(f"{member.mention} {snowflake}")
|
||||||
pages = [page for page in paginator.build_pages()]
|
pages = [page for page in paginator.build_pages()]
|
||||||
|
|
||||||
|
# Send paginator
|
||||||
if len(pages) > 1:
|
if len(pages) > 1:
|
||||||
navigator = nav.NavigatorView(
|
navigator = nav.NavigatorView(
|
||||||
pages=pages,
|
pages=pages,
|
||||||
|
|
|
@ -15,14 +15,17 @@ async def check_activity():
|
||||||
for author_id, timestamp in c.db.items():
|
for author_id, timestamp in c.db.items():
|
||||||
if dt.datetime.now(dt.timezone.utc) - timestamp >= dt.timedelta(seconds=c.config["duration"]):
|
if dt.datetime.now(dt.timezone.utc) - timestamp >= dt.timedelta(seconds=c.config["duration"]):
|
||||||
try:
|
try:
|
||||||
|
# Acquire member object
|
||||||
member = plugin.bot.cache.get_member(
|
member = plugin.bot.cache.get_member(
|
||||||
c.config["guild"], author_id
|
c.config["guild"], author_id
|
||||||
) or await plugin.bot.rest.fetch_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:
|
if c.config["active"] and c.config["active"] in member.role_ids:
|
||||||
await member.remove_role(c.config["active"])
|
await member.remove_role(c.config["active"])
|
||||||
if c.config["inactive"] and c.config["inactive"] not in member.role_ids:
|
if c.config["inactive"] and c.config["inactive"] not in member.role_ids:
|
||||||
await member.add_role(c.config["inactive"])
|
await member.add_role(c.config["inactive"])
|
||||||
|
# Delete member from db if not found
|
||||||
except hikari.NotFoundError:
|
except hikari.NotFoundError:
|
||||||
del c.db[author_id]
|
del c.db[author_id]
|
||||||
|
|
||||||
|
@ -36,11 +39,14 @@ async def on_ready(event):
|
||||||
# Listener for guild messages
|
# Listener for guild messages
|
||||||
@plugin.listener(hikari.GuildMessageCreateEvent)
|
@plugin.listener(hikari.GuildMessageCreateEvent)
|
||||||
async def on_message(event):
|
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:
|
if event.is_bot or event.guild_id != c.config["guild"] or c.config["exclude"] in event.member.role_ids:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Insert current timestamp into db
|
||||||
c.db[event.author_id] = dt.datetime.now(dt.timezone.utc) # or event.message.timestamp
|
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:
|
if c.config["active"] and c.config["active"] not in event.member.role_ids:
|
||||||
await event.member.add_role(c.config["active"])
|
await event.member.add_role(c.config["active"])
|
||||||
if c.config["inactive"] and c.config["inactive"] in event.member.role_ids:
|
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
|
# Listener for voice state
|
||||||
@plugin.listener(hikari.VoiceStateUpdateEvent)
|
@plugin.listener(hikari.VoiceStateUpdateEvent)
|
||||||
async def on_voice(event):
|
async def on_voice(event):
|
||||||
|
# Exclude bots, unselected guild, and excluded role
|
||||||
if (
|
if (
|
||||||
event.state.member.is_bot
|
event.state.member.is_bot
|
||||||
or event.guild_id != c.config["guild"]
|
or event.guild_id != c.config["guild"]
|
||||||
|
@ -57,8 +64,10 @@ async def on_voice(event):
|
||||||
):
|
):
|
||||||
return
|
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:
|
if c.config["active"] and c.config["active"] not in event.state.member.role_ids:
|
||||||
await event.state.member.add_role(c.config["active"])
|
await event.state.member.add_role(c.config["active"])
|
||||||
if c.config["inactive"] and c.config["inactive"] in event.state.member.role_ids:
|
if c.config["inactive"] and c.config["inactive"] in event.state.member.role_ids:
|
||||||
|
|
Loading…
Reference in a new issue