remove self roels contextcommand and shared function

This commit is contained in:
Baipyrus 2024-02-08 19:44:16 +01:00
parent dfe673bebc
commit e69806c132
3 changed files with 34 additions and 20 deletions

View File

@ -0,0 +1,11 @@
import { removeSelfRoles } from '../../../../shared.js';
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
export const data = new ContextMenuCommandBuilder()
.setDMPermission(false)
.setName('Remove self roles')
.setType(ApplicationCommandType.Message);
export async function execute(interaction) {
const id = interaction.targetMessage.id;
await removeSelfRoles(interaction, id);
}

View File

@ -66,26 +66,7 @@ const removeSelfRoles = async (interaction, msgID) => {
return;
}
// Try deleting message from database
const count = await Message.destroy({
where: {
id: msgID
}
});
// Set reply based on result of deletion
let response = 'Successfully removed';
if (count === 0)
response = 'Failed to remove';
// Reply to acknowledge command
await interaction.reply({
content: `${response} self roles from message!`,
ephemeral: true
});
console.info(`[INFO] Removed self roles from message with ID '${msgID}'.`);
await removeSelfRoles(interaction, msgID);
};
export const data = new SlashCommandBuilder()

View File

@ -3,6 +3,28 @@ import { Op } from 'sequelize';
import { readdir } from 'fs/promises';
import { Message, RoleEmojiPair } from './database.js';
export const removeSelfRoles = async (interaction, id) => {
// Try deleting message from database
const count = await Message.destroy({
where: {
id: id
}
});
// Set reply based on result of deletion
let response = 'Successfully removed';
if (count === 0)
response = 'Failed to remove';
// Reply to acknowledge command
await interaction.reply({
content: `${response} self roles from message!`,
ephemeral: true
});
console.info(`[INFO] Removed self roles from message with ID '${id}'.`);
};
const saveMessageData = async (id, role, emoji) => {
// Try finding message
const msg = await Message.findOne({ where: { id } });