mirror of
https://github.com/myned/watcher.git
synced 2024-11-01 12:22:38 +00:00
Add inactive command
This commit is contained in:
parent
52c26b34a3
commit
38d184f38b
6 changed files with 73 additions and 6 deletions
53
commands/info.py
Normal file
53
commands/info.py
Normal 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)
|
|
@ -1,4 +1,5 @@
|
||||||
import toml
|
import toml
|
||||||
|
import sqlitedict
|
||||||
import hikari
|
import hikari
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,3 +27,5 @@ except FileNotFoundError:
|
||||||
f.write(CONFIG)
|
f.write(CONFIG)
|
||||||
print("config.toml created with default values. Restart when modified")
|
print("config.toml created with default values. Restart when modified")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
db = sqlitedict.SqliteDict(config["db"], tablename=str(config["guild"]), autocommit=True)
|
||||||
|
|
|
@ -12,6 +12,7 @@ uvloop = "*"
|
||||||
sqlitedict = "*"
|
sqlitedict = "*"
|
||||||
hikari = {extras = ["speedups"], version = "*"}
|
hikari = {extras = ["speedups"], version = "*"}
|
||||||
hikari-lightbulb = "*"
|
hikari-lightbulb = "*"
|
||||||
|
hikari-miru = "*"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
black = "*"
|
black = "*"
|
||||||
|
|
2
run.py
2
run.py
|
@ -28,5 +28,5 @@ async def on_error(event):
|
||||||
|
|
||||||
|
|
||||||
tasks.load(bot)
|
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)
|
bot.run(activity=hikari.Activity(name=c.config["activity"], type=c.ACTIVITY) if c.config["activity"] else None)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import sqlitedict
|
|
||||||
import hikari
|
import hikari
|
||||||
import lightbulb
|
import lightbulb
|
||||||
from lightbulb.ext import tasks
|
from lightbulb.ext import tasks
|
||||||
|
@ -8,13 +7,12 @@ import config as c
|
||||||
|
|
||||||
|
|
||||||
plugin = lightbulb.Plugin("activity")
|
plugin = lightbulb.Plugin("activity")
|
||||||
db = sqlitedict.SqliteDict(c.config["db"], tablename=str(c.config["guild"]), autocommit=True)
|
|
||||||
|
|
||||||
|
|
||||||
# Check every minute if inactive
|
# Check every minute if inactive
|
||||||
@tasks.task(s=60)
|
@tasks.task(s=60)
|
||||||
async def check_activity():
|
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"]):
|
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(
|
member = plugin.bot.cache.get_member(c.config["guild"], author_id) or await plugin.bot.rest.fetch_member(
|
||||||
c.config["guild"], author_id
|
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:
|
if event.is_bot or event.guild_id != c.config["guild"] or c.config["exclude"] in event.member.role_ids:
|
||||||
return
|
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:
|
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"])
|
||||||
|
@ -56,7 +54,7 @@ async def on_voice(event):
|
||||||
):
|
):
|
||||||
return
|
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:
|
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"])
|
||||||
|
|
12
tools/components.py
Normal file
12
tools/components.py
Normal 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)
|
Loading…
Reference in a new issue