mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-14 15:57:42 +02:00
Yeah, sorry, not a fan
This commit is contained in:
@@ -4,7 +4,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const Registry = require('./Registry');
|
||||
const SlashRegistry = require('./slash/SlashRegistry');
|
||||
const Dispatcher = require('./Dispatcher');
|
||||
require('./Extensions');
|
||||
|
||||
@@ -17,7 +16,6 @@ module.exports = class CommandClient extends Client {
|
||||
this.owner = typeof options.owner === 'string' ? [options.owner] : options.owner;
|
||||
this.invite = options.invite || null;
|
||||
this.registry = new Registry(this);
|
||||
this.slashRegistry = new SlashRegistry(this);
|
||||
this.dispatcher = new Dispatcher(this);
|
||||
this.games = new Collection();
|
||||
this.blacklist = { user: [], guild: [] };
|
||||
@@ -25,7 +23,6 @@ module.exports = class CommandClient extends Client {
|
||||
|
||||
this.once('ready', this.onceReady);
|
||||
this.on('messageCreate', this.onMessage);
|
||||
this.on('interactionCreate', this.onInteractionCreate);
|
||||
}
|
||||
|
||||
isOwner(user) {
|
||||
@@ -152,27 +149,6 @@ module.exports = class CommandClient extends Client {
|
||||
}
|
||||
}
|
||||
|
||||
async onInteractionCreate(interaction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const { command } = this.slashRegistry.commands.get(interaction.commandName);
|
||||
if (!command) return;
|
||||
|
||||
try {
|
||||
const result = await command.run(interaction);
|
||||
command.uses++;
|
||||
command.lastRun = new Date();
|
||||
this.emit('commandRun', command, result, interaction);
|
||||
} catch (err) {
|
||||
this.emit('commandError', interaction, err);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
} else {
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
importBlacklist() {
|
||||
const read = fs.readFileSync(path.join(__dirname, '..', 'blacklist.json'), { encoding: 'utf8' });
|
||||
const file = JSON.parse(read);
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
module.exports = class SlashCommand {
|
||||
constructor(client, options) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
this.name = options.name.toLowerCase();
|
||||
this.description = options.description;
|
||||
this.nsfw = options.nsfw || false;
|
||||
this.guildOnly = options.guildOnly || false;
|
||||
this.credit = options.credit || [];
|
||||
this.credit.push({
|
||||
name: 'Dragon Fire',
|
||||
url: 'https://github.com/dragonfire535',
|
||||
reason: 'Code'
|
||||
});
|
||||
this.uses = 0;
|
||||
this.lastRun = null;
|
||||
}
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
const { SlashCommandBuilder, Routes } = require('discord.js');
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { TEST_GUILD_ID } = process.env;
|
||||
|
||||
module.exports = class SlashRegistry {
|
||||
constructor(client) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
this.commands = new Collection();
|
||||
}
|
||||
|
||||
registerCommand(command) {
|
||||
const slashCmd = new SlashCommandBuilder()
|
||||
.setName(command.name)
|
||||
.setDescription(command.description);
|
||||
if (command.guildOnly) slashCmd.setDMPermission(false);
|
||||
if (command.nsfw) slashCmd.setNSFW(true);
|
||||
this.commands.set(command.name, { command, data: slashCmd });
|
||||
return this;
|
||||
}
|
||||
|
||||
registerCommandsIn(dir) {
|
||||
const commands = fs.readdirSync(dir);
|
||||
for (const command of commands) {
|
||||
if (!command.endsWith('.js')) continue;
|
||||
const Required = require(path.join(dir, command));
|
||||
this.registerCommand(new Required(this.client));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
uploadTestCommands() {
|
||||
return this.client.rest.put(
|
||||
Routes.applicationGuildCommands(this.client.user.id, TEST_GUILD_ID),
|
||||
{ body: this.commands.map(cmd => cmd.data.toJSON()) }
|
||||
);
|
||||
}
|
||||
|
||||
uploadGlobalCommands() {
|
||||
return this.client.rest.put(
|
||||
Routes.applicationCommands(this.client.user.id),
|
||||
{ body: this.commands.map(cmd => cmd.data.toJSON()) }
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user