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; return;
} }
// Try deleting message from database await removeSelfRoles(interaction, msgID);
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}'.`);
}; };
export const data = new SlashCommandBuilder() export const data = new SlashCommandBuilder()

View File

@ -3,6 +3,28 @@ import { Op } from 'sequelize';
import { readdir } from 'fs/promises'; import { readdir } from 'fs/promises';
import { Message, RoleEmojiPair } from './database.js'; 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) => { const saveMessageData = async (id, role, emoji) => {
// Try finding message // Try finding message
const msg = await Message.findOne({ where: { id } }); const msg = await Message.findOne({ where: { id } });