Moved back to MongoDB, added some extra flags to flag

This commit is contained in:
TheEssem 2020-07-26 19:52:13 -05:00
parent 0ebd0a0cee
commit 6eee7c6058
18 changed files with 303 additions and 269 deletions

3
app.js
View File

@ -55,9 +55,10 @@ async function init() {
handler.unload(command); handler.unload(command);
} }
client.disconnect(); client.disconnect();
require("./utils/database.js").end(); require("./utils/database.js").connection.close(() => {
process.exit(0); process.exit(0);
}); });
});
} }
// launch the bot // launch the bot

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
assets/images/transflag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -4,28 +4,28 @@ exports.run = async (message, args) => {
if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to enable/disable me!`; if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to enable/disable me!`;
if (args.length === 0) return `${message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`; if (args.length === 0) return `${message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`;
if (args[0] !== "disable" && args[0] !== "enable") return `${message.author.mention}, that's not a valid option!`; if (args[0] !== "disable" && args[0] !== "enable") return `${message.author.mention}, that's not a valid option!`;
const guildDB = await db.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guildDB = await db.guilds.findOne({id: message.channel.guild.id});
if (args[0].toLowerCase() === "disable") { if (args[0].toLowerCase() === "disable") {
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) { if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", ""); const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");
if (guildDB.rows[0].disabled.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`; if (guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.rows[0].disabled.push(id); guildDB.disabledChannels.push(id);
} else { } else {
if (guildDB.rows[0].disabled.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`; if (guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.rows[0].disabled.push(message.channel.id); guildDB.disabledChannels.push(message.channel.id);
} }
await db.query("UPDATE guilds SET disabled = $1 WHERE guild_id = $2", [guildDB.rows[0].disabled, message.channel.guild.id]); await guildDB.save();
return `${message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.rows[0].prefix}channel enable\`.`; return `${message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
} else if (args[0].toLowerCase() === "enable") { } else if (args[0].toLowerCase() === "enable") {
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) { if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", ""); const id = args[1].replace("@", "").replace("#", "").replace("!", "").replace("&", "").replace("<", "").replace(">", "");
if (!guildDB.rows[0].disabled.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`; if (!guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
guildDB.rows[0].disabled = guildDB.rows[0].disabled.filter(item => item !== id); guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== id);
} else { } else {
if (!guildDB.rows[0].disabled.includes(message.channel.id)) return `${message.author.mention}, I'm not disabled in this channel!`; if (!guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm not disabled in this channel!`;
guildDB.rows[0].disabled = guildDB.rows[0].disabled.filter(item => item !== message.channel.id ); guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== message.channel.id );
} }
await db.query("UPDATE guilds SET disabled = $1 WHERE guild_id = $2", [guildDB.rows[0].disabled, message.channel.guild.id]); await guildDB.save();
return `${message.author.mention}, I have been re-enabled in this channel.`; return `${message.author.mention}, I have been re-enabled in this channel.`;
} }
}; };

View File

@ -5,13 +5,13 @@ const database = require("../utils/database.js");
exports.run = async (message) => { exports.run = async (message) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`; if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`; if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const counts = await database.query("SELECT * FROM counts"); const counts = (await database.global.findOne({})).cmdCounts;
const countArray = []; const countArray = [];
const sortedValues = counts.rows.sort((a, b) => { const sortedValues = [...counts.entries()].sort((a, b) => {
return b.count - a.count; return b[1] - a[1];
}); });
for (const { command, count } of sortedValues) { for (const [key, value] of sortedValues) {
countArray.push(`**${command}**: ${count}`); countArray.push(`**${key}**: ${value}`);
} }
const embeds = []; const embeds = [];
const groups = countArray.map((item, index) => { const groups = countArray.map((item, index) => {

View File

@ -1,5 +1,6 @@
const magick = require("../build/Release/image.node"); const magick = require("../build/Release/image.node");
const { promisify } = require("util"); const { promisify } = require("util");
const fs = require("fs");
const emojiRegex = require("emoji-regex"); const emojiRegex = require("emoji-regex");
const emoji = require("node-emoji"); const emoji = require("node-emoji");
@ -11,6 +12,14 @@ exports.run = async (message, args) => {
const flag = emoji.unemojify(args[0]).replace(/:/g, "").replace("flag-", ""); const flag = emoji.unemojify(args[0]).replace(/:/g, "").replace("flag-", "");
let path = `./assets/images/region-flags/png/${flag.toUpperCase()}.png`; let path = `./assets/images/region-flags/png/${flag.toUpperCase()}.png`;
if (flag === "🏴‍☠️") path = "./assets/images/pirateflag.png"; if (flag === "🏴‍☠️") path = "./assets/images/pirateflag.png";
if (flag === "rainbow-flag") path = "./assets/images/rainbowflag.png";
if (flag === "checkered_flag") path = "./assets/images/checkeredflag.png";
if (flag === "🏳️‍⚧️") path = "./assets/images/transflag.png";
try {
await promisify(fs.access)(path);
} catch (e) {
return `${message.author.mention}, that isn't a flag!`;
}
const buffer = await promisify(magick.flag)(image.path, path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0); const buffer = await promisify(magick.flag)(image.path, path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
return { return {
file: buffer, file: buffer,

View File

@ -6,7 +6,7 @@ const paginator = require("../utils/pagination/pagination.js");
const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional."]; const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional."];
exports.run = async (message, args) => { exports.run = async (message, args) => {
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const commands = collections.commands; const commands = collections.commands;
const aliases = collections.aliases; const aliases = collections.aliases;
if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) { if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) {
@ -17,7 +17,7 @@ exports.run = async (message, args) => {
"name": "esmBot Help", "name": "esmBot Help",
"icon_url": client.user.avatarURL "icon_url": client.user.avatarURL
}, },
"title": `${guildDB.rows[0].prefix}${aliases.has(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase()}`, "title": `${guild.prefix}${aliases.has(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase()}`,
"url": "https://projectlounge.pw/esmBot/help.html", "url": "https://projectlounge.pw/esmBot/help.html",
"description": info.description, "description": info.description,
"color": 16711680, "color": 16711680,
@ -94,7 +94,7 @@ exports.run = async (message, args) => {
}, },
"fields": [{ "fields": [{
"name": "Prefix", "name": "Prefix",
"value": guildDB.rows[0].prefix "value": guild.prefix
}, { }, {
"name": "Tip", "name": "Tip",
"value": misc.random(tips) "value": misc.random(tips)

View File

@ -1,14 +1,14 @@
const database = require("../utils/database.js"); const database = require("../utils/database.js");
exports.run = async (message, args) => { exports.run = async (message, args) => {
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guild = await database.guilds.findOne({ id: message.channel.guild.id });
if (args.length !== 0) { if (args.length !== 0) {
if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to change the bot prefix!`; if (!message.member.permission.has("administrator") && message.member.id !== process.env.OWNER) return `${message.author.mention}, you need to be an administrator to change the bot prefix!`;
if (args[0].length > 15) return `${message.author.mention}, that prefix is too long!`; guild.set("prefix", args[0]);
await database.query("UPDATE guilds SET prefix = $1 WHERE guild_id = $2", [args[0], message.channel.guild.id]); await guild.save();
return `The prefix has been changed to ${args[0]}.`; return `The prefix has been changed to ${args[0]}.`;
} else { } else {
return `${message.author.mention}, the current prefix is \`${guildDB.rows[0].prefix}\`.`; return `${message.author.mention}, the current prefix is \`${guild.prefix}\`.`;
} }
}; };

View File

@ -5,44 +5,43 @@ const { random } = require("../utils/misc.js");
exports.run = async (message, args) => { exports.run = async (message, args) => {
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`; if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const tags = guildDB.rows[0].tags; const tags = guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random"]; const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "create":
case "add": case "add":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`; if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to add!`;
if (blacklist.includes(args[1].toLowerCase())) return `${message.author.mention}, you can't make a tag with that name!`; if (blacklist.includes(args[1].toLowerCase())) return `${message.author.mention}, you can't make a tag with that name!`;
if (tags[args[1].toLowerCase()]) return `${message.author.mention}, this tag already exists!`; if (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
var result = await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guildDB); var result = await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
if (result) return result; if (result) return result;
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`; return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
case "delete": case "delete":
case "remove": case "remove":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`; if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`;
if (!tags[args[1].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`; if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags[args[1].toLowerCase()].author !== message.author.id && !message.member.permission.has("administrator") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`; if (tags.get(args[1].toLowerCase()).author !== message.author.id && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
delete tags[args[1].toLowerCase()]; tags.set(args[1].toLowerCase(), undefined);
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [tags, message.channel.guild.id]); await guild.save();
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`; return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
case "edit": case "edit":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to edit!`; if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to edit!`;
if (!tags[args[1].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`; if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags[args[1].toLowerCase()].author !== message.author.id && tags[args[1].toLowerCase()].author !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`; if (tags.get(args[1].toLowerCase()).author !== message.author.id && tags.get(args[1].toLowerCase()).author !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guildDB); await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`; return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
case "own": case "own":
case "owner": case "owner":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to check the owner of!`; if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to check the owner of!`;
if (!tags[args[1].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`; if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
return `${message.author.mention}, this tag is owned by **${client.users.get(tags[args[1].toLowerCase()].author).username}#${client.users.get(tags[args[1].toLowerCase()].author).discriminator}** (\`${tags[args[1].toLowerCase()].author}\`).`; return `${message.author.mention}, this tag is owned by **${client.users.get(tags.get(args[1].toLowerCase()).author).username}#${client.users.get(tags.get(args[1].toLowerCase()).author).discriminator}** (\`${tags.get(args[1].toLowerCase()).author}\`).`;
case "list": case "list":
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`; if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`; if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
var pageSize = 15; var pageSize = 15;
var embeds = []; var embeds = [];
var groups = Object.keys(tags).map((item, index) => { var groups = [...tags.keys()].map((item, index) => {
return index % pageSize === 0 ? Object.keys(tags).slice(index, index + pageSize) : null; return index % pageSize === 0 ? [...tags.keys()].slice(index, index + pageSize) : null;
}).filter((item) => { }).filter((item) => {
return item; return item;
}); });
@ -68,21 +67,23 @@ exports.run = async (message, args) => {
case "random": case "random":
return random([...tags])[1].content; return random([...tags])[1].content;
default: default:
if (!tags[args[0].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`; if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
return tags[args[0].toLowerCase()].content; return tags.get(args[0].toLowerCase()).content;
} }
}; };
const setTag = async (content, name, message, guildDB) => { const setTag = async (content, name, message, guild) => {
if ((!content || content.length === 0) && message.attachments.length === 0) return `${message.author.mention}, you need to provide the content of the tag!`; if ((!content || content.length === 0) && message.attachments.length === 0) return `${message.author.mention}, you need to provide the content of the tag!`;
if (message.attachments.length !== 0 && content) { if (message.attachments.length !== 0 && content) {
guildDB.rows[0].tags[name] = { content: `${content} ${message.attachments[0].url}`, author: message.author.id }; guild.tags.set(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id });
await guild.save();
} else if (message.attachments.length !== 0) { } else if (message.attachments.length !== 0) {
guildDB.rows[0].tags[name] = { content: message.attachments[0].url, author: message.author.id }; guild.tags.set(name, { content: message.attachments[0].url, author: message.author.id });
await guild.save();
} else { } else {
guildDB.rows[0].tags[name] = { content: content, author: message.author.id }; guild.tags.set(name, { content: content, author: message.author.id });
await guild.save();
} }
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [guildDB.rows[0].tags, message.channel.guild.id]);
return; return;
}; };

View File

@ -7,8 +7,8 @@ exports.run = async (message, args) => {
const memberCheck = message.mentions.length >= 1 ? message.mentions[0] : client.users.get(args[0]); const memberCheck = message.mentions.length >= 1 ? message.mentions[0] : client.users.get(args[0]);
const member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, "")); const member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, ""));
if (member) { if (member) {
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const array = guildDB.rows[0].warns[member.id] ? guildDB.rows[0].warns[member.id] : []; const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
if (args[1].toLowerCase() !== "list") { if (args[1].toLowerCase() !== "list") {
args.shift(); args.shift();
array.push({ array.push({
@ -16,8 +16,11 @@ exports.run = async (message, args) => {
time: new Date(), time: new Date(),
creator: message.author.id creator: message.author.id
}); });
guildDB.rows[0].warns[member.id] = array; guild.warns.set(member.id, {
await database.query("UPDATE guilds SET warns = $1 WHERE guild_id = $2", [guildDB.rows[0].warns, message.channel.guild.id]); count: (guild.warns.get(member.id) ? guild.warns.get(member.id).count : 0) + 1,
warns: array
});
await guild.save();
//await message.channel.guild.banMember(member.id, 0, `ban command used by @${message.author.username}#${message.author.discriminator}`); //await message.channel.guild.banMember(member.id, 0, `ban command used by @${message.author.username}#${message.author.discriminator}`);
return `Successfully warned ${member.mention} for \`${args.join(" ")}\`.`; return `Successfully warned ${member.mention} for \`${args.join(" ")}\`.`;
} else { } else {
@ -25,7 +28,7 @@ exports.run = async (message, args) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`; if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const warnArray = []; const warnArray = [];
for (const [i, value] of array.entries()) { for (const [i, value] of array.entries()) {
warnArray.push(`**${i + 1}: Added by ${message.channel.guild.members.get(value.creator).username}#${message.channel.guild.members.get(value.creator).discriminator}**: ${value.message} (${new Date(value.time).toUTCString()})`); warnArray.push(`**${i + 1}: Added by ${message.channel.guild.members.get(value.creator).username}#${message.channel.guild.members.get(value.creator).discriminator}**: ${value.message} (${value.time.toUTCString()})`);
} }
const pageSize = 15; const pageSize = 15;
const embeds = []; const embeds = [];

View File

@ -1,76 +0,0 @@
require("dotenv").config();
const { promisify } = require("util");
const { writeFile } = require("fs");
const { Pool } = require("pg");
const pool = new Pool({
user: "esmbot",
host: "localhost",
database: "esmbot",
port: 5432
});
const mongoose = require("mongoose");
mongoose.connect(process.env.MONGO, { poolSize: 10, bufferMaxEntries: 0, reconnectTries: 5000, useNewUrlParser: true, useUnifiedTopology: true });
const guildSchema = new mongoose.Schema({
id: String,
tags: Map,
prefix: String,
warns: Map,
disabledChannels: [String]
});
const Guild = mongoose.model("Guild", guildSchema);
const tweetSchema = new mongoose.Schema({
tweets: [String],
replies: [String],
media: [String],
phrases: [String],
games: [String],
characters: [String],
download: [String],
enabled: Boolean
});
const TweetCollection = mongoose.model("TweetCollection", tweetSchema);
const globalSchema = new mongoose.Schema({
cmdCounts: Map
});
const Global = mongoose.model("Global", globalSchema);
(async () => {
console.log("Migrating guilds...");
const guilds = await Guild.find();
try {
await pool.query("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags json NOT NULL, prefix VARCHAR(15) NOT NULL, warns json NOT NULL, disabled text ARRAY NOT NULL )");
} catch {
console.log("Skipping table creation due to error...");
}
for (const guild of guilds) {
if ((await pool.query("SELECT * FROM guilds WHERE guild_id = $1", [guild.id])).rows.length !== 0) {
await pool.query("UPDATE guilds SET tags = $1, prefix = $2, warns = $3, disabled = $4 WHERE guild_id = $5", [guild.tags, guild.prefix, guild.warns, guild.disabledChannels, guild.id]);
} else {
await pool.query("INSERT INTO guilds (guild_id, tags, prefix, warns, disabled) VALUES ($1, $2, $3, $4, $5)", [guild.id, guild.tags, guild.prefix, guild.warns, guild.disabledChannels]);
}
console.log(`Migrated guild with ID ${guild.id}`);
}
console.log("Migrating Tweets...");
const tweets = await TweetCollection.find();
await promisify(writeFile)("../tweets.json", JSON.stringify(tweets, null, 2));
console.log("Migrating command counts...");
const global = await Global.findOne();
try {
await pool.query("CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL )");
} catch {
console.log("Skipping table creation due to error...");
}
console.log(global);
for (const [key, value] of global.cmdCounts) {
if ((await pool.query("SELECT * FROM counts WHERE command = $1", [key])).rows.length !== 0) {
await pool.query("UPDATE counts SET count = $1 WHERE command = $2", [value, key]);
} else {
await pool.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [key, value]);
}
console.log(`Migrated counts for command ${key}`);
}
console.log("Done!");
return;
})();

View File

@ -6,5 +6,12 @@ const client = require("../utils/client.js");
// run when the bot is added to a guild // run when the bot is added to a guild
module.exports = async (guild) => { module.exports = async (guild) => {
logger.log("info", `[GUILD JOIN] ${guild.name} (${guild.id}) added the bot. Owner: ${client.users.get(guild.ownerID).username}#${client.users.get(guild.ownerID).discriminator} (${guild.ownerID})`); logger.log("info", `[GUILD JOIN] ${guild.name} (${guild.id}) added the bot. Owner: ${client.users.get(guild.ownerID).username}#${client.users.get(guild.ownerID).discriminator} (${guild.ownerID})`);
await db.query("INSERT INTO guilds (guild_id, tags, prefix, warns, disabled) VALUES ($1, $2, $3, $4, $5)", [guild.id, misc.tagDefaults, "&", {}, []]); const guildDB = new db.guilds({
id: guild.id,
tags: misc.tagDefaults,
prefix: "&",
warns: {},
disabledChannels: []
});
await guildDB.save();
}; };

View File

@ -16,9 +16,9 @@ module.exports = async (message) => {
if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return; if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
// prefix can be a mention or a set of special characters // prefix can be a mention or a set of special characters
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]); const guildDB = await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec();
const prefixMention = new RegExp(`^<@!?${client.user.id}> `); const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.rows[0].prefix; const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.prefix;
// ignore other stuff // ignore other stuff
if (message.content.startsWith(prefix) === false) return; if (message.content.startsWith(prefix) === false) return;
@ -30,7 +30,7 @@ module.exports = async (message) => {
const command = args.shift().toLowerCase(); const command = args.shift().toLowerCase();
// don't run if message is in a disabled channel // don't run if message is in a disabled channel
if (guildDB.rows[0].disabled && guildDB.rows[0].disabled.includes(message.channel.id) && command != "channel") return; if (guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
// check if command exists // check if command exists
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command)); const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
@ -39,8 +39,10 @@ module.exports = async (message) => {
// actually run the command // actually run the command
logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`); logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`);
try { try {
const count = await database.query("SELECT * FROM counts WHERE command = $1", [collections.aliases.has(command) ? collections.aliases.get(command) : command]); const global = (await database.global.findOne({}).exec());
await database.query("UPDATE counts SET count = $1 WHERE command = $2", [count.rows[0].count + 1, collections.aliases.has(command) ? collections.aliases.get(command) : command]); const count = global.cmdCounts.get(collections.aliases.has(command) ? collections.aliases.get(command) : command);
global.cmdCounts.set(collections.aliases.has(command) ? collections.aliases.get(command) : command, parseInt(count) + 1);
await global.save();
const result = await cmd(message, args, content.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy const result = await cmd(message, args, content.replace(command, "").trim()); // we also provide the message content as a parameter for cases where we need more accuracy
if (typeof result === "string" || (typeof result === "object" && result.embed)) { if (typeof result === "string" || (typeof result === "object" && result.embed)) {
await client.createMessage(message.channel.id, result); await client.createMessage(message.channel.id, result);

View File

@ -20,21 +20,38 @@ module.exports = async () => {
// make sure settings/tags exist // make sure settings/tags exist
for (const [id] of client.guilds) { for (const [id] of client.guilds) {
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [id]); const guildDB = await database.guilds.findOne({id: id});
if (guildDB.rows.length === 0) { if (!guildDB) {
logger.log(`Registering guild database entry for guild ${id}...`); logger.log(`Registering guild database entry for guild ${id}...`);
await database.query("INSERT INTO guilds (guild_id, tags, prefix, warns, disabled) VALUES ($1, $2, $3, $4, $5)", [id, misc.tagDefaults, "&", {}, []]); const newGuild = new database.guilds({
id: id,
tags: misc.tagDefaults,
prefix: "&",
warns: {},
disabledChannels: []
});
await newGuild.save();
} else if (guildDB) {
if (!guildDB.warns) {
logger.log(`Creating warn object for guild ${id}...`);
guildDB.set("warns", {});
await guildDB.save();
} else if (!guildDB.disabledChannels) {
logger.log(`Creating disabled channels object for guild ${id}...`);
guildDB.set("disabledChannels", []);
await guildDB.save();
}
} }
} }
if (!run && first) { if (!run && first) {
const job = new cron.CronJob("0 0 * * 0", async () => { const job = new cron.CronJob("0 0 * * 0", async () => {
logger.log("Deleting stale guild entries in database..."); logger.log("Deleting stale guild entries in database...");
const guildDB = await database.query("SELECT * FROM guilds"); const guildDB = await database.guilds.find({});
for (const { guild_id } of guildDB.rows) { for (const { id } of guildDB) {
if (!client.guilds.get(guild_id)) { if (!client.guilds.get(id)) {
await database.query("DELETE FROM guilds WHERE guild_id = $1", [guild_id]); await database.guilds.deleteMany({ id: id });
logger.log(`Deleted entry for guild ID ${guild_id}.`); logger.log(`Deleted entry for guild ID ${id}.`);
} }
} }
logger.log("Finished deleting stale entries."); logger.log("Finished deleting stale entries.");
@ -42,21 +59,21 @@ module.exports = async () => {
job.start(); job.start();
} }
let counts; const global = await database.global.findOne({});
try { if (!global) {
counts = await database.query("SELECT * FROM counts"); const countObject = {};
} catch {
counts = { rows: [] };
}
if (!counts.rows[0]) {
for (const command of collections.commands.keys()) { for (const command of collections.commands.keys()) {
await database.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]); countObject[command] = 0;
} }
const newGlobal = new database.global({
cmdCounts: countObject
});
await newGlobal.save();
} else { } else {
for (const command of collections.commands.keys()) { for (const command of collections.commands.keys()) {
const count = await database.query("SELECT * FROM counts WHERE command = $1", [command]); if (!global.cmdCounts.has(command)) {
if (!count.rows[0]) { global.cmdCounts.set(command, 0);
await database.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]); await global.save();
} }
} }
} }

271
package-lock.json generated
View File

@ -237,6 +237,11 @@
} }
} }
}, },
"bluebird": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
"integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
},
"boolbase": { "boolbase": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
@ -251,6 +256,11 @@
"concat-map": "0.0.1" "concat-map": "0.0.1"
} }
}, },
"bson": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz",
"integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q=="
},
"buffer": { "buffer": {
"version": "5.4.3", "version": "5.4.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz",
@ -289,11 +299,6 @@
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
}, },
"buffer-writer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz",
"integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw=="
},
"bufferutil": { "bufferutil": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.1.tgz", "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.1.tgz",
@ -612,6 +617,11 @@
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o="
}, },
"denque": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
"integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
},
"detect-libc": { "detect-libc": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
@ -1389,6 +1399,11 @@
"resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.3.1.tgz", "resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.3.1.tgz",
"integrity": "sha512-zCTP6Qd/WwjrpuHFkJuXc5opRdKprUr7eI7+JCCtcetThJt45qptu82MWQ+eET+FtDrMo7+BYjo3iD0XIq1L9Q==" "integrity": "sha512-zCTP6Qd/WwjrpuHFkJuXc5opRdKprUr7eI7+JCCtcetThJt45qptu82MWQ+eET+FtDrMo7+BYjo3iD0XIq1L9Q=="
}, },
"kareem": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz",
"integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw=="
},
"kuler": { "kuler": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
@ -1451,6 +1466,12 @@
"triple-beam": "^1.3.0" "triple-beam": "^1.3.0"
} }
}, },
"memory-pager": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
"optional": true
},
"mime-db": { "mime-db": {
"version": "1.42.0", "version": "1.42.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.42.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.42.0.tgz",
@ -1551,6 +1572,97 @@
"moment": ">= 2.9.0" "moment": ">= 2.9.0"
} }
}, },
"mongodb": {
"version": "3.5.9",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.9.tgz",
"integrity": "sha512-vXHBY1CsGYcEPoVWhwgxIBeWqP3dSu9RuRDsoLRPTITrcrgm1f0Ubu1xqF9ozMwv53agmEiZm0YGo+7WL3Nbug==",
"requires": {
"bl": "^2.2.0",
"bson": "^1.1.4",
"denque": "^1.4.1",
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
"saslprep": "^1.0.0"
},
"dependencies": {
"bl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
"integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
"requires": {
"readable-stream": "^2.3.5",
"safe-buffer": "^5.1.1"
}
}
}
},
"mongoose": {
"version": "5.9.25",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.25.tgz",
"integrity": "sha512-vz/DqJ3mrHqEIlfRbKmDZ9TzQ1a0hCtSQpjHScIxr4rEtLs0tjsXDeEWcJ/vEEc3oLfP6vRx9V+uYSprXDUvFQ==",
"requires": {
"bson": "^1.1.4",
"kareem": "2.3.1",
"mongodb": "3.5.9",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.7.0",
"mquery": "3.2.2",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
"safe-buffer": "5.2.1",
"sift": "7.0.1",
"sliced": "1.0.1"
},
"dependencies": {
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
}
}
},
"mongoose-legacy-pluralize": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",
"integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ=="
},
"mpath": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz",
"integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg=="
},
"mquery": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.2.tgz",
"integrity": "sha512-XB52992COp0KP230I3qloVUbkLUxJIu328HBP2t2EsxSFtf4W1HPSOBWOXf1bqxK4Xbb66lfMJ+Bpfd9/yZE1Q==",
"requires": {
"bluebird": "3.5.1",
"debug": "3.1.0",
"regexp-clone": "^1.0.0",
"safe-buffer": "5.1.2",
"sliced": "1.0.1"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
"ms": { "ms": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
@ -1753,11 +1865,6 @@
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
}, },
"packet-reader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz",
"integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ=="
},
"parent-module": { "parent-module": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
@ -1807,96 +1914,11 @@
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
"integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA="
}, },
"pg": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.3.0.tgz",
"integrity": "sha512-jQPKWHWxbI09s/Z9aUvoTbvGgoj98AU7FDCcQ7kdejupn/TcNpx56v2gaOTzXkzOajmOEJEdi9eTh9cA2RVAjQ==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "^2.3.0",
"pg-pool": "^3.2.1",
"pg-protocol": "^1.2.5",
"pg-types": "^2.1.0",
"pgpass": "1.x",
"semver": "4.3.2"
},
"dependencies": {
"semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
}
}
},
"pg-connection-string": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.3.0.tgz",
"integrity": "sha512-ukMTJXLI7/hZIwTW7hGMZJ0Lj0S2XQBCJ4Shv4y1zgQ/vqVea+FLhzywvPj0ujSuofu+yA4MYHGZPTsgjBgJ+w=="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-pool": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.2.1.tgz",
"integrity": "sha512-BQDPWUeKenVrMMDN9opfns/kZo4lxmSWhIqo+cSAF7+lfi9ZclQbr9vfnlNaPr8wYF3UYjm5X0yPAhbcgqNOdA=="
},
"pg-protocol": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.2.5.tgz",
"integrity": "sha512-1uYCckkuTfzz/FCefvavRywkowa6M5FohNMF5OjKrqo9PSR8gYc8poVmwwYQaBxhmQdBjhtP514eXy9/Us2xKg=="
},
"pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "^1.0.0"
}
},
"pngjs": { "pngjs": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-3.4.0.tgz", "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-3.4.0.tgz",
"integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w==" "integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="
}, },
"postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA=="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.5.tgz",
"integrity": "sha512-pdau6GRPERdAYUQwkBnGKxEfPyhVZXG/JiS44iZWiNdSOWE09N2lUgN6yshuq6fVSon4Pm0VMXd1srUUkLe9iA=="
},
"postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"prebuild-install": { "prebuild-install": {
"version": "5.3.5", "version": "5.3.5",
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.5.tgz", "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.5.tgz",
@ -2070,6 +2092,11 @@
"resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz", "resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz",
"integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA==" "integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA=="
}, },
"regexp-clone": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
"integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
},
"regexpp": { "regexpp": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz",
@ -2086,6 +2113,22 @@
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
}, },
"require_optional": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
"integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
"requires": {
"resolve-from": "^2.0.0",
"semver": "^5.1.0"
},
"dependencies": {
"resolve-from": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
"integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
}
}
},
"resolve-from": { "resolve-from": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
@ -2148,6 +2191,15 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true "dev": true
}, },
"saslprep": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
"integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
"optional": true,
"requires": {
"sparse-bitfield": "^3.0.3"
}
},
"semver": { "semver": {
"version": "5.7.0", "version": "5.7.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
@ -2195,6 +2247,11 @@
"integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
"dev": true "dev": true
}, },
"sift": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz",
"integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g=="
},
"signal-exit": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
@ -2249,6 +2306,11 @@
"is-fullwidth-code-point": "^2.0.0" "is-fullwidth-code-point": "^2.0.0"
} }
}, },
"sliced": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
"integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
},
"sodium-native": { "sodium-native": {
"version": "2.4.6", "version": "2.4.6",
"resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-2.4.6.tgz", "resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-2.4.6.tgz",
@ -2274,12 +2336,13 @@
} }
} }
}, },
"split": { "sparse-bitfield": {
"version": "1.0.1", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==", "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
"optional": true,
"requires": { "requires": {
"through": "2" "memory-pager": "^1.0.2"
} }
}, },
"sprintf-js": { "sprintf-js": {
@ -2474,7 +2537,8 @@
"through": { "through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
"dev": true
}, },
"token-types": { "token-types": {
"version": "2.0.0", "version": "2.0.0",
@ -2676,11 +2740,6 @@
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==" "integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
}, },
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
},
"y18n": { "y18n": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",

View File

@ -32,11 +32,11 @@
"lavacord": "^1.1.9", "lavacord": "^1.1.9",
"moment": "^2.27.0", "moment": "^2.27.0",
"moment-duration-format": "^2.3.2", "moment-duration-format": "^2.3.2",
"mongoose": "^5.9.25",
"node-addon-api": "^3.0.1", "node-addon-api": "^3.0.1",
"node-emoji": "^1.10.0", "node-emoji": "^1.10.0",
"node-fetch": "^2.6.0", "node-fetch": "^2.6.0",
"node-tweet": "^0.1.4", "node-tweet": "^0.1.4",
"pg": "^8.3.0",
"puppeteer-core": "^2.1.1", "puppeteer-core": "^2.1.1",
"qrcode": "^1.4.4", "qrcode": "^1.4.4",
"retrotext": "github:TheEssem/retrotext", "retrotext": "github:TheEssem/retrotext",

View File

@ -1,9 +1,20 @@
// database stuff // database stuff
const { Pool } = require("pg"); const mongoose = require("mongoose");
const pool = new Pool({ mongoose.connect(process.env.MONGO, { poolSize: 10, bufferMaxEntries: 0, useNewUrlParser: true, useUnifiedTopology: true });
user: "esmbot", const guildSchema = new mongoose.Schema({
host: "localhost", id: String,
database: "esmbot", tags: Map,
port: 5432 prefix: String,
warns: Map,
disabledChannels: [String]
}); });
module.exports = pool; const Guild = mongoose.model("Guild", guildSchema);
const globalSchema = new mongoose.Schema({
cmdCounts: Map
});
const Global = mongoose.model("Global", globalSchema);
exports.guilds = Guild;
exports.global = Global;
exports.connection = mongoose.connection;