Implement staff notifications when particular users are active on the server.
Requirements:
ON_MESSAGE
event listener that compares the author to that of the elements in a configurable list of guild membersNice to have: Ability to set and compare the message volume to a configurable threshold of n messages over an interval within a single channel.
Use case: Staff may place a user on probation, or otherwise want to monitor them for conduct concerns. This would make it easier for moderators to fulfill their responsibilities in a timely manner, as it can often be difficult to keep up with the flow of chats.
Draft of change committed to
feature/user-watch
@ ee2cf0f2. Still requires testing. Requested review from ~luma_inhibitor
Started on testing. See this commit.
comments from eli:
if i add myself to the watch list and then make a post, it causes this error
File "/home/eli/code/cabling-bot/cabling_bot/events/message_watch_user.py", line 203, in handle_message watched, last_active = self._get(msg.guild.id, msg.author.id) TypeError: cannot unpack non-iterable int object
the error disappears if i do bot reload and post again, though
i also added a logger statement to self._get() and it isn't showing, so i'm pretty sure the error is actually occurring in the previous line, which has this
is_cached = self._get.has(msg.guild.id, msg.author.id)
steps to reproduce:
- watch list to verify you aren't already watched; if you are, remove yourself
- restart bot (clean cache)
- watch add
- make a post -- this will trigger the exception in the log -- bot won't send the watch message
- bot reload
- make a post -- no exception this time -- bot will send the watch message
there's also still the matter of not having permission gating on use of the commands that needs addressed.
Committed a bit of a change to catch the failure case of there being no watched user when
_get
is called. Also tried to fix the list deconstruction in the message handler, unsuccessfully.When calling
.watch list
, this is returned:File "/usr/src/cables/cabling_bot/events/message_watch_user.py", line 212, in handle_message next_report = last_active + int(60 * 5) TypeError: can only concatenate list (not "int") to list ... File "/usr/src/cables/cabling_bot/events/message_watch_user.py", line 206, in handle_message watched, *last_active = self._get(msg.guild.id, msg.author.id) TypeError: cannot unpack non-iterable bool object
Which implies that the cursor is returning a result, but the method is returning false as if it didn't. This leads to
last_active
being an empty list, and the activity time comparison throwing the first exception. Also, the second exception implies that the list deconstruction is incorrect for what I'm trying to do.I suppose a potential workaround here is to store the last active time in the DB, but that'd increase DB calls on message events, which I think is undesirable, even though it would be limited to every 5 minutes per active user.