remove self roels contextcommand and shared function
This commit is contained in:
parent
dfe673bebc
commit
e69806c132
11
commands/admin/self_roles/context/remove.js
Normal file
11
commands/admin/self_roles/context/remove.js
Normal 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);
|
||||
}
|
@ -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()
|
||||
|
22
shared.js
22
shared.js
@ -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 } });
|
||||
|
Loading…
Reference in New Issue
Block a user