mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-10-19 08:37:39 +02:00
feat(arabot): add logging for one sus note removal
This commit is contained in:
parent
c8eb8299dd
commit
b762ae3bc8
@ -29,6 +29,7 @@ import {
|
|||||||
Guild,
|
Guild,
|
||||||
TextChannel,
|
TextChannel,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
|
Snowflake,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import type { Message } from 'discord.js';
|
import type { Message } from 'discord.js';
|
||||||
import { isMessageInstance } from '@sapphire/discord.js-utilities';
|
import { isMessageInstance } from '@sapphire/discord.js-utilities';
|
||||||
@ -320,6 +321,7 @@ export class SusCommand extends Subcommand {
|
|||||||
public async removeNote(interaction: Subcommand.ChatInputCommandInteraction) {
|
public async removeNote(interaction: Subcommand.ChatInputCommandInteraction) {
|
||||||
// Get the arguments
|
// Get the arguments
|
||||||
const noteId = interaction.options.getInteger('id', true);
|
const noteId = interaction.options.getInteger('id', true);
|
||||||
|
const mod = interaction.user;
|
||||||
const { guild, channel } = interaction;
|
const { guild, channel } = interaction;
|
||||||
|
|
||||||
// Checks if all the variables are of the right type
|
// Checks if all the variables are of the right type
|
||||||
@ -349,26 +351,36 @@ export class SusCommand extends Subcommand {
|
|||||||
const modId = note.modId;
|
const modId = note.modId;
|
||||||
|
|
||||||
// Get user GuildMembers for user and mod and person who ran command
|
// Get user GuildMembers for user and mod and person who ran command
|
||||||
const user = this.container.client.users.cache.get(note.userId);
|
let user = guild.client.users.cache.get(userId);
|
||||||
const mod = this.container.client.users.cache.get(note.modId);
|
if (!(user instanceof User)) {
|
||||||
|
user = await guild.client.users.fetch(userId).catch(() => undefined);
|
||||||
let userDisplay = userId;
|
}
|
||||||
if (user instanceof User) {
|
if (user === undefined) {
|
||||||
userDisplay = user.tag;
|
await interaction.reply({
|
||||||
|
content: 'Error fetching user!',
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let modDisplay = modId;
|
let modCreator = guild.client.users.cache.get(modId);
|
||||||
if (mod instanceof User) {
|
if (!(modCreator instanceof User)) {
|
||||||
modDisplay = mod.displayName;
|
modCreator = await guild.client.users.fetch(modId).catch(() => undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
let modCreatorDisplay = modId;
|
||||||
|
if (modCreator instanceof User) {
|
||||||
|
modCreatorDisplay = modCreator.displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an embed for the note
|
// Create an embed for the note
|
||||||
const noteEmbed = new EmbedBuilder()
|
const noteEmbed = new EmbedBuilder()
|
||||||
.setColor('#ff0000')
|
.setColor('#ff0000')
|
||||||
.setTitle(`Sus note for ${userDisplay}`)
|
.setTitle(`Sus note for ${user.tag}`)
|
||||||
.setThumbnail(user!.displayAvatarURL())
|
.setThumbnail(user.displayAvatarURL())
|
||||||
.addFields({
|
.addFields({
|
||||||
name: `ID: ${noteId} | Moderator: ${modDisplay} | Date: <t:${Math.floor(
|
name: `ID: ${noteId} | Moderator: ${modCreatorDisplay} | Date: <t:${Math.floor(
|
||||||
note.time.getTime() / 1000,
|
note.time.getTime() / 1000,
|
||||||
)}>`,
|
)}>`,
|
||||||
value: note.note,
|
value: note.note,
|
||||||
@ -411,9 +423,7 @@ export class SusCommand extends Subcommand {
|
|||||||
if (button.customId === `delete${noteId}`) {
|
if (button.customId === `delete${noteId}`) {
|
||||||
await deactivateNote(noteId);
|
await deactivateNote(noteId);
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: `${
|
content: `${user}'s sus note (ID: ${noteId}) has been successfully removed`,
|
||||||
user instanceof User ? user : userDisplay
|
|
||||||
}'s sus note (ID: ${noteId}) has been successfully removed`,
|
|
||||||
embeds: [],
|
embeds: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -432,6 +442,9 @@ export class SusCommand extends Subcommand {
|
|||||||
await member.roles.remove(IDs.roles.restrictions.sus);
|
await member.roles.remove(IDs.roles.restrictions.sus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logs the removal of the sus note
|
||||||
|
await this.deleteNoteLogger(userId, mod, noteId, guild);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -443,6 +456,52 @@ export class SusCommand extends Subcommand {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logs removal of 1 sus note
|
||||||
|
private async deleteNoteLogger(
|
||||||
|
userId: Snowflake,
|
||||||
|
mod: User,
|
||||||
|
noteId: number,
|
||||||
|
guild: Guild,
|
||||||
|
) {
|
||||||
|
// Find user
|
||||||
|
let user = guild.client.users.cache.get(userId);
|
||||||
|
if (!(user instanceof User)) {
|
||||||
|
user = await guild.client.users.fetch(userId).catch(() => undefined);
|
||||||
|
}
|
||||||
|
if (!(user instanceof User)) return;
|
||||||
|
|
||||||
|
// Log the sus note
|
||||||
|
let logChannel = guild.channels.cache.get(IDs.channels.logs.sus) as
|
||||||
|
| TextChannel
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
if (logChannel === undefined) {
|
||||||
|
logChannel = (await guild.channels.fetch(IDs.channels.logs.sus)) as
|
||||||
|
| TextChannel
|
||||||
|
| undefined;
|
||||||
|
if (logChannel === undefined) {
|
||||||
|
this.container.logger.error('Sus Error: Could not fetch log channel');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor('#28A745')
|
||||||
|
.setAuthor({
|
||||||
|
name: `Removed sus note for ${user.tag}`,
|
||||||
|
iconURL: `${user.displayAvatarURL()}`,
|
||||||
|
})
|
||||||
|
.addFields(
|
||||||
|
{ name: 'User', value: `${user}`, inline: true },
|
||||||
|
{ name: 'Moderator', value: `${mod}`, inline: true },
|
||||||
|
{ name: 'Note ID', value: `${noteId}`, inline: true },
|
||||||
|
)
|
||||||
|
.setTimestamp()
|
||||||
|
.setFooter({ text: `ID: ${user.id}` });
|
||||||
|
|
||||||
|
await logChannel.send({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
|
||||||
public async removeAllNotes(
|
public async removeAllNotes(
|
||||||
interaction: Subcommand.ChatInputCommandInteraction,
|
interaction: Subcommand.ChatInputCommandInteraction,
|
||||||
) {
|
) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user