Skip to content

Commit 9c05f6a

Browse files
committed
Only record voice join after notice sent
1 parent 34a726f commit 9c05f6a

1 file changed

Lines changed: 30 additions & 20 deletions

File tree

src/modules/tccpp/components/voice-first-join-notice.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,6 @@ export default class VoiceFirstJoinNotice extends BotComponent {
6969
if (has_voice_mod_or_ban_moderator) {
7070
return;
7171
}
72-
73-
const res = await this.database.voice_first_join_notice.updateOne(
74-
{ guild: new_state.guild.id, user: member.id },
75-
{
76-
$setOnInsert: {
77-
guild: new_state.guild.id,
78-
user: member.id,
79-
first_seen_at: new Date(),
80-
first_channel: new_state.channelId,
81-
},
82-
},
83-
{ upsert: true },
84-
);
85-
if (res.upsertedCount === 0) {
86-
return;
87-
}
8872
if (
8973
member.roles.cache.has(this.roles.voice.id) ||
9074
member.roles.cache.has(this.roles.no_voice.id) ||
@@ -102,13 +86,39 @@ export default class VoiceFirstJoinNotice extends BotComponent {
10286
"__Please do not ping voice moderators to be unsupressed or for the voice role.__";
10387
// Try DM first; fall back to the voice channel if the user has DMs disabled.
10488
// DM's will pierce the veil of a users inbox and is far more likely to be read.
89+
let sent = false;
10590
try {
10691
await member.send({ content: message });
92+
sent = true;
10793
} catch {
108-
await channel.send({
109-
content: `<@${member.id}> ` + message,
110-
allowedMentions: { users: [member.id] },
111-
});
94+
try {
95+
await channel.send({
96+
content: `<@${member.id}> ` + message,
97+
allowedMentions: { users: [member.id] },
98+
});
99+
sent = true;
100+
} catch {
101+
sent = false;
102+
}
103+
}
104+
if (!sent) {
105+
return;
106+
}
107+
108+
const res = await this.database.voice_first_join_notice.updateOne(
109+
{ guild: new_state.guild.id, user: member.id },
110+
{
111+
$setOnInsert: {
112+
guild: new_state.guild.id,
113+
user: member.id,
114+
first_seen_at: new Date(),
115+
first_channel: new_state.channelId,
116+
},
117+
},
118+
{ upsert: true },
119+
);
120+
if (res.upsertedCount === 0) {
121+
return;
112122
}
113123
}
114124
}

0 commit comments

Comments
 (0)