-
Notifications
You must be signed in to change notification settings - Fork 21
Auto message info on vc join #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8a43d12
Add in auto message for first-ever voice access
Rinzii 80cc0d4
Also check for booster status or skill role above beginner
Rinzii 95be28d
Move vc auto reply logic into a tccpp component and apply requested c…
Rinzii 1b026b1
Remove redundant comments
Rinzii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/modules/tccpp/components/voice-first-join-notice.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { strict as assert } from "assert"; | ||
| import * as Discord from "discord.js"; | ||
|
|
||
| import { BotComponent } from "../../../bot-component.js"; | ||
| import SkillRoles, { SkillLevel } from "./skill-roles.js"; | ||
|
|
||
| type voice_first_join_notice_entry = { | ||
| guild: string; | ||
| user: string; | ||
| first_seen_at: Date; | ||
| first_channel: string; | ||
| }; | ||
|
|
||
| export default class VoiceFirstJoinNotice extends BotComponent { | ||
| private database = this.wheatley.database.create_proxy<{ | ||
| voice_first_join_notice: voice_first_join_notice_entry; | ||
| }>(); | ||
|
|
||
| override async setup() { | ||
| await this.database.voice_first_join_notice.createIndex({ guild: 1, user: 1 }, { unique: true }); | ||
| } | ||
|
|
||
| override async on_voice_state_update(old_state: Discord.VoiceState, new_state: Discord.VoiceState) { | ||
| // user joined a voice channel | ||
| if (old_state.channelId != null || new_state.channelId == null) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore other guilds | ||
| if (new_state.guild.id !== this.wheatley.guild.id) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore bots | ||
| const member = new_state.member; | ||
| if (!member || member.user.bot) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore AFK | ||
| if (new_state.channelId === this.wheatley.guild.afkChannelId) { | ||
| return; | ||
| } | ||
|
|
||
| // Record first join regardless of whether we'd send (so we never send later if roles change) | ||
| const res = await this.database.voice_first_join_notice.updateOne( | ||
| { guild: new_state.guild.id, user: member.id }, | ||
| { | ||
| $setOnInsert: { | ||
| guild: new_state.guild.id, | ||
| user: member.id, | ||
| first_seen_at: new Date(), | ||
| first_channel: new_state.channelId, | ||
| }, | ||
| }, | ||
| { upsert: true }, | ||
| ); | ||
|
|
||
| // ignore if we already recorded this join | ||
| if (res.upsertedCount === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Only send to users without permanent voice access / exceptions. | ||
| if (member.roles.cache.has(this.wheatley.roles.voice.id)) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore if the user has the no_voice role | ||
| if (member.roles.cache.has(this.wheatley.roles.no_voice.id)) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore if the user is a server booster | ||
| if (member.roles.cache.has(this.wheatley.roles.server_booster.id)) { | ||
| return; | ||
| } | ||
|
|
||
| // ignore if the user has a skill level above beginner | ||
| const skill_roles_component = this.wheatley.components.get("SkillRoles"); | ||
| assert(skill_roles_component && skill_roles_component instanceof SkillRoles, "SkillRoles component missing"); | ||
| if (skill_roles_component.find_highest_skill_level(member) > SkillLevel.beginner) { | ||
| return; | ||
| } | ||
|
|
||
| const channel = new_state.channel; | ||
| // The member joined a voice channel so this should always be non-null. | ||
| if (!channel) { | ||
| return; | ||
| } | ||
|
|
||
| await channel.send({ | ||
| content: | ||
| `<@${member.id}> ` + | ||
| "new users are suppressed by default to protect our voice channels. " + | ||
| "You will be able to speak when joining a channel with a voice moderator present. " + | ||
| "Stick around and you will eventually be granted permanent voice access. " + | ||
| "__Please do not ping voice moderators to be unsupressed or for the voice role.__", | ||
| allowedMentions: { users: [member.id] }, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.