1
0
Fork 0
mirror of https://github.com/myned/watcher.git synced 2024-12-23 12:57:28 +00:00

Add inactive command

This commit is contained in:
Myned 2022-07-05 17:19:59 -05:00
parent 52c26b34a3
commit 38d184f38b
No known key found for this signature in database
GPG key ID: 33790F979F7A28B8
6 changed files with 73 additions and 6 deletions

53
commands/info.py Normal file
View file

@ -0,0 +1,53 @@
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"])
# Get list of inactive members
@plugin.command
@lightbulb.add_checks(lightbulb.has_guild_permissions(hikari.Permissions.MANAGE_GUILD))
@lightbulb.command("inactive", "List inactive members", ephemeral=True)
@lightbulb.implements(lightbulb.SlashCommand)
async def inactive(context):
def build(index, content):
return hikari.Embed(
title="Inactive", description=content, color=context.get_guild().get_my_member().get_top_role().color
).set_footer(f"{len(inactive)} members")
inactive = {
snowflake: member
for snowflake, member in sorted(
context.get_guild().get_members().items(), key=lambda item: item[1].display_name
)
if snowflake not in c.db
}
paginator = lightbulb.utils.EmbedPaginator()
paginator.set_embed_factory(build)
for snowflake, member in inactive.items():
paginator.add_line(f"{member.mention} {snowflake}")
pages = [page for page in paginator.build_pages()]
if len(pages) > 1:
navigator = nav.NavigatorView(
pages=pages,
buttons=[components.Back(), components.Forward()],
timeout=600,
)
await navigator.send(context.interaction, ephemeral=True)
else:
await context.respond(pages[0])
def load(bot):
bot.add_plugin(plugin)
def unload(bot):
bot.remove_plugin(plugin)

View file

@ -1,4 +1,5 @@
import toml
import sqlitedict
import hikari
@ -26,3 +27,5 @@ except FileNotFoundError:
f.write(CONFIG)
print("config.toml created with default values. Restart when modified")
exit()
db = sqlitedict.SqliteDict(config["db"], tablename=str(config["guild"]), autocommit=True)

View file

@ -12,6 +12,7 @@ uvloop = "*"
sqlitedict = "*"
hikari = {extras = ["speedups"], version = "*"}
hikari-lightbulb = "*"
hikari-miru = "*"
[tool.poetry.dev-dependencies]
black = "*"

2
run.py
View file

@ -28,5 +28,5 @@ async def on_error(event):
tasks.load(bot)
bot.load_extensions_from("tasks")
bot.load_extensions_from("commands", "tasks")
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)

View file

@ -1,5 +1,4 @@
import datetime as dt
import sqlitedict
import hikari
import lightbulb
from lightbulb.ext import tasks
@ -8,13 +7,12 @@ import config as c
plugin = lightbulb.Plugin("activity")
db = sqlitedict.SqliteDict(c.config["db"], tablename=str(c.config["guild"]), autocommit=True)
# Check every minute if inactive
@tasks.task(s=60)
async def check_activity():
for author_id, timestamp in db.items():
for author_id, timestamp in c.db.items():
if dt.datetime.now(dt.timezone.utc) - timestamp >= dt.timedelta(seconds=c.config["duration"]):
member = plugin.bot.cache.get_member(c.config["guild"], author_id) or await plugin.bot.rest.fetch_member(
c.config["guild"], author_id
@ -38,7 +36,7 @@ async def on_message(event):
if event.is_bot or event.guild_id != c.config["guild"] or c.config["exclude"] in event.member.role_ids:
return
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
if c.config["active"] and c.config["active"] not in event.member.role_ids:
await event.member.add_role(c.config["active"])
@ -56,7 +54,7 @@ async def on_voice(event):
):
return
db[event.state.user_id] = dt.datetime.now(dt.timezone.utc)
c.db[event.state.user_id] = dt.datetime.now(dt.timezone.utc)
if c.config["active"] and c.config["active"] not in event.state.member.role_ids:
await event.state.member.add_role(c.config["active"])

12
tools/components.py Normal file
View file

@ -0,0 +1,12 @@
import hikari
from miru.ext import nav
class Back(nav.PrevButton):
def __init__(self):
super().__init__(style=hikari.ButtonStyle.SECONDARY, label="", emoji=None)
class Forward(nav.NextButton):
def __init__(self):
super().__init__(style=hikari.ButtonStyle.SECONDARY, label="", emoji=None)