Repository navigation
Expand file tree
/
Copy pathwarn.js
More file actions
161 lines (137 loc) · 5.66 KB
/
Copy pathwarn.js
File metadata and controls
161 lines (137 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const { warns } = require("./db.js")
const { MessageActionRow, MessageButton } = require('discord.js');
module.exports = {
takeInteraction: async function (interaction) {
if (!interaction.member.roles.cache.get(process.env.MODERATOR_ROLE_ID)) return interaction.reply({ content: 'You do not have permission to use this command!', ephemeral: true });
let user = interaction.options.getUser('user');
let message = interaction.options.getString('message');
warn = await warns.insert({ user: user.id, moderator: interaction.member.id, message: message, date: Date.now() });
let totalInfractions = await warns.count({ user: user.id });
let confirmationMessageActions = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('delete-warn')
.setLabel('Delete')
.setStyle('DANGER'),
)
let confirmationMessage = {
embeds: [{
title: `Warned ${user.username}`,
description: message,
fields: [
{
name: "Moderator",
value: `<@${warn.moderator}>`,
},
{
name: "User",
value: `<@${warn.user}>`,
},
{
name: "Warn ID",
value: warn._id.toString(),
},
{
name: "Web UI",
value:`[See at griffbot.jeffalo.net](${process.env.ADMIN_URL}/dashboard/infractions/${warn._id})`,
},
{
name: "Total Infractions",
value: totalInfractions.toString(),
},
],
color: '#f03a7c',
"thumbnail": {
"url": user.displayAvatarURL()
}
}],
components: [confirmationMessageActions]
}
// now dm the user
let dmMessage = {
embeds: [{
title: `You were warned in the ${interaction.guild.name} server!`,
description: message,
color: '#f03a7c',
thumbnail: {
url: interaction.guild.iconURL()
}
}]
}
try {
await user.send(dmMessage)
} catch (error) {
confirmationMessage.embeds[0].fields.push({
name: "DM Error",
value: error.message,
})
}
interaction.reply(confirmationMessage);
},
takeDeleteInteraction: async function (interaction) {
if (!interaction.member.roles.cache.get(process.env.MODERATOR_ROLE_ID)) return interaction.reply({ content: 'You do not have permission to use this command!', ephemeral: true });
// let warnID = interaction.message.embeds[0].fields[2].value;
let warnID = interaction.message.embeds[0].fields.find(field => field.name === "Warn ID").value;
if (!warnID.match(/^[0-9a-fA-F]{24}$/)) {
return interaction.reply({ content: 'Invalid ID.', ephemeral: true });
}
let warn = await warns.findOne({ _id: warnID });
if (!warn) return interaction.reply({ content: 'That warn does not exist!', ephemeral: true });
await warns.remove({ _id: warnID });
let deletedConfirmationMessageActions = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('delete-warn')
.setLabel('Deleted')
.setStyle('DANGER')
.setDisabled(true),
)
interaction.message.edit({ components: [deletedConfirmationMessageActions] })
interaction.reply({ content: 'Warn deleted!', ephemeral: true });
},
takeInfractionsInteraction: async function (interaction) {
await interaction.deferReply();
if (!interaction.member.roles.cache.get(process.env.MODERATOR_ROLE_ID)) return interaction.reply({ content: 'You do not have permission to use this command!', ephemeral: true });
let user = interaction.options.getUser('user');
let infractions = await warns.find({ user: user.id })
infractions = infractions.reverse();
// create a list of infractions, and say how many were within this week
/* let infractionListMessage = {
embeds: [{
title: `Infractions for ${user.username}`,
description: `This user has ${infractions.length} infractions. ${infractions.filter(infraction => infraction.date > Date.now() - 604800000).length} were within the last week.`,
fields: [
{
name: "Infractions",
value: infractions.map((infraction, i) => `**${infractions.length - i}**. ${infraction.message}\n\n<@${infraction.moderator}> - <t:${Math.floor(infraction.date / 1000)}:R> - [${infraction._id}](${process.env.ADMIN_URL}/dashboard/infractions/${infraction._id})`).join('\n\n'),
},
],
color: '#f03a7c',
"thumbnail": {
"url": user.displayAvatarURL()
}
}],
} */
let infractionListMessage = {
embeds: [{
title: `Infractions for ${user.username}`,
description: `This user has ${infractions.length} infractions. ${infractions.filter(infraction => infraction.date > Date.now() - 604800000).length} were within the last week.`,
fields: infractions.map((infraction, i) => {
return {
name: `Warn #${infractions.length - i}`,
value: `${infraction.message}\n\n<@${infraction.moderator}> - <t:${Math.floor(infraction.date / 1000)}:R> - [${infraction._id}](${process.env.ADMIN_URL}/dashboard/infractions/${infraction._id})`,
}
}),
color: '#f03a7c',
"thumbnail": {
"url": user.displayAvatarURL()
}
}],
}
try {
await interaction.editReply(infractionListMessage);
} catch (error) {
interaction.editReply({ content: `There was an error sending infraction list. ${error.message}. Try viewing the infractions at ${process.env.ADMIN_URL}/dashboard/search-infractions?user=490581889980301312`, });
}
}
}