diff --git a/commands/admin/custom_vc/slash.js b/commands/admin/custom_vc/slash.js index f825e41..8b612c6 100644 --- a/commands/admin/custom_vc/slash.js +++ b/commands/admin/custom_vc/slash.js @@ -1,129 +1,129 @@ -import { ChannelType, SlashCommandBuilder } from 'discord.js'; -import { VoiceChannel } from '../../../database.js'; - -export const data = new SlashCommandBuilder() - .setName('custom_vc') - .setDMPermission(false) - .setDescription('Manages reactions for self roles.') - .addSubcommand((subcommand) => - subcommand - .setName('create') - .setDescription('Creates new voice channel.') - .addStringOption((option) => - option - .setName('name') - .setRequired(true) - .setDescription('The name to use for the voice channel.') - ) - ) - .addSubcommand((subcommand) => - subcommand - .setName('register') - .setDescription('Registers an existing voice channel for custom channel creation.') - .addChannelOption((option) => - option - .setRequired(true) - .setName('channel') - .addChannelTypes(ChannelType.GuildVoice) - .setDescription('The voice channel to be used.') - ) - ) - .addSubcommand((subcommand) => - subcommand - .setName('remove') - .setDescription('Remove a voice channel from custom channel creation.') - .addChannelOption((option) => - option - .setRequired(true) - .setName('channel') - .addChannelTypes(ChannelType.GuildVoice) - .setDescription('The voice channel to be unregistered.') - ) - ); -export async function execute(interaction) { - const { guild, options } = interaction; - - let step; - try { - switch (options.getSubcommand()) { - case 'create': { - // Get channel name from user input - const name = options.getString('name'); - - step = 'create'; - // Create new channel - const channel = await guild.channels.create({ - name, type: ChannelType.GuildVoice - }); - - // Save channel data - step = 'save'; - await VoiceChannel.create({ - id: channel.id, - create: true - }); - - // Reply success to acknowledge command - await interaction.reply({ - content: `Successfully created channel!`, - ephemeral: true - }); - - console.info(`[INFO] New custom VC created with ID '${channel.id}'.`); - break; - } - case 'register': { - // Get channel id from user input - const { id } = options.getChannel('channel'); - - // Save channel data - step = 'save'; - await VoiceChannel.create({ id, create: true }); - - // Reply success to acknowledge command - await interaction.reply({ - content: `Successfully registered channel!`, - ephemeral: true - }); - - console.info(`[INFO] New custom VC registered using ID '${id}'.`); - break; - } - case 'remove': { - // Get channel id from user input - const { id } = options.getChannel('channel'); - - // Remove channel from guild - step = 'remove'; - const count = await VoiceChannel.destroy({ - where: { - id, - create: true - } - }); - - // 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} channel from custom channel creation!`, - ephemeral: true - }); - - console.info(`[INFO] Removed custom VC with ID '${id}'.`); - break; - } - } - } catch (error) { - console.error(error); - - // Reply failed to acknowledge command - await interaction.reply({ - content: `Failed to ${step} channel!`, - ephemeral: true - }); - } -} +import { ChannelType, SlashCommandBuilder } from 'discord.js'; +import { VoiceChannel } from '../../../database.js'; + +export const data = new SlashCommandBuilder() + .setName('custom_vc') + .setDMPermission(false) + .setDescription('Manages reactions for self roles.') + .addSubcommand((subcommand) => + subcommand + .setName('create') + .setDescription('Creates new voice channel.') + .addStringOption((option) => + option + .setName('name') + .setRequired(true) + .setDescription('The name to use for the voice channel.') + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('register') + .setDescription('Registers an existing voice channel for custom channel creation.') + .addChannelOption((option) => + option + .setRequired(true) + .setName('channel') + .addChannelTypes(ChannelType.GuildVoice) + .setDescription('The voice channel to be used.') + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('remove') + .setDescription('Remove a voice channel from custom channel creation.') + .addChannelOption((option) => + option + .setRequired(true) + .setName('channel') + .addChannelTypes(ChannelType.GuildVoice) + .setDescription('The voice channel to be unregistered.') + ) + ); +export async function execute(interaction) { + const { guild, options } = interaction; + + let step; + try { + switch (options.getSubcommand()) { + case 'create': { + // Get channel name from user input + const name = options.getString('name'); + + step = 'create'; + // Create new channel + const channel = await guild.channels.create({ + name, + type: ChannelType.GuildVoice + }); + + // Save channel data + step = 'save'; + await VoiceChannel.create({ + id: channel.id, + create: true + }); + + // Reply success to acknowledge command + await interaction.reply({ + content: `Successfully created channel!`, + ephemeral: true + }); + + console.info(`[INFO] New custom VC created with ID '${channel.id}'.`); + break; + } + case 'register': { + // Get channel id from user input + const { id } = options.getChannel('channel'); + + // Save channel data + step = 'save'; + await VoiceChannel.create({ id, create: true }); + + // Reply success to acknowledge command + await interaction.reply({ + content: `Successfully registered channel!`, + ephemeral: true + }); + + console.info(`[INFO] New custom VC registered using ID '${id}'.`); + break; + } + case 'remove': { + // Get channel id from user input + const { id } = options.getChannel('channel'); + + // Remove channel from guild + step = 'remove'; + const count = await VoiceChannel.destroy({ + where: { + id, + create: true + } + }); + + // 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} channel from custom channel creation!`, + ephemeral: true + }); + + console.info(`[INFO] Removed custom VC with ID '${id}'.`); + break; + } + } + } catch (error) { + console.error(error); + + // Reply failed to acknowledge command + await interaction.reply({ + content: `Failed to ${step} channel!`, + ephemeral: true + }); + } +} diff --git a/commands/admin/self_roles/context/remove.js b/commands/admin/self_roles/context/remove.js index 497aa8b..75fc6ca 100644 --- a/commands/admin/self_roles/context/remove.js +++ b/commands/admin/self_roles/context/remove.js @@ -1,11 +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); -} +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); +} diff --git a/events/channels/channelDelete.js b/events/channels/channelDelete.js index 6564da4..b3494b5 100644 --- a/events/channels/channelDelete.js +++ b/events/channels/channelDelete.js @@ -1,14 +1,13 @@ -import { Events } from 'discord.js'; -import { VoiceChannel } from '../../database.js'; - -export const name = Events.ChannelDelete; -export async function execute(channel) { - // Delete channel entry once channel is deleted itself - const count = await VoiceChannel.destroy({ - where: { - id: channel.id - } - }); - if (count > 0) - console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`); -} +import { Events } from 'discord.js'; +import { VoiceChannel } from '../../database.js'; + +export const name = Events.ChannelDelete; +export async function execute(channel) { + // Delete channel entry once channel is deleted itself + const count = await VoiceChannel.destroy({ + where: { + id: channel.id + } + }); + if (count > 0) console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`); +} diff --git a/events/channels/voiceStateUpdate.js b/events/channels/voiceStateUpdate.js index f14694f..616349d 100644 --- a/events/channels/voiceStateUpdate.js +++ b/events/channels/voiceStateUpdate.js @@ -47,7 +47,7 @@ const getChannel = async (member, channels) => { await VoiceChannel.create({ id: privCh.id, owner: member.user.id - }) + }); return privCh; }; @@ -78,14 +78,13 @@ const leftVoiceChat = async (state) => { export const name = Events.VoiceStateUpdate; export async function execute(oldState, newState) { - if (!newState.channel) - return await leftVoiceChat(oldState); + if (!newState.channel) return await leftVoiceChat(oldState); // Find channel by id, return if not registered for customs const createCh = await VoiceChannel.findOne({ where: { id: newState.channel.id, - create: true, + create: true } }); if (createCh === null) return; diff --git a/events/messages/messageDelete.js b/events/messages/messageDelete.js index 3975c95..2f26198 100644 --- a/events/messages/messageDelete.js +++ b/events/messages/messageDelete.js @@ -1,14 +1,13 @@ -import { Events } from 'discord.js'; -import { Message } from '../../database.js'; - -export const name = Events.MessageDelete; -export async function execute(message) { - // Delete message entry once message is deleted itself - const count = await Message.destroy({ - where: { - id: message.id - } - }); - if (count > 0) - console.info(`[INFO] Reaction Roles Message with ID '${message.id}' was deleted.`); -} +import { Events } from 'discord.js'; +import { Message } from '../../database.js'; + +export const name = Events.MessageDelete; +export async function execute(message) { + // Delete message entry once message is deleted itself + const count = await Message.destroy({ + where: { + id: message.id + } + }); + if (count > 0) console.info(`[INFO] Reaction Roles Message with ID '${message.id}' was deleted.`); +} diff --git a/models/voiceChannels.js b/models/voiceChannels.js index db8057b..f1149c7 100644 --- a/models/voiceChannels.js +++ b/models/voiceChannels.js @@ -1,6 +1,6 @@ import { DataTypes } from 'sequelize'; -export default function(sequelize) { +export default function (sequelize) { return sequelize.define('VoiceChannel', { id: { type: DataTypes.STRING, diff --git a/shared.js b/shared.js index 1ead0ea..5a09112 100644 --- a/shared.js +++ b/shared.js @@ -13,8 +13,7 @@ export const removeSelfRoles = async (interaction, id) => { // Set reply based on result of deletion let response = 'Successfully removed'; - if (count === 0) - response = 'Failed to remove'; + if (count === 0) response = 'Failed to remove'; // Reply to acknowledge command await interaction.reply({