@@ -57,9 +57,9 @@ export default class VoiceFirstJoinNotice extends BotComponent {
5757 return ;
5858 }
5959
60- // Only record or notify on first join when no voice mod or ban-capable mod is present.
61- // If one is present, the user can be helped immediately; we delay the notice until they
62- // join with no moderator present.
60+ // Only record or notify when no voice mod or ban-capable mod is present.
61+ // If one is present the user can be helped immediately,
62+ // so we delay the notice until they join with no moderator present.
6363 const has_voice_mod_or_ban_moderator = [ ...channel . members . values ( ) ] . some (
6464 m =>
6565 m . id !== member . id &&
@@ -79,33 +79,34 @@ export default class VoiceFirstJoinNotice extends BotComponent {
7979 ) {
8080 return ;
8181 }
82+ const already_notified = await this . database . voice_first_join_notice . findOne ( {
83+ guild : new_state . guild . id ,
84+ user : member . id ,
85+ } ) ;
86+ if ( already_notified ) {
87+ return ;
88+ }
8289 const message =
8390 "new users are suppressed by default to protect our voice channels. " +
8491 "You will be able to speak when joining a channel with a voice moderator present. " +
8592 "Stick around and you will eventually be granted permanent voice access. " +
86- "__Please do not ping voice moderators to be unsupressed or for the voice role.__" ;
87- // Try DM first; fall back to the voice channel if the user has DMs disabled.
88- // DM's will pierce the veil of a users inbox and is far more likely to be read.
89- let sent = false ;
93+ "__Please do not ping voice moderators to be unsuppressed or for the voice role.__" ;
94+ // Try a DM first since it is far more likely to be read
95+ // fall back to the voice channel if the user has DMs disabled.
9096 try {
9197 await member . send ( { content : message } ) ;
92- sent = true ;
9398 } catch {
9499 try {
95100 await channel . send ( {
96101 content : `<@${ member . id } > ` + message ,
97102 allowedMentions : { users : [ member . id ] } ,
98103 } ) ;
99- sent = true ;
100104 } catch {
101- sent = false ;
105+ // Neither delivery worked, leave the user unrecorded so the next join retries
106+ return ;
102107 }
103108 }
104- if ( ! sent ) {
105- return ;
106- }
107-
108- const res = await this . database . voice_first_join_notice . updateOne (
109+ await this . database . voice_first_join_notice . updateOne (
109110 { guild : new_state . guild . id , user : member . id } ,
110111 {
111112 $setOnInsert : {
@@ -117,8 +118,5 @@ export default class VoiceFirstJoinNotice extends BotComponent {
117118 } ,
118119 { upsert : true } ,
119120 ) ;
120- if ( res . upsertedCount === 0 ) {
121- return ;
122- }
123121 }
124122}
0 commit comments