From e3eb892ee41d85448e3c77d21995e398d91523c3 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Tue, 17 Jan 2023 15:27:51 -0500 Subject: [PATCH] 1st command --- src/handle/runtime/commands/bot/ping.js | 7 +++++++ src/handle/runtime/events/messageCreate.js | 7 +++++++ src/handle/runtime/events/ready.js | 2 +- src/handle/startup/collect/commands.js | 3 ++- src/handle/startup/collect/events.js | 2 +- src/handle/startup/run/hello.js | 3 ++- src/json/config.json | 21 +++++++++++++++++---- 7 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 src/handle/runtime/commands/bot/ping.js diff --git a/src/handle/runtime/commands/bot/ping.js b/src/handle/runtime/commands/bot/ping.js new file mode 100644 index 0000000..b877d3d --- /dev/null +++ b/src/handle/runtime/commands/bot/ping.js @@ -0,0 +1,7 @@ +module.exports = { + name: "ping", + aliases: ["p"], + async run(client, message, args, cmd) { + message.reply("Pong! This is Natsuki v2 you're speaking with \\*tips hat*"); + } +}; \ No newline at end of file diff --git a/src/handle/runtime/events/messageCreate.js b/src/handle/runtime/events/messageCreate.js index 4322192..6e9eac2 100644 --- a/src/handle/runtime/events/messageCreate.js +++ b/src/handle/runtime/events/messageCreate.js @@ -1,3 +1,5 @@ +const chalk = require('chalk'); + module.exports = async (client, message) => { if (!message.content || !message.content.length) {return;} //privileged intent fallback @@ -20,4 +22,9 @@ module.exports = async (client, message) => { 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/handle/runtime/events/ready.js index a7898a5..35a0d47 100644 --- a/src/handle/runtime/events/ready.js +++ b/src/handle/runtime/events/ready.js @@ -1,5 +1,5 @@ module.exports = async client => { - client.basePrefix = client.config.options.dev ? client.config.options.prefix || "n!" : "n?"; + client.basePrefix = client.config.options.dev ? client.config.options.prefix || client.config.bot.devPrefix : client.config.bot.prefix; require('../../startup/run/hello')(client); // startup info require('../../startup/run/setstatus')(client); diff --git a/src/handle/startup/collect/commands.js b/src/handle/startup/collect/commands.js index d7b2ee2..38b0985 100644 --- a/src/handle/startup/collect/commands.js +++ b/src/handle/startup/collect/commands.js @@ -48,5 +48,6 @@ module.exports = async client => { 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(', ')))}`)); - client.log(`Loaded ${chalk.white(client.commands.size)} command${client.utils.s(client.commands.size)}!`, {color: 'blue', source: 'boot'}, 1, 1); + 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/handle/startup/collect/events.js index c3d338e..d7a88bd 100644 --- a/src/handle/startup/collect/events.js +++ b/src/handle/startup/collect/events.js @@ -26,7 +26,7 @@ module.exports = async client => { const eventName = file.split('.')[0]; client.removeAllListeners(eventName); client.on(eventName, event.bind(null, client)); - client.log(`Loaded ${chalk.white(eventName)} event`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); + client.log(`Loaded event ${chalk.white(eventName)}`, {color: 'blueBright', source: 'boot', sourceColor: 'blue'}); } catch (e) { client.error(`Failed to read file ${chalk.white(file)}`); diff --git a/src/handle/startup/run/hello.js b/src/handle/startup/run/hello.js index cc3bd61..651c70e 100644 --- a/src/handle/startup/run/hello.js +++ b/src/handle/startup/run/hello.js @@ -6,6 +6,7 @@ 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(`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(`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/json/config.json b/src/json/config.json index 6172595..9694c05 100644 --- a/src/json/config.json +++ b/src/json/config.json @@ -1,4 +1,17 @@ { + "bot": { + "name": "Natsuki", + "consoleName": "NATS", + "prefix": "n?", + "devPrefix": "n!" + }, + "embed": { + "colors": { + "base": "c375f0", + "success": "23d534", + "fail": "d52334" + } + }, "log": { "suffix": ">>", "defaultLevel": 1, @@ -7,10 +20,10 @@ "warn": "yellowBright", "success": "greenBright", "notice": "#8521a0", - "primary": "blueBright", - "secondary": "white", - "altprimary": "", - "altsecondary": "" + "primary": "blue", + "secondary": "green", + "altprimary": "blueBright", + "altsecondary": "greenBright" } } } \ No newline at end of file