Skip to content

Commit eb36abe

Browse files
committed
feat: private message command now works
1 parent 7028872 commit eb36abe

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/commands/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { githubCommand } from './github'
77
import { pingCommand } from './ping'
88
import { solvedCommand } from './solved'
99
import { verifyCommand } from './verify'
10+
import { pmCommand } from '@/commands/pm'
1011

1112
export const commands: AnyCommand[] = [
1213
docsCommand,
@@ -16,6 +17,7 @@ export const commands: AnyCommand[] = [
1617
verifyCommand,
1718
resetCommand,
1819
projectCommand,
20+
pmCommand,
1921
]
2022

2123
export default commands

src/commands/pm.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11
import { ChatInputCommand } from '@/types'
2-
import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js'
2+
import {
3+
ChatInputCommandInteraction,
4+
EmbedBuilder,
5+
GuildMemberRoleManager,
6+
SlashCommandBuilder,
7+
} from 'discord.js'
8+
import process from 'node:process'
9+
import { PERMISSION_ERROR_TEXT } from '@/data'
10+
import { info } from '@/logging/logger'
311

412
export const pmCommand: ChatInputCommand = {
513
data: new SlashCommandBuilder()
614
.setName('pm')
7-
.setDescription('Send a private message.')
15+
.setDescription('Send a private message')
816
.addStringOption((option) =>
917
option.setName('id').setDescription('Discord User ID').setRequired(true),
1018
)
19+
.addStringOption((option) =>
20+
option.setName('reason').setDescription('Reason for sending a message').setRequired(true),
21+
)
1122
.addStringOption((option) =>
1223
option.setName('message').setDescription('Private message').setRequired(true),
1324
)
1425
.addStringOption((option) =>
1526
option.setName('title').setDescription('Embed title').setRequired(false),
1627
) as SlashCommandBuilder,
1728
meta: {
18-
name: 'reset',
19-
description: 'Reset user active role and message counter',
29+
name: 'pm',
30+
description: 'Send a private message',
2031
category: 'moderation',
2132
guildOnly: true,
2233
},
2334
execute: async (interaction: ChatInputCommandInteraction) => {
24-
if (!interaction.guild) return
35+
if (!interaction.guild || !interaction.member) return
36+
if (
37+
!(interaction.member.roles as GuildMemberRoleManager).cache.has(
38+
process.env.DISCORD_MODERATOR_ROLE_ID!,
39+
)
40+
) {
41+
await interaction.reply({
42+
content: PERMISSION_ERROR_TEXT,
43+
flags: 'Ephemeral',
44+
})
45+
return
46+
}
2547

2648
const id = interaction.options.getString('id', true)
49+
const reason = interaction.options.getString('reason', true)
2750
const message = interaction.options.getString('message', true)
2851
const title = interaction.options.getString('title', false)
2952
const member = await interaction.guild.members.fetch(id)
@@ -34,5 +57,12 @@ export const pmCommand: ChatInputCommand = {
3457
.setDescription(message)
3558

3659
await member.user.send({ embeds: [embed] })
60+
await interaction.reply({
61+
content: 'Private message has been successfully sent!',
62+
flags: 'Ephemeral',
63+
})
64+
info(
65+
`:incoming_envelope: Moderator (\`${interaction.user.username}\`, ID: ${interaction.user.id}) has sent a private message to a user ${member.user} (\`${member.user.username}\`, ID: ${member.user.id}), with a reason: ${reason}.`,
66+
)
3767
},
3868
}

src/commands/reset.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { db } from '@/db'
77
import { users } from '@/db/schema'
88
import { ChatInputCommand } from '@/types'
99
import { info } from '@/logging/logger'
10+
import content from '*?raw'
11+
import { PERMISSION_ERROR_TEXT } from '@/data'
1012

1113
export const resetCommand: ChatInputCommand = {
1214
data: new SlashCommandBuilder()
@@ -27,6 +29,13 @@ export const resetCommand: ChatInputCommand = {
2729
const id = interaction.options.getString('id', true)
2830
const member = await interaction.guild.members.fetch(id)
2931

32+
if (!member.roles.cache.has(process.env.DISCORD_MODERATOR_ROLE_ID!)) {
33+
await interaction.reply({
34+
content: PERMISSION_ERROR_TEXT,
35+
flags: 'Ephemeral',
36+
})
37+
return
38+
}
3039
await db.update(users).set({ messagesSent: 0 }).where(eq(users.id, id))
3140
await member.roles.remove(process.env.ACTIVE_ROLE_ID!)
3241

0 commit comments

Comments
 (0)