Added support for using both MongoDB and PostgreSQL, changed image api timeouts, removed all moderation commands
This commit is contained in:
parent
69d8100f23
commit
ef945adf09
21 changed files with 683 additions and 371 deletions
|
@ -1,18 +1,8 @@
|
|||
const db = require("../utils/database.js");
|
||||
const logger = require("../utils/logger.js");
|
||||
const misc = require("../utils/misc.js");
|
||||
|
||||
// run when the bot is added to a guild
|
||||
module.exports = async (guild) => {
|
||||
logger.log("info", `[GUILD JOIN] ${guild.name} (${guild.id}) added the bot.`);
|
||||
const guildDB = new db.guilds({
|
||||
id: guild.id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: process.env.PREFIX,
|
||||
warns: {},
|
||||
disabledChannels: [],
|
||||
tagsDisabled: false
|
||||
});
|
||||
await guildDB.save();
|
||||
return guildDB;
|
||||
await db.addGuild(guild);
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@ const client = require("../utils/client.js");
|
|||
const database = require("../utils/database.js");
|
||||
const logger = require("../utils/logger.js");
|
||||
const collections = require("../utils/collections.js");
|
||||
const guildCreate = require("./guildCreate.js");
|
||||
const commands = [...collections.aliases.keys(), ...collections.commands.keys()];
|
||||
|
||||
// run when someone sends a message
|
||||
|
@ -24,13 +23,21 @@ module.exports = async (message) => {
|
|||
}
|
||||
if (!valid) return;
|
||||
|
||||
// prefix can be a mention or a set of special characters
|
||||
let guildDB = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }).lean().exec() : null;
|
||||
if (message.channel.guild && !guildDB) {
|
||||
guildDB = await guildCreate(message.channel.guild);
|
||||
let prefixCandidate;
|
||||
if (collections.prefixCache.has(message.channel.guild.id)) {
|
||||
prefixCandidate = collections.prefixCache.get(message.channel.guild.id);
|
||||
} else {
|
||||
let guildDB = message.channel.guild ? await database.getGuild(message.channel.guild.id) : null;
|
||||
if (message.channel.guild && !(guildDB && guildDB.disabled)) {
|
||||
guildDB = await database.fixGuild(message.channel.guild);
|
||||
}
|
||||
prefixCandidate = guildDB.prefix;
|
||||
collections.prefixCache.set(message.channel.guild.id, guildDB.prefix);
|
||||
}
|
||||
// there's a bit of a workaround here due to member.mention not accounting for both mention types
|
||||
const prefix = message.channel.guild ? (message.content.startsWith(message.channel.guild.members.get(client.user.id).mention) ? `${message.channel.guild.members.get(client.user.id).mention} ` : (message.content.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}> ` : guildDB.prefix)) : "";
|
||||
|
||||
// this line be like Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain. Pain.
|
||||
// there's also bit of a workaround here due to member.mention not accounting for both mention types
|
||||
const prefix = message.channel.guild ? (message.content.startsWith(message.channel.guild.members.get(client.user.id).mention) ? `${message.channel.guild.members.get(client.user.id).mention} ` : (message.content.startsWith(`<@${client.user.id}>`) ? `<@${client.user.id}> ` : prefixCandidate)) : "";
|
||||
|
||||
// ignore other stuff
|
||||
if (message.content.startsWith(prefix) === false) return;
|
||||
|
@ -41,7 +48,14 @@ module.exports = async (message) => {
|
|||
const command = args.shift().toLowerCase();
|
||||
|
||||
// don't run if message is in a disabled channel
|
||||
if (guildDB && guildDB.disabledChannels && guildDB.disabledChannels.includes(message.channel.id) && command != "channel") return;
|
||||
if (collections.disabledCache.has(message.channel.guild.id)) {
|
||||
const disabled = collections.disabledCache.get(message.channel.guild.id);
|
||||
if (disabled.includes(message.channel.id) && command != "channel") return;
|
||||
} else if (message.channel.guild) {
|
||||
const guildDB = await database.getGuild(message.channel.guild.id);
|
||||
collections.disabledCache.set(message.channel.guild.id, guildDB.disabled);
|
||||
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return;
|
||||
}
|
||||
|
||||
// check if command exists
|
||||
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
|
||||
|
@ -50,10 +64,7 @@ module.exports = async (message) => {
|
|||
// actually run the command
|
||||
logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`);
|
||||
try {
|
||||
const global = (await database.global.findOne({}).exec());
|
||||
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();
|
||||
await database.addCount(collections.aliases.has(command) ? collections.aliases.get(command) : command);
|
||||
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)) {
|
||||
await client.createMessage(message.channel.id, result);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const client = require("../utils/client.js");
|
||||
const database = require("../utils/database.js");
|
||||
const collections = require("../utils/collections.js");
|
||||
const logger = require("../utils/logger.js");
|
||||
const messages = require("../messages.json");
|
||||
const misc = require("../utils/misc.js");
|
||||
|
@ -16,58 +15,7 @@ module.exports = async () => {
|
|||
// connect to lavalink
|
||||
if (!soundPlayer.status && !soundPlayer.connected) await soundPlayer.connect();
|
||||
|
||||
// make sure settings/tags exist
|
||||
for (const [id] of client.guilds) {
|
||||
const guildDB = await database.guilds.findOne({id: id});
|
||||
if (!guildDB) {
|
||||
logger.log(`Registering guild database entry for guild ${id}...`);
|
||||
const newGuild = new database.guilds({
|
||||
id: id,
|
||||
tags: misc.tagDefaults,
|
||||
prefix: process.env.PREFIX,
|
||||
warns: {},
|
||||
disabledChannels: [],
|
||||
tagsDisabled: false
|
||||
});
|
||||
await newGuild.save();
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const global = await database.global.findOne({});
|
||||
if (!global) {
|
||||
const countObject = {};
|
||||
for (const command of collections.commands.keys()) {
|
||||
countObject[command] = 0;
|
||||
}
|
||||
const newGlobal = new database.global({
|
||||
cmdCounts: countObject
|
||||
});
|
||||
await newGlobal.save();
|
||||
} else {
|
||||
const exists = [];
|
||||
for (const command of collections.commands.keys()) {
|
||||
if (!global.cmdCounts.has(command)) {
|
||||
global.cmdCounts.set(command, 0);
|
||||
}
|
||||
exists.push(command);
|
||||
}
|
||||
for (const command of global.cmdCounts.keys()) {
|
||||
if (!exists.includes(command)) {
|
||||
global.cmdCounts.set(command, undefined);
|
||||
}
|
||||
}
|
||||
await global.save();
|
||||
}
|
||||
await database.handleCounts();
|
||||
|
||||
// generate docs
|
||||
if (helpGenerator && first) await helpGenerator(process.env.OUTPUT);
|
||||
|
@ -104,16 +52,8 @@ module.exports = async () => {
|
|||
try {
|
||||
const stream = twitter.client.statuses.filter(`@${process.env.HANDLE}`);
|
||||
stream.on("data", async (tweet) => {
|
||||
if (
|
||||
tweet.user.screen_name !== "esmBot_" &&
|
||||
!blocks.ids.includes(tweet.user.id_str)
|
||||
) {
|
||||
let tweetContent;
|
||||
if (new RegExp(["@this_vid", "@DownloaderBot", "GetVideoBot", "@thisvid_"].join("|")).test(tweet.text)) {
|
||||
tweetContent = await misc.getTweet(twitter.tweets, true, true);
|
||||
} else {
|
||||
tweetContent = await misc.getTweet(twitter.tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
|
||||
}
|
||||
if (tweet.user.screen_name !== "esmBot_" && !blocks.ids.includes(tweet.user.id_str)) {
|
||||
const tweetContent = await misc.getTweet(twitter.tweets, true).replace(/{{user}}/gm, `@${tweet.user.screen_name}`);
|
||||
const payload = {
|
||||
status: `@${tweet.user.screen_name} ${tweetContent}`,
|
||||
in_reply_to_status_id: tweet.id_str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue