reformat: auto format
This commit is contained in:
parent
5338b56e4c
commit
7a9c2441a3
@ -1,129 +1,129 @@
|
|||||||
import { ChannelType, SlashCommandBuilder } from 'discord.js';
|
import { ChannelType, SlashCommandBuilder } from 'discord.js';
|
||||||
import { VoiceChannel } from '../../../database.js';
|
import { VoiceChannel } from '../../../database.js';
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName('custom_vc')
|
.setName('custom_vc')
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setDescription('Manages reactions for self roles.')
|
.setDescription('Manages reactions for self roles.')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('create')
|
.setName('create')
|
||||||
.setDescription('Creates new voice channel.')
|
.setDescription('Creates new voice channel.')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('name')
|
.setName('name')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setDescription('The name to use for the voice channel.')
|
.setDescription('The name to use for the voice channel.')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('register')
|
.setName('register')
|
||||||
.setDescription('Registers an existing voice channel for custom channel creation.')
|
.setDescription('Registers an existing voice channel for custom channel creation.')
|
||||||
.addChannelOption((option) =>
|
.addChannelOption((option) =>
|
||||||
option
|
option
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setName('channel')
|
.setName('channel')
|
||||||
.addChannelTypes(ChannelType.GuildVoice)
|
.addChannelTypes(ChannelType.GuildVoice)
|
||||||
.setDescription('The voice channel to be used.')
|
.setDescription('The voice channel to be used.')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('remove')
|
.setName('remove')
|
||||||
.setDescription('Remove a voice channel from custom channel creation.')
|
.setDescription('Remove a voice channel from custom channel creation.')
|
||||||
.addChannelOption((option) =>
|
.addChannelOption((option) =>
|
||||||
option
|
option
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.setName('channel')
|
.setName('channel')
|
||||||
.addChannelTypes(ChannelType.GuildVoice)
|
.addChannelTypes(ChannelType.GuildVoice)
|
||||||
.setDescription('The voice channel to be unregistered.')
|
.setDescription('The voice channel to be unregistered.')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
const { guild, options } = interaction;
|
const { guild, options } = interaction;
|
||||||
|
|
||||||
let step;
|
let step;
|
||||||
try {
|
try {
|
||||||
switch (options.getSubcommand()) {
|
switch (options.getSubcommand()) {
|
||||||
case 'create': {
|
case 'create': {
|
||||||
// Get channel name from user input
|
// Get channel name from user input
|
||||||
const name = options.getString('name');
|
const name = options.getString('name');
|
||||||
|
|
||||||
step = 'create';
|
step = 'create';
|
||||||
// Create new channel
|
// Create new channel
|
||||||
const channel = await guild.channels.create({
|
const channel = await guild.channels.create({
|
||||||
name, type: ChannelType.GuildVoice
|
name,
|
||||||
});
|
type: ChannelType.GuildVoice
|
||||||
|
});
|
||||||
// Save channel data
|
|
||||||
step = 'save';
|
// Save channel data
|
||||||
await VoiceChannel.create({
|
step = 'save';
|
||||||
id: channel.id,
|
await VoiceChannel.create({
|
||||||
create: true
|
id: channel.id,
|
||||||
});
|
create: true
|
||||||
|
});
|
||||||
// Reply success to acknowledge command
|
|
||||||
await interaction.reply({
|
// Reply success to acknowledge command
|
||||||
content: `Successfully created channel!`,
|
await interaction.reply({
|
||||||
ephemeral: true
|
content: `Successfully created channel!`,
|
||||||
});
|
ephemeral: true
|
||||||
|
});
|
||||||
console.info(`[INFO] New custom VC created with ID '${channel.id}'.`);
|
|
||||||
break;
|
console.info(`[INFO] New custom VC created with ID '${channel.id}'.`);
|
||||||
}
|
break;
|
||||||
case 'register': {
|
}
|
||||||
// Get channel id from user input
|
case 'register': {
|
||||||
const { id } = options.getChannel('channel');
|
// Get channel id from user input
|
||||||
|
const { id } = options.getChannel('channel');
|
||||||
// Save channel data
|
|
||||||
step = 'save';
|
// Save channel data
|
||||||
await VoiceChannel.create({ id, create: true });
|
step = 'save';
|
||||||
|
await VoiceChannel.create({ id, create: true });
|
||||||
// Reply success to acknowledge command
|
|
||||||
await interaction.reply({
|
// Reply success to acknowledge command
|
||||||
content: `Successfully registered channel!`,
|
await interaction.reply({
|
||||||
ephemeral: true
|
content: `Successfully registered channel!`,
|
||||||
});
|
ephemeral: true
|
||||||
|
});
|
||||||
console.info(`[INFO] New custom VC registered using ID '${id}'.`);
|
|
||||||
break;
|
console.info(`[INFO] New custom VC registered using ID '${id}'.`);
|
||||||
}
|
break;
|
||||||
case 'remove': {
|
}
|
||||||
// Get channel id from user input
|
case 'remove': {
|
||||||
const { id } = options.getChannel('channel');
|
// Get channel id from user input
|
||||||
|
const { id } = options.getChannel('channel');
|
||||||
// Remove channel from guild
|
|
||||||
step = 'remove';
|
// Remove channel from guild
|
||||||
const count = await VoiceChannel.destroy({
|
step = 'remove';
|
||||||
where: {
|
const count = await VoiceChannel.destroy({
|
||||||
id,
|
where: {
|
||||||
create: true
|
id,
|
||||||
}
|
create: true
|
||||||
});
|
}
|
||||||
|
});
|
||||||
// Set reply based on result of deletion
|
|
||||||
let response = 'Successfully removed';
|
// Set reply based on result of deletion
|
||||||
if (count === 0)
|
let response = 'Successfully removed';
|
||||||
response = 'Failed to remove';
|
if (count === 0) response = 'Failed to remove';
|
||||||
|
|
||||||
// Reply to acknowledge command
|
// Reply to acknowledge command
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${response} channel from custom channel creation!`,
|
content: `${response} channel from custom channel creation!`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
|
||||||
console.info(`[INFO] Removed custom VC with ID '${id}'.`);
|
console.info(`[INFO] Removed custom VC with ID '${id}'.`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
// Reply failed to acknowledge command
|
// Reply failed to acknowledge command
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `Failed to ${step} channel!`,
|
content: `Failed to ${step} channel!`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { removeSelfRoles } from '../../../../shared.js';
|
import { removeSelfRoles } from '../../../../shared.js';
|
||||||
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
|
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js';
|
||||||
|
|
||||||
export const data = new ContextMenuCommandBuilder()
|
export const data = new ContextMenuCommandBuilder()
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
.setName('Remove self roles')
|
.setName('Remove self roles')
|
||||||
.setType(ApplicationCommandType.Message);
|
.setType(ApplicationCommandType.Message);
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
const id = interaction.targetMessage.id;
|
const id = interaction.targetMessage.id;
|
||||||
await removeSelfRoles(interaction, id);
|
await removeSelfRoles(interaction, id);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { Events } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
import { VoiceChannel } from '../../database.js';
|
||||||
|
|
||||||
export const name = Events.ChannelDelete;
|
export const name = Events.ChannelDelete;
|
||||||
export async function execute(channel) {
|
export async function execute(channel) {
|
||||||
// Delete channel entry once channel is deleted itself
|
// Delete channel entry once channel is deleted itself
|
||||||
const count = await VoiceChannel.destroy({
|
const count = await VoiceChannel.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: channel.id
|
id: channel.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (count > 0)
|
if (count > 0) console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`);
|
||||||
console.info(`[INFO] Custom VC with ID '${channel.id}' was deleted.`);
|
}
|
||||||
}
|
|
||||||
|
@ -47,7 +47,7 @@ const getChannel = async (member, channels) => {
|
|||||||
await VoiceChannel.create({
|
await VoiceChannel.create({
|
||||||
id: privCh.id,
|
id: privCh.id,
|
||||||
owner: member.user.id
|
owner: member.user.id
|
||||||
})
|
});
|
||||||
|
|
||||||
return privCh;
|
return privCh;
|
||||||
};
|
};
|
||||||
@ -78,14 +78,13 @@ const leftVoiceChat = async (state) => {
|
|||||||
|
|
||||||
export const name = Events.VoiceStateUpdate;
|
export const name = Events.VoiceStateUpdate;
|
||||||
export async function execute(oldState, newState) {
|
export async function execute(oldState, newState) {
|
||||||
if (!newState.channel)
|
if (!newState.channel) return await leftVoiceChat(oldState);
|
||||||
return await leftVoiceChat(oldState);
|
|
||||||
|
|
||||||
// Find channel by id, return if not registered for customs
|
// Find channel by id, return if not registered for customs
|
||||||
const createCh = await VoiceChannel.findOne({
|
const createCh = await VoiceChannel.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: newState.channel.id,
|
id: newState.channel.id,
|
||||||
create: true,
|
create: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (createCh === null) return;
|
if (createCh === null) return;
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { Events } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
import { Message } from '../../database.js';
|
import { Message } from '../../database.js';
|
||||||
|
|
||||||
export const name = Events.MessageDelete;
|
export const name = Events.MessageDelete;
|
||||||
export async function execute(message) {
|
export async function execute(message) {
|
||||||
// Delete message entry once message is deleted itself
|
// Delete message entry once message is deleted itself
|
||||||
const count = await Message.destroy({
|
const count = await Message.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: message.id
|
id: message.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (count > 0)
|
if (count > 0) console.info(`[INFO] Reaction Roles Message with ID '${message.id}' was deleted.`);
|
||||||
console.info(`[INFO] Reaction Roles Message with ID '${message.id}' was deleted.`);
|
}
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { DataTypes } from 'sequelize';
|
import { DataTypes } from 'sequelize';
|
||||||
|
|
||||||
export default function(sequelize) {
|
export default function (sequelize) {
|
||||||
return sequelize.define('VoiceChannel', {
|
return sequelize.define('VoiceChannel', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
|
@ -13,8 +13,7 @@ export const removeSelfRoles = async (interaction, id) => {
|
|||||||
|
|
||||||
// Set reply based on result of deletion
|
// Set reply based on result of deletion
|
||||||
let response = 'Successfully removed';
|
let response = 'Successfully removed';
|
||||||
if (count === 0)
|
if (count === 0) response = 'Failed to remove';
|
||||||
response = 'Failed to remove';
|
|
||||||
|
|
||||||
// Reply to acknowledge command
|
// Reply to acknowledge command
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
|
Loading…
Reference in New Issue
Block a user