include option to track reaction events

This commit is contained in:
William Kray 2022-06-21 07:33:36 -07:00
parent 9e767eebff
commit 9a12dec6eb
2 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,10 @@ warn_threshold_days: 30
# number of days of inactivity to be considered in the "danger zone"
kick_threshold_days: 60
# track reactions? if false, will only track activity based on normal message events, but if true
# will update the user's last-active date when they add a reaction to a message
track_reactions: True
# list of users who can add mxids to the exclusion list
admins:
- '@user1:server.tld'

View File

@ -20,6 +20,7 @@ class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("admins")
helper.copy("master_room")
helper.copy("track_reactions")
helper.copy("warn_threshold_days")
helper.copy("kick_threshold_days")
@ -31,13 +32,24 @@ class KickBot(Plugin):
self.config.load_and_update()
@event.on(EventType.ROOM_MESSAGE)
async def update_user_timestamp(self, evt: MessageEvent) -> None:
async def update_message_timestamp(self, evt: MessageEvent) -> None:
q = """
REPLACE INTO user_events(mxid, last_message_timestamp)
VALUES ($1, $2)
"""
await self.database.execute(q, evt.sender, evt.timestamp)
@event.on(EventType.REACTION)
async def update_reaction_timestamp(self, evt: MessageEvent) -> None:
if not self.config["track_reactions"]:
pass
else:
q = """
REPLACE INTO user_events(mxid, last_message_timestamp)
VALUES ($1, $2)
"""
await self.database.execute(q, evt.sender, evt.timestamp)
@command.new("activity", help="track active/inactive status of members of a space")
async def activity(self) -> None:
pass