ability to disable tracking altogether, small comment changes

This commit is contained in:
William Kray
2024-10-04 09:26:38 -07:00
parent 914a0f4fd4
commit ce830e29e8
3 changed files with 39 additions and 14 deletions
+4
View File
@@ -10,6 +10,8 @@ warn_threshold_days: 30
# number of days of inactivity to be considered in the "danger zone"
kick_threshold_days: 60
# track users? if false, will disable all tracking and avoid writing anything to the database.
track_users: True
# track messages? if false, will not track user activity timestamps. enable if you'd like to track
# inactive users in your community
@@ -39,6 +41,7 @@ invitees:
# you can use {user} to reference the joining user in this message using a
# matrix.to link (rendered as a "pill" in element clients)
# html formatting is supported
# set to {} if you don't care about greetings
greetings:
generic: |
Welcome {user}! Please be sure to read the topic for helpful links and information.
@@ -50,6 +53,7 @@ greetings:
# which of the above greetings should be used in which rooms? use the exact name of each greeting
# you've assigned, e.g. 'generic' or 'encrypted'. you must use the room ID here.
# enter 'none' to avoid sending a message, but still be notified in the notification_room listed below.
# set to {} if you don't care about greetings or join notifications
greeting_rooms:
'!someroomid:server.tld': generic
'!someotherroom:server.tld': generic
+34 -13
View File
@@ -24,6 +24,7 @@ class Config(BaseProxyConfig):
helper.copy("admins")
helper.copy("moderators")
helper.copy("parent_room")
helper.copy("track_users")
helper.copy("track_messages")
helper.copy("track_reactions")
helper.copy("warn_threshold_days")
@@ -48,6 +49,9 @@ class CommunityBot(Plugin):
async def do_sync(self) -> None:
if not self.config["track_users"]:
return "user tracking is disabled"
space_members_obj = await self.client.get_joined_members(self.config["parent_room"])
space_members_list = space_members_obj.keys()
table_users = await self.database.fetch("SELECT mxid FROM user_events")
@@ -181,7 +185,7 @@ class CommunityBot(Plugin):
except Exception as e:
self.log.error(f"Flagged message could not be redacted: {e}")
if not self.config["track_messages"]:
if not self.config["track_messages"] or not self.config["track_users"]:
pass
else:
q = """
@@ -194,7 +198,7 @@ class CommunityBot(Plugin):
@event.on(EventType.REACTION)
async def update_reaction_timestamp(self, evt: MessageEvent) -> None:
if not self.config["track_reactions"]:
if not self.config["track_reactions"] or not self.config["track_users"]:
pass
else:
q = """
@@ -205,7 +209,7 @@ class CommunityBot(Plugin):
"""
await self.database.execute(q, evt.sender, evt.timestamp)
@command.new("community", help="track active/inactive status of members of a space")
@command.new("community", help="manage rooms and members of a space")
async def community(self) -> None:
pass
@@ -214,6 +218,10 @@ class CommunityBot(Plugin):
in case they are missing")
async def sync_space_members(self, evt: MessageEvent) -> None:
if evt.sender in self.config["admins"]:
if not self.config["track_users"]:
await evt.respond("user tracking is disabled")
return
results = await self.do_sync()
added_str = "<br />".join(results['added'])
@@ -227,6 +235,10 @@ class CommunityBot(Plugin):
@command.argument("mxid", "full matrix ID", required=True)
async def ignore_inactivity(self, evt: MessageEvent, mxid: UserID) -> None:
if evt.sender in self.config["admins"]:
if not self.config["track_users"]:
await evt.reply("user tracking is disabled")
return
try:
Client.parse_user_id(mxid)
await self.database.execute("UPDATE user_events SET ignore_inactivity = 1 WHERE \
@@ -242,6 +254,10 @@ class CommunityBot(Plugin):
@command.argument("mxid", "full matrix ID", required=True)
async def unignore_inactivity(self, evt: MessageEvent, mxid: UserID) -> None:
if evt.sender in self.config["admins"]:
if not self.config["track_users"]:
await evt.reply("user tracking is disabled")
return
try:
Client.parse_user_id(mxid)
await self.database.execute("UPDATE user_events SET ignore_inactivity = 0 WHERE \
@@ -255,16 +271,21 @@ class CommunityBot(Plugin):
@community.subcommand("report", help='generate a list of matrix IDs that have been inactive')
async def get_report(self, evt: MessageEvent) -> None:
sync_results = await self.do_sync()
report = await self.generate_report()
await evt.respond(f"<b>Users inactive for between {self.config['warn_threshold_days']} and \
{self.config['kick_threshold_days']} days:</b><br /> \
{'<br />'.join(report['warn_inactive'])} <br />\
<b>Users inactive for at least {self.config['kick_threshold_days']} days:</b><br /> \
{'<br />'.join(report['kick_inactive'])} <br /> \
<b>Ignored users:</b><br /> \
{'<br />'.join(report['ignored'])}", \
allow_html=True)
if evt.sender in self.config["admins"]:
if not self.config["track_users"]:
await evt.reply("user tracking is disabled")
return
sync_results = await self.do_sync()
report = await self.generate_report()
await evt.respond(f"<b>Users inactive for between {self.config['warn_threshold_days']} and \
{self.config['kick_threshold_days']} days:</b><br /> \
{'<br />'.join(report['warn_inactive'])} <br />\
<b>Users inactive for at least {self.config['kick_threshold_days']} days:</b><br /> \
{'<br />'.join(report['kick_inactive'])} <br /> \
<b>Ignored users:</b><br /> \
{'<br />'.join(report['ignored'])}", \
allow_html=True)
@community.subcommand("purge", help='kick users for excessive inactivity')
+1 -1
View File
@@ -1,6 +1,6 @@
maubot: 0.1.0
id: org.jobmachine.communitybot
version: 0.1.7
version: 0.1.8
license: MIT
modules:
- community