Skip to content
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

Use user notifications everywhere #35

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/commands/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SlashCommandBuilder } from '@discordjs/builders';
import { Ban } from '@/models/bans';
import { sendEventLogMessage, ordinal } from '@/util';
import { untrustUser } from '@/leveling';
import { notifyUser } from '@/notifications';
import type { ChatInputCommandInteraction } from 'discord.js';

async function banHandler(interaction: ChatInputCommandInteraction): Promise<void> {
Expand Down Expand Up @@ -65,7 +66,7 @@ async function banHandler(interaction: ChatInputCommandInteraction): Promise<voi
});

await sendEventLogMessage(guild, null, eventLogEmbed);

const { count, rows } = await Ban.findAndCountAll({
where: {
user_id: member.id
Expand Down Expand Up @@ -131,9 +132,9 @@ async function banHandler(interaction: ChatInputCommandInteraction): Promise<voi
sendMemberEmbeds.push(pastBansEmbed);
}

await member.send({
await notifyUser(guild, user, {
embeds: sendMemberEmbeds
}).catch(() => console.log('Failed to DM user'));
});

await member.ban({
reason: reason
Expand Down Expand Up @@ -172,4 +173,4 @@ export default {
name: command.name,
handler: banHandler,
deploy: command.toJSON()
};
};
9 changes: 5 additions & 4 deletions src/commands/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Kick } from '@/models/kicks';
import { Ban } from '@/models/bans';
import { ordinal, sendEventLogMessage } from '@/util';
import { untrustUser } from '@/leveling';
import { notifyUser } from '@/notifications';
import type { ChatInputCommandInteraction } from 'discord.js';

async function kickHandler(interaction: ChatInputCommandInteraction): Promise<void> {
Expand Down Expand Up @@ -77,7 +78,7 @@ async function kickHandler(interaction: ChatInputCommandInteraction): Promise<vo
if (count >= 2) { // Atleast 2 previous kicks, this would be the 3rd strike. Ban
eventLogEmbed.setColor(0xF24E43);
eventLogEmbed.setTitle('Event Type: _Member Banned_');

const banEmbed = new EmbedBuilder();

banEmbed.setTitle('Punishment Details');
Expand Down Expand Up @@ -172,9 +173,9 @@ async function kickHandler(interaction: ChatInputCommandInteraction): Promise<vo
sendMemberEmbeds.push(pastKicksEmbed);
}

await member.send({
await notifyUser(guild, user, {
embeds: sendMemberEmbeds
}).catch(() => console.log('Failed to DM user'));
});

if (isKick) {
await member.kick(reason);
Expand Down Expand Up @@ -226,4 +227,4 @@ export default {
name: command.name,
handler: kickHandler,
deploy: command.toJSON()
};
};
9 changes: 5 additions & 4 deletions src/commands/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Kick } from '@/models/kicks';
import { Ban } from '@/models/bans';
import { ordinal, sendEventLogMessage } from '@/util';
import { untrustUser } from '@/leveling';
import { notifyUser } from '@/notifications';
import type { ChatInputCommandInteraction } from 'discord.js';

async function warnHandler(interaction: ChatInputCommandInteraction): Promise<void> {
Expand Down Expand Up @@ -176,9 +177,9 @@ async function warnHandler(interaction: ChatInputCommandInteraction): Promise<vo
);
}

await member.send({
await notifyUser(guild, user, {
embeds: [punishmentEmbed, pastWarningsEmbed]
}).catch(() => console.log('Failed to DM user'));
});

if (isKick) {
await member.kick(reason);
Expand Down Expand Up @@ -237,9 +238,9 @@ async function warnHandler(interaction: ChatInputCommandInteraction): Promise<vo
}
);

await member.send({
await notifyUser(guild, user, {
embeds: [punishmentEmbed]
}).catch(() => console.log('Failed to DM user'));
});
}

await Warning.create({
Expand Down
1 change: 0 additions & 1 deletion src/leveling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export async function handleLeveling(message: Message): Promise<void> {
});

notifyUser(guild, message.author, {
content: '',
embeds: [notificationEmbed]
});

Expand Down
21 changes: 9 additions & 12 deletions src/matchmaking-threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MatchmakingThread } from '@/models/matchmakingThreads';
import { User } from '@/models/users';
import { sendEventLogMessage } from '@/util';
import { getDB } from '@/db';
import { notifyUser } from '@/notifications';
import type { Message } from 'discord.js';

export async function handleMatchmakingThreadMessage(message: Message): Promise<void> {
Expand Down Expand Up @@ -104,18 +105,14 @@ export async function checkMatchmakingThreads(): Promise<void> {
iconURL: guild.iconURL()!
});

try {
//TODO - Switch this to the new DM/notification channel system
await creatorUser.send({
embeds: [notificationEmbed]
});
await User.upsert({
user_id: threadChannel.ownerId,
matchmaking_notification_sent: true
});
} catch (error) {
console.log('Failed to DM user');
}
await notifyUser(guild, creatorUser, {
embeds: [notificationEmbed]
});

await User.upsert({
user_id: threadChannel.ownerId,
matchmaking_notification_sent: true
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function notifyUserInChannel(guild: Guild, user: User, message: string | M
if (typeof message === 'string') {
message = `<@${user.id}>\n${message}`;
} else {
message.content = `<@${user.id}>\n${message.content}`;
message.content = `<@${user.id}>\n${message.content ?? ''}`;
}

await thread.send(message);
Expand Down