Add anti AFK component - #177
Conversation
3369978 to
5bc3e9e
Compare
jeremy-rifkin
left a comment
There was a problem hiding this comment.
A couple quick comments, thanks for taking the time to do this
| import { BotComponent } from "../bot-component.js"; | ||
|
|
||
| export default class AntiAFK extends BotComponent { | ||
| private countdown = new Map<string, NodeJS.Timeout>(); |
There was a problem hiding this comment.
In general I try to use self clearing containers for this sort of thing. If the bot loses connection or otherwise misses events some assumptions (like getting a on_voice_state_update call when a user disconnects) can be broken and lead to issues. It seems like storing timeouts like this can work but it makes me a little bit uneasy. I'm wondering whether there might be better ways of doing this. One option might be to use SleepList, possibly modifying it to better fit the use-case here.
There was a problem hiding this comment.
Yeah I considered using a self-clearing container. The thing is though that this would then require us to periodically check the container. Just setting a timeout seems like a simpler and more natural approach. And if anything goes wrong, the timeout will fire regardless, and remove the entry from the Set. So there should be no issue with accumulating entries. And there should generally be at most a handful of these in flight at any moment anyways. The worst-case failure mode should be that someone is spuriously moved to AFK when they shouldn't have been because the bot missed their undeafening, but I'm not sure there's much we can do about that. Regarding SleepList: I was kinda assuming that Node.js timeouts would already be implemented like that?
There was a problem hiding this comment.
Sounds good, I’m happy to accept my fud and go with this :)
| ) { | ||
| assert(new_state.member); | ||
| const member = new_state.member; | ||
| const timeout = setTimeout( |
There was a problem hiding this comment.
Take a look at the set_timeout utility, in general the bot uses this and similar everywhere. It's mostly for an old debugging reason but I think the instrumentation is valuable, and consistency etc.
5bc3e9e to
9ec97d0
Compare
|



Keep members from taking up voice slots by moving them to AFK if they linger in a self-deafened state.