Skip to content

Add anti AFK component - #177

Merged
jeremy-rifkin merged 4 commits into
TCCPP:mainfrom
michael-kenzel:anti-afk
Oct 2, 2025
Merged

Add anti AFK component#177
jeremy-rifkin merged 4 commits into
TCCPP:mainfrom
michael-kenzel:anti-afk

Conversation

@michael-kenzel

Copy link
Copy Markdown
Contributor

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

@jeremy-rifkin jeremy-rifkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@michael-kenzel michael-kenzel Oct 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I’m happy to accept my fud and go with this :)

Comment thread src/components/anti-afk.ts Outdated
) {
assert(new_state.member);
const member = new_state.member;
const timeout = setTimeout(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2025

Copy link
Copy Markdown

@jeremy-rifkin jeremy-rifkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@jeremy-rifkin
jeremy-rifkin merged commit 66f7b52 into TCCPP:main Oct 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants