Added sqlite database support, connect new argument parser to message handler

This commit is contained in:
Essem 2021-07-01 23:42:12 -05:00
parent 714e4a451c
commit ecc6d98aec
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
11 changed files with 330 additions and 39 deletions

View file

@ -11,6 +11,8 @@ TOKEN=
# Put the database connection URL here # Put the database connection URL here
# Example for MongoDB: # Example for MongoDB:
# DB=mongodb://localhost:27017/esmBot # DB=mongodb://localhost:27017/esmBot
# Example for SQLite:
# DB=sqlite://data.sqlite
# Example for PostgreSQL: # Example for PostgreSQL:
DB=postgresql://esmbot:verycoolpass100@localhost:5432/esmbot DB=postgresql://esmbot:verycoolpass100@localhost:5432/esmbot

View file

@ -1,11 +1,12 @@
class Command { class Command {
constructor(client, cluster, ipc, message, args, content) { constructor(client, cluster, ipc, message, args, content, specialArgs) {
this.client = client; this.client = client;
this.cluster = cluster; this.cluster = cluster;
this.ipc = ipc; this.ipc = ipc;
this.message = message; this.message = message;
this.args = args; this.args = args;
this.content = content; this.content = content;
this.specialArgs = specialArgs;
this.reference = { this.reference = {
messageReference: { messageReference: {
channelID: this.message.channel.id, channelID: this.message.channel.id,

View file

@ -2,8 +2,8 @@ const Command = require("./command.js");
const soundPlayer = require("../utils/soundplayer.js"); const soundPlayer = require("../utils/soundplayer.js");
class MusicCommand extends Command { class MusicCommand extends Command {
constructor(client, cluster, ipc, message, args, content) { constructor(client, cluster, ipc, message, args, content, specialArgs) {
super(client, cluster, ipc, message, args, content); super(client, cluster, ipc, message, args, content, specialArgs);
this.connection = soundPlayer.players.get(message.channel.guild.id); this.connection = soundPlayer.players.get(message.channel.guild.id);
} }

View file

@ -4,7 +4,7 @@ class CaptionCommand extends ImageCommand {
params(args, url) { params(args, url) {
const newArgs = args.filter(item => !item.includes(url)); const newArgs = args.filter(item => !item.includes(url));
let newCaption = newArgs.join(" ").replaceAll("&", "\\&amp;").replaceAll(">", "\\&gt;").replaceAll("<", "\\&lt;").replaceAll("\"", "\\&quot;").replaceAll("'", "\\&apos;").replaceAll("%", "\\%"); let newCaption = newArgs.join(" ").replaceAll("&", "\\&amp;").replaceAll(">", "\\&gt;").replaceAll("<", "\\&lt;").replaceAll("\"", "\\&quot;").replaceAll("'", "\\&apos;").replaceAll("%", "\\%");
if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real") newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`; if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real" && !this.specialArgs.noEgg) newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`;
return { return {
caption: newCaption caption: newCaption
}; };

View file

@ -11,7 +11,7 @@ class TagsCommand extends Command {
if ((guild.tagsDisabled || guild.tags_disabled) && this.args[0].toLowerCase() !== ("enable" || "disable")) return; if ((guild.tagsDisabled || guild.tags_disabled) && this.args[0].toLowerCase() !== ("enable" || "disable")) return;
if (this.args.length === 0) return "You need to provide the name of the tag you want to view!"; if (this.args.length === 0) return "You need to provide the name of the tag you want to view!";
const tags = guild.tags instanceof Map ? Object.fromEntries(guild.tags) : guild.tags; const tags = guild.tags instanceof Map ? Object.fromEntries(guild.tags) : typeof guild.tags === "string" ? JSON.parse(guild.tags) : guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random", "own", "owner", "enable", "disable"]; const blacklist = ["add", "edit", "remove", "delete", "list", "random", "own", "owner", "enable", "disable"];
switch (this.args[0].toLowerCase()) { switch (this.args[0].toLowerCase()) {
case "add": case "add":
@ -58,7 +58,6 @@ class TagsCommand extends Command {
"text": `Page ${i + 1} of ${groups.length}` "text": `Page ${i + 1} of ${groups.length}`
}, },
"description": value.join("\n"), "description": value.join("\n"),
"fields": process.env.NODE_ENV === "development" ? [{"name": "Note", "value": "Tags created in this version of esmBot will not carry over to the final release."}] : null,
"author": { "author": {
"name": this.message.author.username, "name": this.message.author.username,
"icon_url": this.message.author.avatarURL "icon_url": this.message.author.avatarURL

View file

@ -2,7 +2,7 @@ const fs = require("fs");
const database = require("../utils/database.js"); const database = require("../utils/database.js");
const logger = require("../utils/logger.js"); const logger = require("../utils/logger.js");
const collections = require("../utils/collections.js"); const collections = require("../utils/collections.js");
//const commands = [...collections.aliases.keys(), ...collections.commands.keys()]; const parseCommand = require("../utils/parseCommand.js");
// run when someone sends a message // run when someone sends a message
module.exports = async (client, cluster, ipc, message) => { module.exports = async (client, cluster, ipc, message) => {
@ -50,9 +50,10 @@ module.exports = async (client, cluster, ipc, message) => {
const replace = isMention ? `@${client.user.username} ` : prefix; const replace = isMention ? `@${client.user.username} ` : prefix;
const content = message.cleanContent.substring(replace.length).trim(); const content = message.cleanContent.substring(replace.length).trim();
const rawContent = message.content.substring(prefix.length).trim(); const rawContent = message.content.substring(prefix.length).trim();
const args = content.split(/\s+/g); const preArgs = content.split(/\s+/g);
args.shift(); preArgs.shift();
const command = rawContent.split(/\s+/g).shift().toLowerCase(); const command = rawContent.split(/\s+/g).shift().toLowerCase();
const parsed = parseCommand(preArgs);
// don't run if message is in a disabled channel // don't run if message is in a disabled channel
if (message.channel.guild) { if (message.channel.guild) {
@ -86,7 +87,8 @@ module.exports = async (client, cluster, ipc, message) => {
try { try {
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command); await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
const startTime = new Date(); const startTime = new Date();
const commandClass = new cmd(client, cluster, ipc, message, args, message.content.substring(prefix.length).trim().replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy // eslint-disable-next-line no-unused-vars
const commandClass = new cmd(client, cluster, ipc, message, parsed._, message.content.substring(prefix.length).trim().replace(command, "").trim(), (({ _, ...o }) => o)(parsed)); // we also provide the message content as a parameter for cases where we need more accuracy
const result = await commandClass.run(); const result = await commandClass.run();
const endTime = new Date(); const endTime = new Date();
if ((endTime - startTime) >= 180000) reference.allowedMentions.repliedUser = true; if ((endTime - startTime) >= 180000) reference.allowedMentions.repliedUser = true;

207
package-lock.json generated
View file

@ -34,6 +34,7 @@
"node": ">=15" "node": ">=15"
}, },
"optionalDependencies": { "optionalDependencies": {
"better-sqlite3": "^7.4.1",
"bufferutil": "^4.0.1", "bufferutil": "^4.0.1",
"erlpack": "github:abalabahaha/erlpack", "erlpack": "github:abalabahaha/erlpack",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",
@ -690,6 +691,18 @@
} }
] ]
}, },
"node_modules/better-sqlite3": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.4.1.tgz",
"integrity": "sha512-sk1kW3PsWE7W7G9qbi5TQxCROlQVR8YWlp4srbyrwN5DrLeamKfrm3JExwOiNSAYyJv8cw5/2HOfvF/ipZj4qg==",
"hasInstallScript": true,
"optional": true,
"dependencies": {
"bindings": "^1.5.0",
"prebuild-install": "^6.0.1",
"tar": "^6.1.0"
}
},
"node_modules/bindings": { "node_modules/bindings": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
@ -850,9 +863,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001240", "version": "1.0.30001241",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001240.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001241.tgz",
"integrity": "sha512-nb8mDzfMdxBDN7ZKx8chWafAdBp5DAAlpWvNyUGe5tcDWd838zpzDN3Rah9cjCqhfOKkrvx40G2SDtP0qiWX/w==", "integrity": "sha512-1uoSZ1Pq1VpH0WerIMqwptXHNNGfdl7d1cJUFs80CwQ/lVzdhTvsFZCeNFslze7AjsQnb4C85tzclPa1VShbeQ==",
"dev": true, "dev": true,
"peer": true, "peer": true,
"funding": { "funding": {
@ -875,9 +888,13 @@
} }
}, },
"node_modules/chownr": { "node_modules/chownr": {
"version": "1.1.4", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
"optional": true,
"engines": {
"node": ">=10"
}
}, },
"node_modules/cliui": { "node_modules/cliui": {
"version": "5.0.0", "version": "5.0.0",
@ -1164,9 +1181,9 @@
} }
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.3.759", "version": "1.3.761",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.759.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.761.tgz",
"integrity": "sha512-nM76xH0t2FBH5iMEZDVc3S/qbdKjGH7TThezxC8k1Q7w7WHvIAyJh8lAe2UamGfdRqBTjHfPDn82LJ0ksCiB9g==", "integrity": "sha512-7a/wV/plM/b95XjTdA2Q4zAxxExTDKkNQpTiaU/nVT8tGCQVtX9NsnTjhALBFICpOB58hU6xg5fFC3CT2Bybpg==",
"dev": true, "dev": true,
"peer": true "peer": true
}, },
@ -1212,7 +1229,7 @@
}, },
"node_modules/eris-sharder": { "node_modules/eris-sharder": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "git+ssh://git@github.com/esmBot/eris-sharder.git#edc1b3154604c3106a45c42ecf9b25703bc44498", "resolved": "git+ssh://git@github.com/esmBot/eris-sharder.git#3b7366e5d99012ca0e3350e4d81f384b48911c2d",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"colors": "^1.1.2", "colors": "^1.1.2",
@ -1690,6 +1707,18 @@
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="
}, },
"node_modules/fs-minipass": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
"integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
"optional": true,
"dependencies": {
"minipass": "^3.0.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/fs.realpath": { "node_modules/fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -2158,6 +2187,43 @@
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
}, },
"node_modules/minipass": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz",
"integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==",
"optional": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/minizlib": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
"integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
"optional": true,
"dependencies": {
"minipass": "^3.0.0",
"yallist": "^4.0.0"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"optional": true,
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/mkdirp-classic": { "node_modules/mkdirp-classic": {
"version": "0.5.3", "version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
@ -3277,6 +3343,23 @@
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
"dev": true "dev": true
}, },
"node_modules/tar": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
"optional": true,
"dependencies": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"minipass": "^3.0.0",
"minizlib": "^2.1.1",
"mkdirp": "^1.0.3",
"yallist": "^4.0.0"
},
"engines": {
"node": ">= 10"
}
},
"node_modules/tar-fs": { "node_modules/tar-fs": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
@ -3288,6 +3371,11 @@
"tar-stream": "^2.1.4" "tar-stream": "^2.1.4"
} }
}, },
"node_modules/tar-fs/node_modules/chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
},
"node_modules/tar-stream": { "node_modules/tar-stream": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz",
@ -3591,9 +3679,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"node_modules/ws": { "node_modules/ws": {
"version": "7.5.0", "version": "7.5.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.1.tgz",
"integrity": "sha512-6ezXvzOZupqKj4jUqbQ9tXuJNo+BR2gU8fFRk3XCP3e0G6WT414u5ELe6Y0vtp7kmSJ3F7YWObSNr1ESsgi4vw==", "integrity": "sha512-2c6faOUH/nhoQN6abwMloF7Iyl0ZS2E9HGtsiLrWn0zOOMWlhtDmdf/uihDt6jnuCxgtwGBNy6Onsoy2s2O2Ow==",
"engines": { "engines": {
"node": ">=8.3.0" "node": ">=8.3.0"
}, },
@ -4197,6 +4285,17 @@
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
}, },
"better-sqlite3": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.4.1.tgz",
"integrity": "sha512-sk1kW3PsWE7W7G9qbi5TQxCROlQVR8YWlp4srbyrwN5DrLeamKfrm3JExwOiNSAYyJv8cw5/2HOfvF/ipZj4qg==",
"optional": true,
"requires": {
"bindings": "^1.5.0",
"prebuild-install": "^6.0.1",
"tar": "^6.1.0"
}
},
"bindings": { "bindings": {
"version": "1.5.0", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
@ -4317,9 +4416,9 @@
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
}, },
"caniuse-lite": { "caniuse-lite": {
"version": "1.0.30001240", "version": "1.0.30001241",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001240.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001241.tgz",
"integrity": "sha512-nb8mDzfMdxBDN7ZKx8chWafAdBp5DAAlpWvNyUGe5tcDWd838zpzDN3Rah9cjCqhfOKkrvx40G2SDtP0qiWX/w==", "integrity": "sha512-1uoSZ1Pq1VpH0WerIMqwptXHNNGfdl7d1cJUFs80CwQ/lVzdhTvsFZCeNFslze7AjsQnb4C85tzclPa1VShbeQ==",
"dev": true, "dev": true,
"peer": true "peer": true
}, },
@ -4335,9 +4434,10 @@
} }
}, },
"chownr": { "chownr": {
"version": "1.1.4", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==",
"optional": true
}, },
"cliui": { "cliui": {
"version": "5.0.0", "version": "5.0.0",
@ -4561,9 +4661,9 @@
"integrity": "sha512-I9OvvrHp4pIARv4+x9iuewrWycX6CcZtoAu1XrzPxc5UygMJXJZYmBsynku8IkrJwgypE5DGNjDPmPRhDCptUg==" "integrity": "sha512-I9OvvrHp4pIARv4+x9iuewrWycX6CcZtoAu1XrzPxc5UygMJXJZYmBsynku8IkrJwgypE5DGNjDPmPRhDCptUg=="
}, },
"electron-to-chromium": { "electron-to-chromium": {
"version": "1.3.759", "version": "1.3.761",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.759.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.761.tgz",
"integrity": "sha512-nM76xH0t2FBH5iMEZDVc3S/qbdKjGH7TThezxC8k1Q7w7WHvIAyJh8lAe2UamGfdRqBTjHfPDn82LJ0ksCiB9g==", "integrity": "sha512-7a/wV/plM/b95XjTdA2Q4zAxxExTDKkNQpTiaU/nVT8tGCQVtX9NsnTjhALBFICpOB58hU6xg5fFC3CT2Bybpg==",
"dev": true, "dev": true,
"peer": true "peer": true
}, },
@ -4599,7 +4699,7 @@
} }
}, },
"eris-sharder": { "eris-sharder": {
"version": "git+ssh://git@github.com/esmBot/eris-sharder.git#edc1b3154604c3106a45c42ecf9b25703bc44498", "version": "git+ssh://git@github.com/esmBot/eris-sharder.git#3b7366e5d99012ca0e3350e4d81f384b48911c2d",
"from": "eris-sharder@github:esmBot/eris-sharder#eris-dev", "from": "eris-sharder@github:esmBot/eris-sharder#eris-dev",
"requires": { "requires": {
"colors": "^1.1.2", "colors": "^1.1.2",
@ -4958,6 +5058,15 @@
"resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz",
"integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow=="
}, },
"fs-minipass": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
"integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==",
"optional": true,
"requires": {
"minipass": "^3.0.0"
}
},
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -5317,6 +5426,31 @@
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
}, },
"minipass": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz",
"integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==",
"optional": true,
"requires": {
"yallist": "^4.0.0"
}
},
"minizlib": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz",
"integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==",
"optional": true,
"requires": {
"minipass": "^3.0.0",
"yallist": "^4.0.0"
}
},
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"optional": true
},
"mkdirp-classic": { "mkdirp-classic": {
"version": "0.5.3", "version": "0.5.3",
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
@ -6160,6 +6294,20 @@
} }
} }
}, },
"tar": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz",
"integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==",
"optional": true,
"requires": {
"chownr": "^2.0.0",
"fs-minipass": "^2.0.0",
"minipass": "^3.0.0",
"minizlib": "^2.1.1",
"mkdirp": "^1.0.3",
"yallist": "^4.0.0"
}
},
"tar-fs": { "tar-fs": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
@ -6169,6 +6317,13 @@
"mkdirp-classic": "^0.5.2", "mkdirp-classic": "^0.5.2",
"pump": "^3.0.0", "pump": "^3.0.0",
"tar-stream": "^2.1.4" "tar-stream": "^2.1.4"
},
"dependencies": {
"chownr": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz",
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="
}
} }
}, },
"tar-stream": { "tar-stream": {
@ -6404,9 +6559,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"ws": { "ws": {
"version": "7.5.0", "version": "7.5.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.1.tgz",
"integrity": "sha512-6ezXvzOZupqKj4jUqbQ9tXuJNo+BR2gU8fFRk3XCP3e0G6WT414u5ELe6Y0vtp7kmSJ3F7YWObSNr1ESsgi4vw==", "integrity": "sha512-2c6faOUH/nhoQN6abwMloF7Iyl0ZS2E9HGtsiLrWn0zOOMWlhtDmdf/uihDt6jnuCxgtwGBNy6Onsoy2s2O2Ow==",
"requires": {} "requires": {}
}, },
"xtend": { "xtend": {

View file

@ -46,6 +46,7 @@
"eslint": "^7.23.0" "eslint": "^7.23.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"better-sqlite3": "^7.4.1",
"bufferutil": "^4.0.1", "bufferutil": "^4.0.1",
"erlpack": "github:abalabahaha/erlpack", "erlpack": "github:abalabahaha/erlpack",
"mongoose": "^5.11.8", "mongoose": "^5.11.8",

127
utils/database/sqlite.js Normal file
View file

@ -0,0 +1,127 @@
const collections = require("../collections.js");
const misc = require("../misc.js");
const logger = require("../logger.js");
const sqlite3 = require("better-sqlite3");
const connection = sqlite3(process.env.DB.replace("sqlite://", ""));
exports.setup = async () => {
let counts;
try {
counts = connection.prepare("SELECT * FROM counts").all();
} catch {
connection.prepare("CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL )").run();
counts = [];
}
if (!counts) {
for (const command of collections.commands.keys()) {
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0);
}
} else {
const exists = [];
for (const command of collections.commands.keys()) {
const count = connection.prepare("SELECT * FROM counts WHERE command = ?").get(command);
if (!count) {
connection.prepare("INSERT INTO counts (command, count) VALUES (?, ?)").run(command, 0);
}
exists.push(command);
}
for (const { command } of counts) {
if (!exists.includes(command)) {
connection.prepare("DELETE FROM counts WHERE command = ?").run(command);
}
}
}
};
exports.stop = async () => {
connection.close();
};
exports.fixGuild = async (guild) => {
let guildDB;
try {
guildDB = connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(guild.id);
} catch {
connection.prepare("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags text NOT NULL, prefix VARCHAR(15) NOT NULL, disabled text NOT NULL, tags_disabled integer NOT NULL DEFAULT 0 CHECK(tags_disabled IN (0,1)) )").run();
}
if (!guildDB) {
logger.log(`Registering guild database entry for guild ${guild.id}...`);
return await this.addGuild(guild);
}
};
exports.addCount = async (command) => {
connection.prepare("UPDATE counts SET count = count + 1 WHERE command = ?").run(command);
};
exports.getCounts = async () => {
const counts = connection.prepare("SELECT * FROM counts").all();
const countObject = {};
for (const { command, count } of counts) {
countObject[command] = count;
}
return countObject;
};
exports.disableChannel = async (channel) => {
const guildDB = await this.getGuild(channel.guild.id);
connection.prepare("UPDATE guilds SET disabled = ? WHERE guild_id = ?").run(JSON.stringify([...JSON.parse(guildDB.disabled), channel.id]), channel.guild.id);
collections.disabledCache.set(channel.guild.id, [...JSON.parse(guildDB.disabled), channel.id]);
};
exports.enableChannel = async (channel) => {
const guildDB = await this.getGuild(channel.guild.id);
const newDisabled = JSON.parse(guildDB.disabled).filter(item => item !== channel.id);
connection.prepare("UPDATE guilds SET disabled = ? WHERE guild_id = ?").run(JSON.stringify(newDisabled), channel.guild.id);
collections.disabledCache.set(channel.guild.id, newDisabled);
};
exports.toggleTags = async (guild) => {
const guildDB = await this.getGuild(guild.id);
guildDB.tags_disabled = guildDB.tags_disabled ? 0 : 1;
connection.prepare("UPDATE guilds SET tags_disabled = ? WHERE guild_id = ?").run(guildDB.tags_disabled, guild.id);
};
exports.setTag = async (name, content, guild) => {
const guildDB = await this.getGuild(guild.id);
const tags = JSON.parse(guildDB.tags);
tags[name] = content;
connection.prepare("UPDATE guilds SET tags = ? WHERE guild_id = ?").run(JSON.stringify(tags), guild.id);
};
exports.removeTag = async (name, guild) => {
const guildDB = await this.getGuild(guild.id);
const tags = JSON.parse(guildDB.tags);
delete tags[name];
connection.prepare("UPDATE guilds SET tags = ? WHERE guild_id = ?").run(JSON.stringify(tags), guild.id);
};
exports.setPrefix = async (prefix, guild) => {
connection.prepare("UPDATE guilds SET prefix = ? WHERE guild_id = ?").run(prefix, guild.id);
collections.prefixCache.set(guild.id, prefix);
};
exports.addGuild = async (guild) => {
const query = await this.getGuild(guild);
if (query) return query;
const guildObject = {
id: guild.id,
tags: JSON.stringify(misc.tagDefaults),
prefix: process.env.PREFIX,
disabled: "[]",
tagsDisabled: 0
};
connection.prepare("INSERT INTO guilds (guild_id, tags, prefix, disabled, tags_disabled) VALUES (@id, @tags, @prefix, @disabled, @tagsDisabled)").run(guildObject);
return guildObject;
};
exports.getGuild = async (query) => {
try {
return connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(query);
} catch {
return;
}
};

View file

@ -143,7 +143,7 @@ const getIdeal = async () => {
const controller = new AbortController(); // eslint-disable-line no-undef const controller = new AbortController(); // eslint-disable-line no-undef
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
controller.abort(); controller.abort();
}, 2000); }, 5000);
try { try {
const statusRequest = await fetch(`http://${address}:8080/status`, { signal: controller.signal }); const statusRequest = await fetch(`http://${address}:8080/status`, { signal: controller.signal });
clearTimeout(timeout); clearTimeout(timeout);
@ -235,7 +235,7 @@ exports.getType = async (image, extraReturnTypes) => {
return type; return type;
}; };
exports.run = object => { exports.run = (object) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (process.env.API === "true") { if (process.env.API === "true") {
// Connect to best image server // Connect to best image server

View file

@ -1,5 +1,5 @@
module.exports = (input, allowed) => { module.exports = (input, allowed) => {
input = input.split(" "); if (typeof input === "string") input = input.split(/\s+/g);
const args = { _: [] }; const args = { _: [] };
let curr = null; let curr = null;
let concated = ""; let concated = "";
@ -18,6 +18,10 @@ module.exports = (input, allowed) => {
} }
} else if (value.endsWith("\"")) { } else if (value.endsWith("\"")) {
args[arg] += a.slice(0, -1); args[arg] += a.slice(0, -1);
} else if (value === "true") {
args[arg] = true;
} else if (value === "false") {
args[arg] = false;
} else if (value !== "") { } else if (value !== "") {
args[arg] = value; args[arg] = value;
} else { } else {