From 1083262fae71a6ac8dbaf0af8055333612e109fc Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 13 Feb 2025 15:38:42 -0700 Subject: [PATCH] v2 fixes --- .gitignore | 2 +- bot.js | 19 ++-- package-lock.json | 30 ++--- package.json | 2 +- .../runtime/commands/bot/commands.js.test | 0 .../runtime/commands/bot/ping.js | 0 .../runtime/events/messageCreate.js | 78 ++++++------- src/{handle => bot}/runtime/events/ready.js | 18 +-- .../startup/collect/commands.js | 104 +++++++++--------- src/{handle => bot}/startup/collect/events.js | 88 +++++++-------- src/{handle => bot}/startup/run/collect.js | 14 +-- src/{handle => bot}/startup/run/getflags.js | 38 +++---- src/{handle => bot}/startup/run/hello.js | 22 ++-- src/{handle => bot}/startup/run/login.js | 42 +++---- src/{handle => bot}/startup/run/setstatus.js | 82 +++++++------- src/db/connect.js | 2 +- 16 files changed, 263 insertions(+), 278 deletions(-) rename src/{handle => bot}/runtime/commands/bot/commands.js.test (100%) rename src/{handle => bot}/runtime/commands/bot/ping.js (100%) rename src/{handle => bot}/runtime/events/messageCreate.js (98%) rename src/{handle => bot}/runtime/events/ready.js (97%) rename src/{handle => bot}/startup/collect/commands.js (96%) rename src/{handle => bot}/startup/collect/events.js (95%) rename src/{handle => bot}/startup/run/collect.js (95%) rename src/{handle => bot}/startup/run/getflags.js (97%) rename src/{handle => bot}/startup/run/hello.js (98%) rename src/{handle => bot}/startup/run/login.js (97%) rename src/{handle => bot}/startup/run/setstatus.js (98%) diff --git a/.gitignore b/.gitignore index ae3054f..3418c03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules/ -auth.json +src/json/auth.json test.js /.idea/ diff --git a/bot.js b/bot.js index 25dda43..a8b2600 100644 --- a/bot.js +++ b/bot.js @@ -1,10 +1,6 @@ const Discord = require('discord.js'); -const auth = require('./src/json/auth.json'); -const config = require('./src/json/config.json'); -const randresp = require('./src/json/randresp.json'); const errorhandler = require('./src/util/log/errorhandler'); - const log = require('./src/util/log/log'); const flags = Discord.GatewayIntentBits; @@ -14,11 +10,12 @@ const client = new Discord.Client({intents: fl, partials: [partials.Channel, par // a "fuck v14" counter is gonna be here real soon i can feel it. //fuck new embeds + const startBot = async () => { - client.config = config; - client.auth = auth; - client.config.randResp = randresp; + client.config = require('./src/json/config.json'); + client.auth = require('./src/json/auth.json'); + client.config.randResp = require('./src/json/randresp.json'); require('./src/util/misc/setutils')(client); // add some basic swiss army knife utils @@ -27,13 +24,13 @@ const startBot = async () => { client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: client.config.bot.consoleName}, true, true); //natsuki's wakeup log - require('./src/handle/startup/run/getflags')(client); + require('./src/bot/startup/run/getflags')(client); await require('./src/db/connect')(client); //connect to database - await require('./src/handle/startup/run/collect')(client); //load in commands and events - await require('./src/handle/startup/run/login')(client); //log in to discord + await require('./src/bot/startup/run/collect')(client); //load in commands and events + await require('./src/bot/startup/run/login')(client); //log in to discord - require('./src/util/misc/nodehandlers')(client); //handle uncaught promises, warnings, event loop shenanigans + require('./src/util/misc/nodehandlers')(client); //bot uncaught promises, warnings, event loop shenanigans }; startBot().catch(e => errorhandler(client, e)); // TODO add a .catch() and flag to recover the process diff --git a/package-lock.json b/package-lock.json index 1a80d3d..5ca9f1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "dreidels": "^0.6.1", "express": "^4.21.2", "fuzzysort": "^3.1.0", - "gradient-string": "^3.0.0", + "gradient-string": "^2.0.2", "lastfm": "^0.9.4", "moment": "^2.30.1", "moment-precise-range-plugin": "^1.3.0", @@ -414,9 +414,9 @@ } }, "node_modules/chalk": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", - "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", @@ -971,28 +971,16 @@ } }, "node_modules/gradient-string": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/gradient-string/-/gradient-string-3.0.0.tgz", - "integrity": "sha512-frdKI4Qi8Ihp4C6wZNB565de/THpIaw3DjP5ku87M+N9rNSGmPTjfkq61SdRXB7eCaL8O1hkKDvf6CDMtOzIAg==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/gradient-string/-/gradient-string-2.0.2.tgz", + "integrity": "sha512-rEDCuqUQ4tbD78TpzsMtt5OIf0cBCSDWSJtUDaF6JsAh+k0v9r++NzxNEG87oDZx9ZwGhD8DaezR2L/yrw0Jdw==", "license": "MIT", "dependencies": { - "chalk": "^5.3.0", + "chalk": "^4.1.2", "tinygradient": "^1.1.5" }, "engines": { - "node": ">=14" - } - }, - "node_modules/gradient-string/node_modules/chalk": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.4.1.tgz", - "integrity": "sha512-zgVZuo2WcZgfUEmsn6eO3kINexW8RAE4maiQ8QNs8CtpPCSyMiYsULR3HQYkm3w8FIA3SberyMJMSldGsW+U3w==", - "license": "MIT", - "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "node": ">=10" } }, "node_modules/gradient-string/node_modules/tinygradient": { diff --git a/package.json b/package.json index 781ad78..d7da154 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "dreidels": "^0.6.1", "express": "^4.21.2", "fuzzysort": "^3.1.0", - "gradient-string": "^3.0.0", + "gradient-string": "^2.0.2", "lastfm": "^0.9.4", "moment": "^2.30.1", "moment-precise-range-plugin": "^1.3.0", diff --git a/src/handle/runtime/commands/bot/commands.js.test b/src/bot/runtime/commands/bot/commands.js.test similarity index 100% rename from src/handle/runtime/commands/bot/commands.js.test rename to src/bot/runtime/commands/bot/commands.js.test diff --git a/src/handle/runtime/commands/bot/ping.js b/src/bot/runtime/commands/bot/ping.js similarity index 100% rename from src/handle/runtime/commands/bot/ping.js rename to src/bot/runtime/commands/bot/ping.js diff --git a/src/handle/runtime/events/messageCreate.js b/src/bot/runtime/events/messageCreate.js similarity index 98% rename from src/handle/runtime/events/messageCreate.js rename to src/bot/runtime/events/messageCreate.js index 42fc357..0b82bf9 100644 --- a/src/handle/runtime/events/messageCreate.js +++ b/src/bot/runtime/events/messageCreate.js @@ -1,40 +1,40 @@ -const chalk = require('chalk'); -const {Embed, EmbedBuilder} = require('discord.js'); - -module.exports = async (client, message) => { - if (!message.content || !message.content.length) {return;} //privileged intent fallback //TODO edit for privileged intent - - let prefix = client.basePrefix; //TODO prefixes - - if ([`<@${client.user.id}>`, `<@!${client.user.id}>`].includes(message.content.trim())) { //Ping hello - message.channel.send({embeds: [new EmbedBuilder() - .setTitle(client.utils.gr(client.config.randResp.pinghello)) - .setDescription(`You've reached ${client.config.options.dev ? "a developer (beta) instance of" : ''} Natsuki! My prefix here is \`${prefix}\`, and you can use the \`help\` command to get started.`) - .setColor('c375f0') - .setFooter({text: "Natsuki", iconURL: client.user.avatarURL()}) - ]}); - } - - let cmd = {}; - cmd.msg = message.content.toLowerCase().trim(); //i believe in shitty naming conventions :D - - let prefixUsed = cmd.msg.startsWith(client.basePrefix) ? client.basePrefix //stamdard default/dev client prefix - : cmd.msg.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}>` //mention prefix - : cmd.msg.startsWith(`<@!${client.user.id}>`) ? `<@!${client.user.id}>` //nicknamed mention prefix - : null //no prefix used - - cmd.prefix = prefixUsed; - - if (!cmd.prefix) {return;} // ----------> PREFIXED GATEWAY <---------- - - cmd.msg = cmd.msg.slice(prefixUsed.length); - let args = cmd.msg.split(/\s+/gm); //"args" is split by ALL WHITESPACE AND IS LOWERCASED - cmd.name = args.shift(); //the command without the prefix - cmd.msg = args.join(" "); - cmd.args = message.content.trim().slice(prefixUsed.length).trim().split(/ +/gm).slice(1); //args but preserves text state and newlines - - let cmdToRun = client.commands.get(cmd.name) || client.commands.get(client.aliases.get(cmd.name)); - if (!cmdToRun) {return;} - try {cmdToRun.run(client, message, args, cmd).catch(e => client.error(`There was an error in the ${cmdToRun.name} command.`, 0, 1, e, '\n'));} - catch (e) {client.error(`There was an error in the ${cmdToRun.name} command.`, 0, 1, e, '\n');} +const chalk = require('chalk'); +const {Embed, EmbedBuilder} = require('discord.js'); + +module.exports = async (client, message) => { + if (!message.content || !message.content.length) {return;} //privileged intent fallback //TODO edit for privileged intent + + let prefix = client.basePrefix; //TODO prefixes + + if ([`<@${client.user.id}>`, `<@!${client.user.id}>`].includes(message.content.trim())) { //Ping hello + message.channel.send({embeds: [new EmbedBuilder() + .setTitle(client.utils.gr(client.config.randResp.pinghello)) + .setDescription(`You've reached ${client.config.options.dev ? "a developer (beta) instance of" : ''} Natsuki! My prefix here is \`${prefix}\`, and you can use the \`help\` command to get started.`) + .setColor('c375f0') + .setFooter({text: "Natsuki", iconURL: client.user.avatarURL()}) + ]}); + } + + let cmd = {}; + cmd.msg = message.content.toLowerCase().trim(); //i believe in shitty naming conventions :D + + let prefixUsed = cmd.msg.startsWith(client.basePrefix) ? client.basePrefix //stamdard default/dev client prefix + : cmd.msg.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}>` //mention prefix + : cmd.msg.startsWith(`<@!${client.user.id}>`) ? `<@!${client.user.id}>` //nicknamed mention prefix + : null //no prefix used + + cmd.prefix = prefixUsed; + + if (!cmd.prefix) {return;} // ----------> PREFIXED GATEWAY <---------- + + cmd.msg = cmd.msg.slice(prefixUsed.length); + let args = cmd.msg.split(/\s+/gm); //"args" is split by ALL WHITESPACE AND IS LOWERCASED + cmd.name = args.shift(); //the command without the prefix + cmd.msg = args.join(" "); + cmd.args = message.content.trim().slice(prefixUsed.length).trim().split(/ +/gm).slice(1); //args but preserves text state and newlines + + let cmdToRun = client.commands.get(cmd.name) || client.commands.get(client.aliases.get(cmd.name)); + if (!cmdToRun) {return;} + try {cmdToRun.run(client, message, args, cmd).catch(e => client.error(`There was an error in the ${cmdToRun.name} command.`, 0, 1, e, '\n'));} + catch (e) {client.error(`There was an error in the ${cmdToRun.name} command.`, 0, 1, e, '\n');} }; \ No newline at end of file diff --git a/src/handle/runtime/events/ready.js b/src/bot/runtime/events/ready.js similarity index 97% rename from src/handle/runtime/events/ready.js rename to src/bot/runtime/events/ready.js index 941f914..2fdba35 100644 --- a/src/handle/runtime/events/ready.js +++ b/src/bot/runtime/events/ready.js @@ -1,10 +1,10 @@ -module.exports = async client => { - client.basePrefix = client.config.options.dev ? client.config.options.prefix || client.config.bot.devPrefix : client.config.bot.prefix; - - await require('../../../api/index')(client); - - require('../../startup/run/hello')(client); // startup info - require('../../startup/run/setstatus')(client); - - client.log(client.utils.gr(client.config.randResp.cliloaded), {color: "#78d9f8", source: client.config.bot.consoleName}, true, true); //natsuki doing some more complaining +module.exports = async client => { + client.basePrefix = client.config.options.dev ? client.config.options.prefix || client.config.bot.devPrefix : client.config.bot.prefix; + + await require('../../../api/index')(client); + + require('../../startup/run/hello')(client); // startup info + require('../../startup/run/setstatus')(client); + + client.log(client.utils.gr(client.config.randResp.cliloaded), {color: "#78d9f8", source: client.config.bot.consoleName}, true, true); //natsuki doing some more complaining }; \ No newline at end of file diff --git a/src/handle/startup/collect/commands.js b/src/bot/startup/collect/commands.js similarity index 96% rename from src/handle/startup/collect/commands.js rename to src/bot/startup/collect/commands.js index 38b0985..5d9d02f 100644 --- a/src/handle/startup/collect/commands.js +++ b/src/bot/startup/collect/commands.js @@ -1,53 +1,53 @@ -const fs = require('fs'); -const chalk = require('chalk'); -const {Collection} = require('discord.js'); - -const commandsDirName = './src/handle/runtime/commands'; - -module.exports = async client => { - client.aliases = new Collection(); - - let dirErrors = []; let fileErrors = []; //collect error objects to output them all at the end - let readDirs = []; //list of dirs to print at the end - let conflictingAliases = {}; - client.log('Loading commands...', {source: 'boot', color: 'blue'}, 0, 1); - const readDir = dir => { //when you're trying to comment your code but realize you have good variable naming for once and don't need to :D - let dirRead; - try {dirRead = fs.readdirSync(dir);} - catch (e) { - client.error(`Failed to read directory ${chalk.white(dir)}`); - return dirErrors.push([`Unable to read directory ${chalk.white(dir)}. Error:`, e]); - } - let files = dirRead.filter(item => item.endsWith('.js')); - let folders = dirRead.filter(item => fs.lstatSync(`${dir}/${item}`).isDirectory()); - files.forEach(file => { - try { - const command = require(`../../../../${dir.slice(2)}/${file}`); - client.commands.set(command.name, command); - if (command.aliases) {command.aliases.forEach(alias => { - if (client.aliases.has(alias)) { - if (conflictingAliases[alias]) {conflictingAliases[alias].push(command.name);} //object of alias conflictions keyed by alias -> by array[command names] - else {conflictingAliases[alias] = [command.name];} - } - client.aliases.set(alias, command.name); - });} - client.log(`Loaded ${chalk.white(command.name)} with ${chalk.white(`${command.aliases ? command.aliases.length : 0}`)} alias${command.aliases && command.aliases.length === 1 ? '' : 'es'}.`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); - } - catch (e) { - client.error(`Failed to read file ${chalk.white(file)}`); - return fileErrors.push([`Unable to read file ${chalk.white(file)}. Error:`, e]); - } - }); - readDirs.push(`${dir.split('/').slice(4).join('/')}/`); // "commands/..." - return folders.forEach(folder => readDir(`${dir}/${folder}`)); //recurse infinitely - }; - readDir(commandsDirName); - console.log(""); - dirErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); - fileErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); - readDirs.forEach(dir => client.log(`Read from directory ${chalk.green(dir)}`, {source: 'proc'})); - console.log(''); - Object.keys(conflictingAliases).forEach(alias => client.warn(`Alias ${chalk.white(alias)} appears on ${client.utils.as(conflictingAliases[alias].length, 'command')} ${chalk.white(conflictingAliases[alias].join(chalk.yellow(', ')))}`)); - if (Object.keys(conflictingAliases).length) {console.log('')}; - client.log(`Loaded ${chalk.white(client.commands.size)} command${client.utils.s(client.commands.size)}!`, {color: 'blue', source: 'boot'}, 0, 1); +const fs = require('fs'); +const chalk = require('chalk'); +const {Collection} = require('discord.js'); + +const commandsDirName = './src/bot/runtime/commands'; + +module.exports = async client => { + client.aliases = new Collection(); + + let dirErrors = []; let fileErrors = []; //collect error objects to output them all at the end + let readDirs = []; //list of dirs to print at the end + let conflictingAliases = {}; + client.log('Loading commands...', {source: 'boot', color: 'blue'}, 0, 1); + const readDir = dir => { //when you're trying to comment your code but realize you have good variable naming for once and don't need to :D + let dirRead; + try {dirRead = fs.readdirSync(dir);} + catch (e) { + client.error(`Failed to read directory ${chalk.white(dir)}`); + return dirErrors.push([`Unable to read directory ${chalk.white(dir)}. Error:`, e]); + } + let files = dirRead.filter(item => item.endsWith('.js')); + let folders = dirRead.filter(item => fs.lstatSync(`${dir}/${item}`).isDirectory()); + files.forEach(file => { + try { + const command = require(`../../../../${dir.slice(2)}/${file}`); + client.commands.set(command.name, command); + if (command.aliases) {command.aliases.forEach(alias => { + if (client.aliases.has(alias)) { + if (conflictingAliases[alias]) {conflictingAliases[alias].push(command.name);} //object of alias conflictions keyed by alias -> by array[command names] + else {conflictingAliases[alias] = [command.name];} + } + client.aliases.set(alias, command.name); + });} + client.log(`Loaded ${chalk.white(command.name)} with ${chalk.white(`${command.aliases ? command.aliases.length : 0}`)} alias${command.aliases && command.aliases.length === 1 ? '' : 'es'}.`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); + } + catch (e) { + client.error(`Failed to read file ${chalk.white(file)}`); + return fileErrors.push([`Unable to read file ${chalk.white(file)}. Error:`, e]); + } + }); + readDirs.push(`${dir.split('/').slice(4).join('/')}/`); // "commands/..." + return folders.forEach(folder => readDir(`${dir}/${folder}`)); //recurse infinitely + }; + readDir(commandsDirName); + console.log(""); + dirErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); + fileErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); + readDirs.forEach(dir => client.log(`Read from directory ${chalk.green(dir)}`, {source: 'proc'})); + console.log(''); + Object.keys(conflictingAliases).forEach(alias => client.warn(`Alias ${chalk.white(alias)} appears on ${client.utils.as(conflictingAliases[alias].length, 'command')} ${chalk.white(conflictingAliases[alias].join(chalk.yellow(', ')))}`)); + if (Object.keys(conflictingAliases).length) {console.log('')}; + client.log(`Loaded ${chalk.white(client.commands.size)} command${client.utils.s(client.commands.size)}!`, {color: 'blue', source: 'boot'}, 0, 1); }; \ No newline at end of file diff --git a/src/handle/startup/collect/events.js b/src/bot/startup/collect/events.js similarity index 95% rename from src/handle/startup/collect/events.js rename to src/bot/startup/collect/events.js index d7a88bd..ff9906e 100644 --- a/src/handle/startup/collect/events.js +++ b/src/bot/startup/collect/events.js @@ -1,45 +1,45 @@ -const fs = require('fs'); -const chalk = require('chalk'); -const {Collection} = require('discord.js'); - -const eventsDirName = './src/handle/runtime/events'; - -module.exports = async client => { - client.aliases = new Collection(); - - let dirErrors = []; let fileErrors = []; //collect error objects to output them all at the end - let readDirs = []; //list of dirs to print at the end - let totalEvents = 0; - client.log('Loading events...', {source: 'boot', color: 'blue'}, 0, 1); - const readDir = dir => { - let dirRead; - try {dirRead = fs.readdirSync(dir);} - catch (e) { - client.error(`Failed to read directory ${chalk.white(dir)}`); - return dirErrors.push([`Unable to read directory ${chalk.white(dir)}. Error:`, e]); - } - let files = dirRead.filter(item => item.endsWith('.js')); - let folders = dirRead.filter(item => fs.lstatSync(`${dir}/${item}`).isDirectory()); - files.forEach(file => { - try { - const event = require(`../../../../${dir.slice(2)}/${file}`); - const eventName = file.split('.')[0]; - client.removeAllListeners(eventName); - client.on(eventName, event.bind(null, client)); - client.log(`Loaded event ${chalk.white(eventName)}`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); - } - catch (e) { - client.error(`Failed to read file ${chalk.white(file)}`); - return fileErrors.push([`Unable to read file ${chalk.white(file)}. Error:`, e]); - } - }); - readDirs.push(`${dir.split('/').slice(4).join('/')}/`); // "events/..." - return folders.forEach(folder => readDir(`${dir}/${folder}`)); //recurse infinitely - }; - readDir(eventsDirName); - console.log(""); - dirErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); - fileErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); - readDirs.forEach(dir => client.log(`Read from directory ${chalk.green(dir)}`, {source: 'proc'})); - client.log(`Loaded ${chalk.white(totalEvents)} event${client.utils.s(totalEvents)}!`, {color: 'blue', source: 'boot'}, 1, 1); +const fs = require('fs'); +const chalk = require('chalk'); +const {Collection} = require('discord.js'); + +const eventsDirName = './src/bot/runtime/events'; + +module.exports = async client => { + client.aliases = new Collection(); + + let dirErrors = []; let fileErrors = []; //collect error objects to output them all at the end + let readDirs = []; //list of dirs to print at the end + let totalEvents = 0; + client.log('Loading events...', {source: 'boot', color: 'blue'}, 0, 1); + const readDir = dir => { + let dirRead; + try {dirRead = fs.readdirSync(dir);} + catch (e) { + client.error(`Failed to read directory ${chalk.white(dir)}`); + return dirErrors.push([`Unable to read directory ${chalk.white(dir)}. Error:`, e]); + } + let files = dirRead.filter(item => item.endsWith('.js')); + let folders = dirRead.filter(item => fs.lstatSync(`${dir}/${item}`).isDirectory()); + files.forEach(file => { + try { + const event = require(`../../../../${dir.slice(2)}/${file}`); + const eventName = file.split('.')[0]; + client.removeAllListeners(eventName); + client.on(eventName, event.bind(null, client)); + client.log(`Loaded event ${chalk.white(eventName)}`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); + } + catch (e) { + client.error(`Failed to read file ${chalk.white(file)}`); + return fileErrors.push([`Unable to read file ${chalk.white(file)}. Error:`, e]); + } + }); + readDirs.push(`${dir.split('/').slice(4).join('/')}/`); // "events/..." + return folders.forEach(folder => readDir(`${dir}/${folder}`)); //recurse infinitely + }; + readDir(eventsDirName); + console.log(""); + dirErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); + fileErrors.forEach(error => client.error(error[0], 0, 0, 1, error[1])); + readDirs.forEach(dir => client.log(`Read from directory ${chalk.green(dir)}`, {source: 'proc'})); + client.log(`Loaded ${chalk.white(totalEvents)} event${client.utils.s(totalEvents)}!`, {color: 'blue', source: 'boot'}, 1, 1); }; \ No newline at end of file diff --git a/src/handle/startup/run/collect.js b/src/bot/startup/run/collect.js similarity index 95% rename from src/handle/startup/run/collect.js rename to src/bot/startup/run/collect.js index fdcc1a1..b5fd53b 100644 --- a/src/handle/startup/run/collect.js +++ b/src/bot/startup/run/collect.js @@ -1,8 +1,8 @@ -const {Collection} = require("discord.js"); - -module.exports = async client => { - ['commands', 'events'].forEach(x => { - client[x] = new Collection(); - require(`../collect/${x}`)(client); - }); +const {Collection} = require("discord.js"); + +module.exports = async client => { + ['commands', 'events'].forEach(x => { + client[x] = new Collection(); + require(`../collect/${x}`)(client); + }); }; \ No newline at end of file diff --git a/src/handle/startup/run/getflags.js b/src/bot/startup/run/getflags.js similarity index 97% rename from src/handle/startup/run/getflags.js rename to src/bot/startup/run/getflags.js index da41420..3e2b7f0 100644 --- a/src/handle/startup/run/getflags.js +++ b/src/bot/startup/run/getflags.js @@ -1,20 +1,20 @@ -const chalk = require('chalk'); - -const {Tag, TagFilter} = require('../../../util/ts/tagfilter'); - -module.exports = client => { - const options = new TagFilter([ - new Tag(['dev', 'd', 'developer', 'test'], 'dev', 'toggle'), - new Tag(['prefix', 'devprefix', 'p'], 'prefix', 'append') - ]).test(process.argv.slice(2).join(" ")); - client.config.options = {}; - - if (Object.keys(options).length) { //log and set options - client.log(`${chalk.gray.bold("Arguments detected.")}`, {source: 'args'}, 0, 1); - Object.keys(options).forEach(arg => { - client.config.options[arg] = options[arg]; - client.log(`${chalk.gray.bold(arg)}${chalk.gray(':')} ${chalk.blue(options[arg])}`, {source: 'args'}); - }); - console.log(''); - } +const chalk = require('chalk'); + +const {Tag, TagFilter} = require('../../../util/ts/tagfilter'); + +module.exports = client => { + const options = new TagFilter([ + new Tag(['dev', 'd', 'developer', 'test'], 'dev', 'toggle'), + new Tag(['prefix', 'devprefix', 'p'], 'prefix', 'append') + ]).test(process.argv.slice(2).join(" ")); + client.config.options = {}; + + if (Object.keys(options).length) { //log and set options + client.log(`${chalk.gray.bold("Arguments detected.")}`, {source: 'args'}, 0, 1); + Object.keys(options).forEach(arg => { + client.config.options[arg] = options[arg]; + client.log(`${chalk.gray.bold(arg)}${chalk.gray(':')} ${chalk.blue(options[arg])}`, {source: 'args'}); + }); + console.log(''); + } }; \ No newline at end of file diff --git a/src/handle/startup/run/hello.js b/src/bot/startup/run/hello.js similarity index 98% rename from src/handle/startup/run/hello.js rename to src/bot/startup/run/hello.js index 651c70e..3d4774d 100644 --- a/src/handle/startup/run/hello.js +++ b/src/bot/startup/run/hello.js @@ -1,12 +1,12 @@ -const moment = require("moment"); -const chalk = require('chalk'); -const os = require('os'); -const gs = require('gradient-string'); - -module.exports = client => { - client.log(`Logged in as ${gs.instagram(client.user.username)}. ${chalk.greenBright(`[${chalk.grey(client.user.id)}]`)}`); - client.log(`Time: ${chalk.blueBright(moment().format('MMMM d, YYYY - HH:MM:SS'))}`); - client.log(`This ${chalk.blue('heap')} has ${chalk.blueBright((process.memoryUsage().heapTotal / (1024 ** 2)).toFixed(2))}MB allocated; The ${chalk.blue('machine')} has ${chalk.blueBright((os.totalmem() / (1024 ** 3)).toFixed(2))}GB (${chalk.blueBright((os.freemem() / (1024 ** 3)).toFixed(2))}GB free)`); - client.log(`Running on ${chalk.blueBright(client.guilds.cache.size)} ${chalk.blue("servers")} and interacting with about ${chalk.blueBright(client.users.cache.size)} ${chalk.blue("users")}.`); - client.log(`Listening for prefix ${chalk.greenBright(client.basePrefix)} || ${chalk.greenBright(`${client.basePrefix}help`)} to get started!`); +const moment = require("moment"); +const chalk = require('chalk'); +const os = require('os'); +const gs = require('gradient-string'); + +module.exports = client => { + client.log(`Logged in as ${gs.instagram(client.user.username)}. ${chalk.greenBright(`[${chalk.grey(client.user.id)}]`)}`); + client.log(`Time: ${chalk.blueBright(moment().format('MMMM d, YYYY - HH:MM:SS'))}`); + client.log(`This ${chalk.blue('heap')} has ${chalk.blueBright((process.memoryUsage().heapTotal / (1024 ** 2)).toFixed(2))}MB allocated; The ${chalk.blue('machine')} has ${chalk.blueBright((os.totalmem() / (1024 ** 3)).toFixed(2))}GB (${chalk.blueBright((os.freemem() / (1024 ** 3)).toFixed(2))}GB free)`); + client.log(`Running on ${chalk.blueBright(client.guilds.cache.size)} ${chalk.blue("servers")} and interacting with about ${chalk.blueBright(client.users.cache.size)} ${chalk.blue("users")}.`); + client.log(`Listening for prefix ${chalk.greenBright(client.basePrefix)} || ${chalk.greenBright(`${client.basePrefix}help`)} to get started!`); }; \ No newline at end of file diff --git a/src/handle/startup/run/login.js b/src/bot/startup/run/login.js similarity index 97% rename from src/handle/startup/run/login.js rename to src/bot/startup/run/login.js index eaa4c5e..ed07dd2 100644 --- a/src/handle/startup/run/login.js +++ b/src/bot/startup/run/login.js @@ -1,21 +1,21 @@ -const chalk = require('chalk'); - -const ora = require('../../../util/log/ora'); - -module.exports = async (client) => { - const t = Date.now(); - client.misc = {}; - client.misc.dscconnected = true; - - await ora(`Waking up Natsuki... ${chalk.blueBright.bold.underline("(Connecting to Discord...)")}`, - client.login(client.auth.token) - ).catch((e) => { - client.error("Failed to connect to Discord!! Error below.", 0, 0, true, e); - client.misc.dscconnected = false; - }); - if (!client.misc.dscconnected) { - client.warn("Discord not connected, considering runtime to be unusable and exiting.", 0, true, true); - throw new Error(); - } - return client.success(`Connected to Discord in ${chalk.white(`${Date.now() - t}ms`)}.`, 0, 0, 1); -}; +const chalk = require('chalk'); + +const ora = require('../../../util/log/ora'); + +module.exports = async (client) => { + const t = Date.now(); + client.misc = {}; + client.misc.dscconnected = true; + + await ora(`Waking up Natsuki... ${chalk.blueBright.bold.underline("(Connecting to Discord...)")}`, + client.login(client.auth.token) + ).catch((e) => { + client.error("Failed to connect to Discord!! Error below.", 0, 0, true, e); + client.misc.dscconnected = false; + }); + if (!client.misc.dscconnected) { + client.warn("Discord not connected, considering runtime to be unusable and exiting.", 0, true, true); + throw new Error(); + } + return client.success(`Connected to Discord in ${chalk.white(`${Date.now() - t}ms`)}.`, 0, 0, 1); +}; diff --git a/src/handle/startup/run/setstatus.js b/src/bot/startup/run/setstatus.js similarity index 98% rename from src/handle/startup/run/setstatus.js rename to src/bot/startup/run/setstatus.js index a4af7cd..47ebae5 100644 --- a/src/handle/startup/run/setstatus.js +++ b/src/bot/startup/run/setstatus.js @@ -1,42 +1,42 @@ -module.exports = client => { - const prefix = client.basePrefix; - const statuses = { - "PLAYING": [ - `with my darling`, 'RAIN: Shadow Lords', "with my waifu", "with the neko formula", - "with magic", "terrible anime games", "anime OSTs at max volume", - `${Math.ceil(Math.random() * 100)} days of trying to become a samurai`, - "with the sauce", "witch hats are >", "explosion magic is the best magic", - "with Kazuma's sanity", "please help i gave myself cat ears", - "starting my own harem", "wor. wor never changes", "a little more UwU than necessary", - "please i just want a cat girl in my life", "i'm your waifu now.", - "i'm in intervention for my neko addiction", "i tried to make a catgirl and broke my staff", - "fluffy tails = drugs", "in a dungeon without wearing my plot armor", - "benefits of Natsuki worship: my beautiful face" - ,`in ${client.guilds.cache.size} servers` - ], - "WATCHING": [ - `for ${client.commands.size} commands`, - "I'm not a bad slime, slurp!", "Lelouch rule the world!", - "a slime somehow start an empire", "a fox-maid get her tail fluffed", - "a raccoon-girl and some guy with a shield", "some chick with unusually red hair", - "Mob hit 100", "a really bad harem anime", "The Black Swordsman", - "The Misfit of Demon King Academy", "Akame ga Kill", "a witch explode a castle", - "Code Geass", "\"did you really think ___ would be enough to kill me?\"", - "hentacle tentai", "JIBUN WO-", "he did it... he actually made risotto", - "sasageyo, sasageyo, chi nto wo sasegeyo", "scientists make nekos real :3", - "yet another isekai don't @ me", "magical girl anime", "episode 1 of One Piece.. pain.", - "a white-haired dude and a goddess with some MELONS" - ,`over ${client.guilds.cache.size} servers` - ] - }; - - try {if (client.misc.statusTimeout) {clearTimeout(client.misc.statusTimeout)};} catch {} - - const setStatus = () => { - let type = Object.keys(statuses)[Math.floor(Math.random() * Object.keys(statuses).length)]; - if (type === "PLAYING") {client.user.setActivity(statuses[type][Math.floor(Math.random() * statuses[type].length)] + " | " + prefix + "help");} - else {client.user.setActivity(statuses[type][Math.floor(Math.random() * statuses[type].length)] + " | " + prefix + "help", {type: type});} - }; - setStatus(); - client.misc.statusTimeout = setTimeout(setStatus, 14400000); +module.exports = client => { + const prefix = client.basePrefix; + const statuses = { + "PLAYING": [ + `with my darling`, 'RAIN: Shadow Lords', "with my waifu", "with the neko formula", + "with magic", "terrible anime games", "anime OSTs at max volume", + `${Math.ceil(Math.random() * 100)} days of trying to become a samurai`, + "with the sauce", "witch hats are >", "explosion magic is the best magic", + "with Kazuma's sanity", "please help i gave myself cat ears", + "starting my own harem", "wor. wor never changes", "a little more UwU than necessary", + "please i just want a cat girl in my life", "i'm your waifu now.", + "i'm in intervention for my neko addiction", "i tried to make a catgirl and broke my staff", + "fluffy tails = drugs", "in a dungeon without wearing my plot armor", + "benefits of Natsuki worship: my beautiful face" + ,`in ${client.guilds.cache.size} servers` + ], + "WATCHING": [ + `for ${client.commands.size} commands`, + "I'm not a bad slime, slurp!", "Lelouch rule the world!", + "a slime somehow start an empire", "a fox-maid get her tail fluffed", + "a raccoon-girl and some guy with a shield", "some chick with unusually red hair", + "Mob hit 100", "a really bad harem anime", "The Black Swordsman", + "The Misfit of Demon King Academy", "Akame ga Kill", "a witch explode a castle", + "Code Geass", "\"did you really think ___ would be enough to kill me?\"", + "hentacle tentai", "JIBUN WO-", "he did it... he actually made risotto", + "sasageyo, sasageyo, chi nto wo sasegeyo", "scientists make nekos real :3", + "yet another isekai don't @ me", "magical girl anime", "episode 1 of One Piece.. pain.", + "a white-haired dude and a goddess with some MELONS" + ,`over ${client.guilds.cache.size} servers` + ] + }; + + try {if (client.misc.statusTimeout) {clearTimeout(client.misc.statusTimeout)};} catch {} + + const setStatus = () => { + let type = Object.keys(statuses)[Math.floor(Math.random() * Object.keys(statuses).length)]; + if (type === "PLAYING") {client.user.setActivity(statuses[type][Math.floor(Math.random() * statuses[type].length)] + " | " + prefix + "help");} + else {client.user.setActivity(statuses[type][Math.floor(Math.random() * statuses[type].length)] + " | " + prefix + "help", {type: type});} + }; + setStatus(); + client.misc.statusTimeout = setTimeout(setStatus, 14400000); }; \ No newline at end of file diff --git a/src/db/connect.js b/src/db/connect.js index 7e794e1..07b3c3b 100644 --- a/src/db/connect.js +++ b/src/db/connect.js @@ -10,7 +10,7 @@ module.exports = async client => { client.misc.dbconnected = true; await ora(chalk.blueBright.bold.underline("Connecting to MongoDB..."), mongoose.connect(`mongodb+srv://${auth.database.user}:${auth.database.password}@${auth.database.cluster}.3jpp4.mongodb.net/test`, { - useFindAndModify: false, useNewUrlParser: true, dbName: auth.database.name, useUnifiedTopology: true, useCreateIndex: true + dbName: auth.database.name //TODO research mongo connect options }) ).catch((e) => { client.error("Failed to connect to mongoose!! Error below.", 0, 0, true, e);