refactor: autoformat with prettier
This commit is contained in:
parent
32ceb7646b
commit
4fea72ad88
@ -24,7 +24,7 @@ export async function modalSubmit(interaction) {
|
||||
if (role === null) {
|
||||
await interaction.reply({
|
||||
content: 'Could not fetch role! Please contact server staff.',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -43,21 +43,24 @@ export async function execute(interaction) {
|
||||
.setStyle(TextInputStyle.Short)
|
||||
.setCustomId('message')
|
||||
.setRequired(true)
|
||||
.setValue(id));
|
||||
.setValue(id)
|
||||
);
|
||||
|
||||
const role = new ActionRowBuilder().addComponents(
|
||||
new TextInputBuilder()
|
||||
.setLabel('Enter exactly one role ID.')
|
||||
.setStyle(TextInputStyle.Short)
|
||||
.setCustomId('role')
|
||||
.setRequired(true));
|
||||
.setRequired(true)
|
||||
);
|
||||
|
||||
const emoji = new ActionRowBuilder().addComponents(
|
||||
new TextInputBuilder()
|
||||
.setLabel('Enter exactly one emoji.')
|
||||
.setStyle(TextInputStyle.Short)
|
||||
.setCustomId('emoji')
|
||||
.setRequired(true));
|
||||
.setRequired(true)
|
||||
);
|
||||
|
||||
modal.addComponents(message, role, emoji);
|
||||
|
||||
|
@ -15,7 +15,7 @@ export async function execute(interaction) {
|
||||
// Reply successfully to acknowledge command
|
||||
await interaction.reply({
|
||||
content: `Successfully saved data from message! Add roles to it with reference ID '${id}'.`,
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
console.info(`[INFO] New self roles on message with ID: '${id}'.`);
|
||||
@ -24,7 +24,7 @@ export async function execute(interaction) {
|
||||
// Reply failed to acknowledge command
|
||||
await interaction.reply({
|
||||
content: 'Failed to save data from message!',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { Op } from 'sequelize';
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import { Message, RoleEmojiPair } from './../../database.js';
|
||||
import { Message } from './../../database.js';
|
||||
import { addSelfRoles } from '../../shared.js';
|
||||
|
||||
const createSelfRoles = async (interaction) => {
|
||||
@ -22,7 +21,7 @@ const registerSelfRoles = async (interaction) => {
|
||||
const id = options.getString('id');
|
||||
const response = {
|
||||
success: false,
|
||||
msgID: null,
|
||||
msgID: null
|
||||
};
|
||||
|
||||
try {
|
||||
@ -32,7 +31,7 @@ const registerSelfRoles = async (interaction) => {
|
||||
// Reply successfully to acknowledge command
|
||||
await interaction.reply({
|
||||
content: 'Successfully fetched message!',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
response.success = true;
|
||||
@ -45,7 +44,7 @@ const registerSelfRoles = async (interaction) => {
|
||||
// Reply failed to acknowledge command
|
||||
await interaction.reply({
|
||||
content: 'Failed to fetch message!',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
return response;
|
||||
@ -55,60 +54,64 @@ export const data = new SlashCommandBuilder()
|
||||
.setName('self_roles')
|
||||
.setDMPermission(false)
|
||||
.setDescription('Manages reactions for self roles.')
|
||||
.addSubcommand(subcommand =>
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('create')
|
||||
.setDescription('Creates new message in channel.')
|
||||
.addStringOption(option =>
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('text')
|
||||
.setRequired(true)
|
||||
.setDescription('The text to be displayed in the message.')))
|
||||
.addSubcommand(subcommand =>
|
||||
.setDescription('The text to be displayed in the message.')
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('register')
|
||||
.setDescription('Registers an existing message.')
|
||||
.addStringOption(option =>
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('id')
|
||||
.setRequired(true)
|
||||
.setDescription('The ID to reference the message to be used.')))
|
||||
.addSubcommand(subcommand =>
|
||||
.setDescription('The ID to reference the message to be used.')
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('add')
|
||||
.setDescription('Add a role-emoji-pair to a message.')
|
||||
.addStringOption(option =>
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('id')
|
||||
.setRequired(true)
|
||||
.setDescription('The ID to reference the message to be used.'))
|
||||
.addRoleOption(option =>
|
||||
option
|
||||
.setName('role')
|
||||
.setRequired(true)
|
||||
.setDescription('The role be assigned to.'))
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('emoji')
|
||||
.setRequired(true)
|
||||
.setDescription('The emoji to be reacted with.')));
|
||||
.setDescription('The ID to reference the message to be used.')
|
||||
)
|
||||
.addRoleOption((option) =>
|
||||
option.setName('role').setRequired(true).setDescription('The role be assigned to.')
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName('emoji').setRequired(true).setDescription('The emoji to be reacted with.')
|
||||
)
|
||||
);
|
||||
export async function execute(interaction) {
|
||||
const { options } = interaction;
|
||||
|
||||
let createNew = false, id;
|
||||
let createNew = false,
|
||||
id;
|
||||
switch (options.getSubcommand()) {
|
||||
case 'create':
|
||||
id = await createSelfRoles(interaction);
|
||||
// Flag to create new database entry
|
||||
createNew = true;
|
||||
break;
|
||||
case 'register':
|
||||
case 'register': {
|
||||
const response = await registerSelfRoles(interaction);
|
||||
id = response.msgID ?? id;
|
||||
// Flag to create new database entry
|
||||
createNew = response.success;
|
||||
break;
|
||||
case 'add':
|
||||
}
|
||||
case 'add': {
|
||||
// Get command options
|
||||
const msgID = options.getString('id');
|
||||
const role = options.getRole('role');
|
||||
@ -117,6 +120,7 @@ export async function execute(interaction) {
|
||||
await addSelfRoles(interaction, msgID, role, emoji);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (createNew) {
|
||||
try {
|
||||
@ -128,7 +132,7 @@ export async function execute(interaction) {
|
||||
// Reply failed to acknowledge command
|
||||
await interaction.followUp({
|
||||
content: 'Failed to save data from message!',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ const { DB_NAME } = process.env;
|
||||
const sequelize = new Sequelize({
|
||||
storage: `${DB_NAME}.sqlite`,
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
logging: false
|
||||
});
|
||||
const RoleEmojiPair = defineRoleEmojiPair(sequelize);
|
||||
const VoiceChannel = defineVoiceChannel(sequelize);
|
||||
|
@ -34,4 +34,5 @@ getFiles(cmdPath)
|
||||
(await Promise.all(files.map(importAndCheck)))
|
||||
.filter((module) => module !== 0)
|
||||
.map((module) => module.data.toJSON())
|
||||
).then(putCommands);
|
||||
)
|
||||
.then(putCommands);
|
||||
|
@ -23,7 +23,11 @@ const executeCommand = async (interaction, command) => {
|
||||
|
||||
const genericExecute = async (interaction, command, name, description, cmdName) => {
|
||||
try {
|
||||
console.info(`[INFO] Command ${(cmdName ?? interaction.commandName) ?? 'anonymous'} ${description ?? `used "${name}"`}.`);
|
||||
console.info(
|
||||
`[INFO] Command ${cmdName ?? interaction.commandName ?? 'anonymous'} ${
|
||||
description ?? `used "${name}"`
|
||||
}.`
|
||||
);
|
||||
await command[name](interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -11,7 +11,7 @@ export async function execute(reaction, user) {
|
||||
const msgID = reaction.message.id;
|
||||
const message = await Message.findOne({
|
||||
where: {
|
||||
id: msgID,
|
||||
id: msgID
|
||||
}
|
||||
});
|
||||
// Ignore if unregistered
|
||||
@ -22,7 +22,7 @@ export async function execute(reaction, user) {
|
||||
const rep = await RoleEmojiPair.findOne({
|
||||
where: {
|
||||
message: msgID,
|
||||
emoji,
|
||||
emoji
|
||||
}
|
||||
});
|
||||
// Deny if unregistered
|
||||
|
@ -11,7 +11,7 @@ export async function execute(reaction, user) {
|
||||
const msgID = reaction.message.id;
|
||||
const message = await Message.findOne({
|
||||
where: {
|
||||
id: msgID,
|
||||
id: msgID
|
||||
}
|
||||
});
|
||||
// Ignore if unregistered
|
||||
@ -22,7 +22,7 @@ export async function execute(reaction, user) {
|
||||
const rep = await RoleEmojiPair.findOne({
|
||||
where: {
|
||||
message: msgID,
|
||||
emoji,
|
||||
emoji
|
||||
}
|
||||
});
|
||||
// Deny if unregistered
|
||||
|
@ -4,7 +4,7 @@ export const name = Events.VoiceStateUpdate;
|
||||
export async function execute(oldState, newState) {
|
||||
console.debug('[DEBUG] Voice State Update');
|
||||
|
||||
const change = (!!oldState.channel) ^ (!!newState.channel);
|
||||
const change = !!oldState.channel ^ !!newState.channel;
|
||||
if (!change) return;
|
||||
|
||||
const guild = newState.guild.name;
|
||||
|
11
index.js
11
index.js
@ -37,13 +37,10 @@ const evtPath = join(__dirname, 'events');
|
||||
getFiles(cmdPath)
|
||||
// For each command file
|
||||
.then(async (files) =>
|
||||
(await Promise.all(files.map(importAndCheck)))
|
||||
.filter((module) => module !== 0)
|
||||
).then(async (commands) => {
|
||||
(await Promise.all(files.map(importAndCheck))).filter((module) => module !== 0)
|
||||
)
|
||||
.then(async (commands) => {
|
||||
const files = await getFiles(evtPath);
|
||||
const events = await Promise.all(
|
||||
files.map(async (filePath) =>
|
||||
await import(filePath)
|
||||
));
|
||||
const events = await Promise.all(files.map(async (filePath) => await import(filePath)));
|
||||
runClient(commands, events);
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { DataTypes } from "sequelize";
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
export default function(sequelize) {
|
||||
export default function (sequelize) {
|
||||
return sequelize.define('Messages', {
|
||||
id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
primaryKey: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
import { DataTypes, Deferrable } from "sequelize";
|
||||
import { DataTypes, Deferrable } from 'sequelize';
|
||||
|
||||
export default function(sequelize) {
|
||||
export default function (sequelize) {
|
||||
return sequelize.define('RoleEmojiPairs', {
|
||||
id: {
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
type: DataTypes.UUID,
|
||||
primaryKey: true,
|
||||
primaryKey: true
|
||||
},
|
||||
message: {
|
||||
type: DataTypes.STRING,
|
||||
references: {
|
||||
deferrable: Deferrable.INITIALLY_IMMEDIATE,
|
||||
model: 'Messages',
|
||||
key: 'id',
|
||||
},
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
emoji: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.STRING
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { DataTypes } from "sequelize";
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
export default function(sequelize) {
|
||||
export default function (sequelize) {
|
||||
return sequelize.define('VoiceChannel', {
|
||||
id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
primaryKey: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
24
shared.js
24
shared.js
@ -1,5 +1,5 @@
|
||||
import { Op } from "sequelize";
|
||||
import { Message, RoleEmojiPair } from "./database.js";
|
||||
import { Op } from 'sequelize';
|
||||
import { Message, RoleEmojiPair } from './database.js';
|
||||
|
||||
const saveMessageData = async (id, role, emoji) => {
|
||||
// Try finding message
|
||||
@ -13,14 +13,18 @@ const saveMessageData = async (id, role, emoji) => {
|
||||
{
|
||||
message: id,
|
||||
role: role.id
|
||||
}, {
|
||||
},
|
||||
{
|
||||
message: id,
|
||||
emoji
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
if (rep !== null) throw new Error(`Existing RoleEmojiPair entry with (partial) data {message:${id},role:${role.id},emoji:${emoji}}!`);
|
||||
if (rep !== null)
|
||||
throw new Error(
|
||||
`Existing RoleEmojiPair entry with (partial) data {message:${id},role:${role.id},emoji:${emoji}}!`
|
||||
);
|
||||
|
||||
// Create database entry for pair
|
||||
await RoleEmojiPair.create({ message: id, role: role.id, emoji });
|
||||
@ -44,7 +48,7 @@ export const addSelfRoles = async (interaction, msgID, role, emoji) => {
|
||||
// Reply successfully to acknowledge command
|
||||
await interaction.reply({
|
||||
content: 'Added new entry for self roles!',
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
console.info(`[INFO] Added new entry to get role with ID '${role.id}' using '${emoji}'.`);
|
||||
@ -54,10 +58,10 @@ export const addSelfRoles = async (interaction, msgID, role, emoji) => {
|
||||
// Reply failed to acknowledge command
|
||||
await interaction.reply({
|
||||
content: `Failed to ${step} message!`,
|
||||
ephemeral: true,
|
||||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
import { join } from 'path';
|
||||
import { readdir } from 'fs/promises';
|
||||
|
||||
@ -66,10 +70,12 @@ const optional = ['autocomplete', 'modalSubmit'];
|
||||
|
||||
export const getFiles = async (dir) => {
|
||||
const dirents = await readdir(dir, { withFileTypes: true });
|
||||
const files = await Promise.all(dirents.map((dirent) => {
|
||||
const files = await Promise.all(
|
||||
dirents.map((dirent) => {
|
||||
const res = join(dir, dirent.name);
|
||||
return dirent.isDirectory() ? getFiles(res) : res;
|
||||
}));
|
||||
})
|
||||
);
|
||||
return Array.prototype.concat(...files);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user