diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9bb08be..49d0534 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,13 @@ - + + + + + + + @@ -43,14 +49,14 @@ - + - + @@ -58,6 +64,9 @@ + + + @@ -90,6 +99,7 @@ + 1640148826800 diff --git a/bot.js b/bot.js index 08eb177..9902744 100644 --- a/bot.js +++ b/bot.js @@ -74,11 +74,8 @@ client.misc = { fullyReady: false }; -//const config = require('./config.js'); const auth = require('./auth.json'); -//client.config = config; - async function init() { const cliargs = new TagFilter([ new Tag(['cli', 'c', 'nc', 'nocli'], 'nocli', 'toggle'), @@ -108,10 +105,6 @@ async function init() { client.misc.startupNoConnect = new Date(); client.config = auth; - client.slash = new SlashManager(client).setTestServer('691122844339404800').importCommands().init(); - client.slash.register(); - client = client.slash.client; - let mloginsp = ora(chalk.magentaBright('Connecting to Mongo client...')).start(); let pmcc = new Date().getTime(); const config = client.config; @@ -140,6 +133,8 @@ async function init() { client.utils.c = (text, a=true) => `${text.slice(0, 1).toUpperCase()}${a ? text.slice(1).toLowerCase() : text.slice(1)}`; client.utils.ca = (text, a=true) => text.split(/\s+/gm).map(t => client.utils.c(t, a)).join(" "); client.utils.sm = (mpr, ago=true) => `${mpr.years ? `${mpr.years} year${client.utils.s(mpr.years)} ` : ''}${mpr.months ? `${mpr.months} month${client.utils.s(mpr.months)} ` : ''}${mpr.days} day${client.utils.s(mpr.days)}${ago ? ' ago' : ''}`; + client.utils.p = (text) => text.endsWith('s') ? "'" : "'s"; + client.utils.ps = (text) => `${text}${client.utils.p(text)}`; ['commands', 'aliases', 'executables'].forEach(x => client[x] = new Discord.Collection()); client.responses = {triggers: [], commands: new Discord.Collection()}; @@ -151,7 +146,19 @@ async function init() { .map(i => client.misc.config.gradients ? gs.instagram(i) : chalk.blue(i)) .forEach((i, ind) => client.misc.cache.spin.add(iters[ind], {text: i})); } + for (let i = 0; i < iters.length; i++) {let x = iters[i]; await require(`./handle/${x}`)(client);} + const spl = client.misc.config.spinners ? (i) => client.misc.cache.spinLog.push(i) : (i) => console.log(i); + spl(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Slash Commands...')}\n`); + client.slash = new SlashManager(client) + .setTestServer('691122844339404800') + .importCommands(false, undefined, (cmd) => spl(`${chalk.gray('[LOAD]')} >> ${chalk.blueBright('Loaded Slash Command')} ${chalk.white(cmd.name)}`)) + .init(); + if (client.misc.config.dev) {await client.slash.devRegister();} + else {await client.slash.register();} + client = client.slash.client; + spl(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Loaded all Slash Commands')}`); + if (client.misc.config.spinners) { client.misc.cache.spinLog.forEach(log => console.log(log)); } diff --git a/events/ready.js b/events/ready.js index c9ebabe..752a590 100644 --- a/events/ready.js +++ b/events/ready.js @@ -21,9 +21,6 @@ module.exports = async client => { const config = client.config; - /*let db = mongoose.connection; - await db.guild.update({}, {"$set": {'prefix': ''}}, false, true);*/ - console.log(`\n${chalk.green('[BOOT]')} >> [${moment().format('L LTS')}] -> ${chalk.greenBright("Connected to Discord")}.`); let date = new Date; date = date.toString().slice(date.toString().search(":") - 2, date.toString().search(":") + 6); console.log(`\n${chalk.gray('[INFO]')} >> ${chalk.white(`Logged in at ${date}.`)}`); diff --git a/slash/8ball.js b/slash/fun/8ball.js similarity index 96% rename from slash/8ball.js rename to slash/fun/8ball.js index 3c03a55..b8063b9 100644 --- a/slash/8ball.js +++ b/slash/fun/8ball.js @@ -1,35 +1,35 @@ -const {SlashCommand} = require('../util/slash'); -const {SlashCommandBuilder} = require('@discordjs/builders'); -const Discord = require('discord.js'); - -module.exports = (client) => { - return new SlashCommand('8ball', client, - new SlashCommandBuilder() - .setName('8ball') - .setDescription("Get a totally accurate and well-thought-out answer to your life's troubles.") - .addStringOption(option => { - return option.setName("question") - .setDescription("Your existential crisis.") - .setRequired(true); - }) - .addBooleanOption(option => { - return option.setName("send") - .setDescription("Should I send the answer to the channel?"); - }), - - async (client, interaction) => { - const responses = [ - /*Positive Responses*/ "Yes!", "I think so", "Possibly", "Certainly", "Definitely", "Absolutely", "Sure!", "Most Likely", "I believe so", "If you're asking for my honest opinion... yes" - /*Negative Responses*/ ,"No!", "I don't think so", "Probably not", "Impossible", "Nope", "Absolutely *not*", "Nah", "Doubt it", "I don't believe so", "If you're asking for my honest opinion... no" - /*Neutral Responses */ ,"Maybe", "I'm not sure", "I'll think about it", "Uhh Natsuki isn't here right now. I can take a message?", "I'm sure if you look deep within your heart, which is currently all over that tree, you'll find the answer", "I mean, if you think so...", "I don't have an opinion on that.", "I'll choose to remain silent." - ]; - return await interaction.reply({embeds: [new Discord.MessageEmbed() - .setAuthor({name: "8ball Question", iconURL: interaction.user.displayAvatarURL()}) - .setDescription("**Question:** " + interaction.options.getString('question') + "\n**Answer:** " + responses[Math.floor(Math.random() * responses.length)]) - .setColor("c375f0") - .setFooter({text: `Asked by ${interaction.guild ? interaction.member.displayName : interaction.user.username} | Natsuki`}) - .setTimestamp() - ], ephemeral: !interaction.options.getBoolean("send")}); - } - ); +const {SlashCommand} = require('../../util/slash'); +const {SlashCommandBuilder} = require('@discordjs/builders'); +const Discord = require('discord.js'); + +module.exports = (client) => { + return new SlashCommand('8ball', client, + new SlashCommandBuilder() + .setName('8ball') + .setDescription("Get a totally accurate and well-thought-out answer to your life's troubles.") + .addStringOption(option => { + return option.setName("question") + .setDescription("Your existential crisis.") + .setRequired(true); + }) + .addBooleanOption(option => { + return option.setName("send") + .setDescription("Should I send the answer to the channel?"); + }), + + async (client, interaction) => { + const responses = [ + /*Positive Responses*/ "Yes!", "I think so", "Possibly", "Certainly", "Definitely", "Absolutely", "Sure!", "Most Likely", "I believe so", "If you're asking for my honest opinion... yes" + /*Negative Responses*/ ,"No!", "I don't think so", "Probably not", "Impossible", "Nope", "Absolutely *not*", "Nah", "Doubt it", "I don't believe so", "If you're asking for my honest opinion... no" + /*Neutral Responses */ ,"Maybe", "I'm not sure", "I'll think about it", "Uhh Natsuki isn't here right now. I can take a message?", "I'm sure if you look deep within your heart, which is currently all over that tree, you'll find the answer", "I mean, if you think so...", "I don't have an opinion on that.", "I'll choose to remain silent." + ]; + return await interaction.reply({embeds: [new Discord.MessageEmbed() + .setAuthor({name: "8ball Question", iconURL: interaction.user.displayAvatarURL()}) + .setDescription("**Question:** " + interaction.options.getString('question') + "\n**Answer:** " + responses[Math.floor(Math.random() * responses.length)]) + .setColor("c375f0") + .setFooter({text: `Asked by ${interaction.guild ? interaction.member.displayName : interaction.user.username} | Natsuki`}) + .setTimestamp() + ], ephemeral: !interaction.options.getBoolean("send")}); + } + ); }; \ No newline at end of file diff --git a/util/slashmanager.d.ts b/util/slashmanager.d.ts index a273946..fc1eb3b 100644 --- a/util/slashmanager.d.ts +++ b/util/slashmanager.d.ts @@ -21,7 +21,7 @@ export declare class SlashManager { setAfterHandle(execute: (client: Discord.Client, interaction: Discord.CommandInteraction, success: Boolean) => any): SlashManager; setTestServer(id: string): SlashManager; private handle; - importCommands(dir?: string): SlashManager; + importCommands(register?: boolean | RegisterMode, dir?: string, log?: (command: SlashCommand, manager: SlashManager) => void): SlashManager; } declare type CommandLookup = SlashCommand[] | SlashCommand | string | string[]; export {}; diff --git a/util/slashmanager.js b/util/slashmanager.js index d4b392a..e45435b 100644 --- a/util/slashmanager.js +++ b/util/slashmanager.js @@ -123,12 +123,19 @@ class SlashManager { this.afterHandle(this.client, interaction, success); } ; - importCommands(dir) { - dir = dir || './slash'; - const commands = fs.readdirSync(dir).filter(file => file.endsWith('.js')); - for (const command of commands) { - this.add(require(`../${dir}/${command}`)(this.client)); - } + importCommands(register = false, dir = './slash', log = () => { }) { + const search = (toSearch) => { + let cdir = fs.readdirSync(toSearch); + const commands = cdir.filter(file => file.endsWith('.js')); + for (const command of commands) { + const slashCommand = require(`../${toSearch}/${command}`)(this.client); + this.add(slashCommand, register); + log(slashCommand, this); + } + const subdirs = cdir.filter(file => fs.lstatSync(`${toSearch}/${file}`).isDirectory()); + subdirs.forEach(subdir => search(`${toSearch}/${subdir}`)); + }; + search(dir); return this; } ; diff --git a/util/ts/slashmanager.ts b/util/ts/slashmanager.ts index 5b9fd04..0b9976b 100644 --- a/util/ts/slashmanager.ts +++ b/util/ts/slashmanager.ts @@ -115,12 +115,19 @@ export class SlashManager { - public importCommands(dir?: string): SlashManager { - dir = dir || './slash'; - const commands = fs.readdirSync(dir).filter(file => file.endsWith('.js')); - for (const command of commands) { - this.add(require(`../${dir}/${command}`)(this.client)); - } + public importCommands(register: boolean | RegisterMode = false, dir: string = './slash', log: (command: SlashCommand, manager: SlashManager) => void = () => {}): SlashManager { + const search = (toSearch: string): void => { + let cdir = fs.readdirSync(toSearch); + const commands = cdir.filter(file => file.endsWith('.js')); + for (const command of commands) { + const slashCommand = require(`../${toSearch}/${command}`)(this.client); + this.add(slashCommand, register); + log(slashCommand, this); + } + const subdirs = cdir.filter(file => fs.lstatSync(`${toSearch}/${file}`).isDirectory()); + subdirs.forEach(subdir => search(`${toSearch}/${subdir}`)); + }; + search(dir); return this; };