From 245603472639904111b5f8bc4e860aeb1358b200 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Mon, 7 Nov 2022 02:41:58 -0700 Subject: [PATCH] basic utils --- bot.js | 21 ++++++++++++++++++--- src/json/randresp.json | 11 +++++++++++ src/util/misc/setutils.js | 22 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/json/randresp.json create mode 100644 src/util/misc/setutils.js diff --git a/bot.js b/bot.js index 81df822..d04443d 100644 --- a/bot.js +++ b/bot.js @@ -2,15 +2,30 @@ 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 log = require('./src/util/log/log'); -const flags = Discord.Intents.FLAGS; +const flags = Discord.GatewayIntentBits; +const partials = Discord.Partials; let fl = []; Object.keys(flags).forEach(flag => fl.push(flags[flag])); // fuck new standards i'm in't'zing with all the flags. -const client = new Discord.Client({intents: fl, partials: ["CHANNEL", "REACTION", "MESSAGE"]}); +const client = new Discord.Client({intents: fl, partials: [partials.Channel, partials.Message, partials.Reaction]}); +// a "fuck v14" counter is gonna be here real soon i can feel it. const startBot = async () => { client.config = config; client.auth = auth; + client.config.randResp = randresp; + + require('./src/util/misc/setutils')(client); // add some basic swiss army knife utils + const loggers = log(client); + Object.keys(loggers).forEach(logger => client[logger] = loggers[logger]); + + client.log(client.utils.gr(client.config.randResp.clistart), {color: "#78d9f8", source: "NATS"}); }; startBot(); -// feels like there isn't a function name to do this justice :joy: \ No newline at end of file +// feels like there isn't a function name to do this justice :joy: + +// to do list: +// TODO check log files later for cleanup, config, and util optimization +// TODO check connect file later for ^ \ No newline at end of file diff --git a/src/json/randresp.json b/src/json/randresp.json new file mode 100644 index 0000000..4bf3aae --- /dev/null +++ b/src/json/randresp.json @@ -0,0 +1,11 @@ +{ + "clistart": [ + "Let me go wake Natsuki real quick...", + "You were looking for Natsuki? I'll grab her, give me just a sec.", + "Natsuki's not here right now... she can take a message... ehe...", + "Ughhhh. Yet again with your beckoning call.", + "I think Natsuki mentioned something about wanting to rest... I'm guessing that won't be happening?", + "*in robotic voice* starting up. booting now. am i convincing yet?", + "Sure sure I'd love to be bothered by Discord users all day. It's not like I had anything else to do, really." + ] +} \ No newline at end of file diff --git a/src/util/misc/setutils.js b/src/util/misc/setutils.js new file mode 100644 index 0000000..4f75f36 --- /dev/null +++ b/src/util/misc/setutils.js @@ -0,0 +1,22 @@ +module.exports = client => { + client.utils = {}; //small collection of basic string manipulation utilities so prettier strings are easier + + //pluralize most strings based on a number + client.utils.s = num => num === 1 ? '' : 's'; + //pluralize but pass in the text to make plural + client.utils.as = (num, text) => `${text}${client.utils.s(num)}`; + // "a" or "an" based on the provided string, caps to begin with capital letter + client.utils.an = (text, caps) => `${caps ? 'A' : 'a'}${['a', 'e', 'i', 'o', 'u'].includes(text.toLowerCase().trim().slice(0, 1)) ? 'n' : ''} ${text}`; + //capitalize a string automatically, "a" if rest of string should be automatically lowercased + client.utils.c = (text, a=true) => `${text.slice(0, 1).toUpperCase()}${a ? text.slice(1).toLowerCase() : text.slice(1)}`; + //split text into words and autocap each one + client.utils.ca = (text, a=true) => text.split(/\s+/gm).map(t => client.utils.c(t, a)).join(" "); + //format a moment-presice-range object + 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' : ''}`; + //add a grammatically correct possessive indicator to the end of a word/string + client.utils.p = (text) => text.endsWith('s') ? "'" : "'s"; + //possessivise but pass in the text to possessivize + client.utils.ps = (text) => `${text}${client.utils.p(text)}`; + //random element of array + client.utils.gr = list => list[Math.floor(Math.random() * list.length)]; +}; \ No newline at end of file