mirror of
https://github.com/williamkray/maubot-kickbot.git
synced 2024-10-01 06:05:46 -04:00
improvements
- sync: purge mxids from tracking table if they are not in the master-room - config: allow configurable thresholds in days of inactivity
This commit is contained in:
parent
5095116775
commit
669fe5a5d8
@ -1,6 +1,12 @@
|
|||||||
# the room-id of the matrix room or space to use as your "full user list"
|
# the room-id of the matrix room or space to use as your "full user list"
|
||||||
master_room: "!somerandomcharacters:server.tld"
|
master_room: "!somerandomcharacters:server.tld"
|
||||||
|
|
||||||
|
# number of days of inactivity to be considered in the "warning zone"
|
||||||
|
warn_threshold_days: 30
|
||||||
|
|
||||||
|
# number of days of inactivity to be considered in the "danger zone"
|
||||||
|
kick_threshold_days: 60
|
||||||
|
|
||||||
# list of users who can add mxids to the exclusion list
|
# list of users who can add mxids to the exclusion list
|
||||||
admins:
|
admins:
|
||||||
- '@user1:server.tld'
|
- '@user1:server.tld'
|
||||||
|
@ -20,6 +20,8 @@ class Config(BaseProxyConfig):
|
|||||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||||
helper.copy("admins")
|
helper.copy("admins")
|
||||||
helper.copy("master_room")
|
helper.copy("master_room")
|
||||||
|
helper.copy("warn_threshold_days")
|
||||||
|
helper.copy("kick_threshold_days")
|
||||||
|
|
||||||
|
|
||||||
class KickBot(Plugin):
|
class KickBot(Plugin):
|
||||||
@ -52,6 +54,7 @@ class KickBot(Plugin):
|
|||||||
table_users = await self.database.fetch("SELECT mxid FROM user_events")
|
table_users = await self.database.fetch("SELECT mxid FROM user_events")
|
||||||
table_user_list = [ row["mxid"] for row in table_users ]
|
table_user_list = [ row["mxid"] for row in table_users ]
|
||||||
untracked_users = set(space_members_list) - set(table_user_list)
|
untracked_users = set(space_members_list) - set(table_user_list)
|
||||||
|
non_space_members = set(table_user_list) - set(space_members_list)
|
||||||
try:
|
try:
|
||||||
for user in untracked_users:
|
for user in untracked_users:
|
||||||
now = int(time.time() * 1000)
|
now = int(time.time() * 1000)
|
||||||
@ -61,6 +64,9 @@ class KickBot(Plugin):
|
|||||||
"""
|
"""
|
||||||
await self.database.execute(q, user, now)
|
await self.database.execute(q, user, now)
|
||||||
self.log.info(f"{user} inserted into activity tracking table")
|
self.log.info(f"{user} inserted into activity tracking table")
|
||||||
|
for user in non_space_members:
|
||||||
|
await self.database.execute("DELETE FROM user_events WHERE mxid = $1", user)
|
||||||
|
self.log.info(f"{user} is not a space member, dropped from activity tracking table")
|
||||||
await evt.react("✅")
|
await evt.react("✅")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.exception(e)
|
self.log.exception(e)
|
||||||
@ -101,23 +107,25 @@ class KickBot(Plugin):
|
|||||||
@activity.subcommand("snitch", help='generate a list of matrix IDs that have been inactive')
|
@activity.subcommand("snitch", help='generate a list of matrix IDs that have been inactive')
|
||||||
async def generate_report(self, evt: MessageEvent) -> None:
|
async def generate_report(self, evt: MessageEvent) -> None:
|
||||||
now = int(time.time() * 1000)
|
now = int(time.time() * 1000)
|
||||||
one_mo_ago = (now - 2592000000)
|
warn_days_ago = (now - (1000 * 60 * 60 * 24 * self.config["warn_threshold_days"]))
|
||||||
two_mo_ago = (now - 5184000000)
|
kick_days_ago = (now - (1000 * 60 * 60 * 24 * self.config["kick_threshold_days"]))
|
||||||
one_mo_q = """
|
warn_q = """
|
||||||
SELECT mxid FROM user_events WHERE last_message_timestamp <= $1 AND
|
SELECT mxid FROM user_events WHERE last_message_timestamp <= $1 AND
|
||||||
last_message_timestamp >= $2
|
last_message_timestamp >= $2
|
||||||
AND ignore_inactivity = 0
|
AND ignore_inactivity = 0
|
||||||
"""
|
"""
|
||||||
two_mo_q = """
|
kick_q = """
|
||||||
SELECT mxid FROM user_events WHERE last_message_timestamp <= $1
|
SELECT mxid FROM user_events WHERE last_message_timestamp <= $1
|
||||||
AND ignore_inactivity = 0
|
AND ignore_inactivity = 0
|
||||||
"""
|
"""
|
||||||
one_mo_inactive_results = await self.database.fetch(one_mo_q, one_mo_ago, two_mo_ago)
|
warn_inactive_results = await self.database.fetch(warn_q, warn_days_ago, kick_days_ago)
|
||||||
two_mo_inactive_results = await self.database.fetch(two_mo_q, two_mo_ago)
|
kick_inactive_results = await self.database.fetch(kick_q, kick_days_ago)
|
||||||
one_mo_inactive = [ row["mxid"] for row in one_mo_inactive_results ] or ["none"]
|
warn_inactive = [ row["mxid"] for row in warn_inactive_results ] or ["none"]
|
||||||
two_mo_inactive = [ row["mxid"] for row in two_mo_inactive_results ] or ["none"]
|
kick_inactive = [ row["mxid"] for row in kick_inactive_results ] or ["none"]
|
||||||
await evt.respond(f"<b>Users inactive for one month:</b> {', '.join(one_mo_inactive)} <br>\
|
await evt.respond(f"<b>Users inactive for {self.config['warn_threshold_days']} days:</b> \
|
||||||
<b>Users inactive for two months:</b> {', '.join(two_mo_inactive)}", \
|
{', '.join(warn_inactive)} <br>\
|
||||||
|
<b>Users inactive for {self.config['kick_threshold_days']} days:</b> \
|
||||||
|
{', '.join(kick_inactive)}", \
|
||||||
allow_html=True)
|
allow_html=True)
|
||||||
|
|
||||||
#need to somehow regularly fetch and update the list of room ids that are associated with a given space
|
#need to somehow regularly fetch and update the list of room ids that are associated with a given space
|
||||||
|
Loading…
Reference in New Issue
Block a user