Initial commit

This commit is contained in:
TheEssem 2019-09-13 15:02:41 -05:00
commit c33a86eb4c
132 changed files with 5860 additions and 0 deletions

7
events/error.js Normal file
View file

@ -0,0 +1,7 @@
const logger = require("../utils/logger.js");
// run when eris encounters an error
module.exports = async (error, id) => {
logger.error(`An error event was sent by Eris in shard ${id}: \n${error.toString()}`);
logger.error(error.toString());
};

11
events/guildCreate.js Normal file
View file

@ -0,0 +1,11 @@
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
const misc = require("../utils/misc.js");
const client = require("../utils/client.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. Owner: ${client.users.get(guild.ownerID).username + client.users.get(guild.ownerID).discriminator} (${guild.ownerID})`);
database.settings.set(guild.id, misc.defaults);
database.tags.set(guild.id, misc.tagDefaults);
};

9
events/guildDelete.js Normal file
View file

@ -0,0 +1,9 @@
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
// run when the bot is removed from a guild
module.exports = async (guild) => {
logger.log(`[GUILD LEAVE] ${guild.name} (${guild.id}) removed the bot.`);
database.settings.delete(guild.id);
database.tags.delete(guild.id);
};

60
events/messageCreate.js Normal file
View file

@ -0,0 +1,60 @@
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const misc = require("../utils/misc.js");
const logger = require("../utils/logger.js");
const collections = require("../utils/collections.js");
// run when someone sends a message
module.exports = async (message) => {
// ignore dms and other bots
if (message.author.bot) return;
if (!message.channel.guild) return;
// prefix can be a mention or a set of special characters
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
const guildConf = database.settings.ensure(message.channel.guild.id, misc.defaults);
const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildConf.prefix;
// ignore other stuff
if (message.content.startsWith(prefix) === false && message.mentions.indexOf(client.user) <= -1 && message.channel.id !== "573553254575898626") return;
// funny stuff
if (message.channel.id === "573553254575898626" && message.channel.guild.id === "433408970955423765") {
const generalChannel = client.guilds.get("322114245632327703").channels.get("322114245632327703");
if (message.attachments.length !== 0) {
const attachments = [];
for (const attachment of message.attachments) {
const res = await require("node-fetch")(attachment.url);
attachments.push({ file: await res.buffer(), name: attachment.filename });
}
await client.createMessage(generalChannel.id, message.content, attachments);
} else {
await client.createMessage(generalChannel.id, message.content);
}
}
// separate commands and args
const escapedPrefix = misc.regexEscape(prefix);
const prefixRegex = new RegExp(`^(${escapedPrefix})`);
const args = message.content.replace(prefixRegex, "").trim().split(/ +/g);
const command = args.shift().toLowerCase();
// check if command exists
const cmd = collections.commands.get(command) || collections.commands.get(collections.aliases.get(command));
if (!cmd) return;
// actually run the command
logger.log("info", `${message.author.username} (${message.author.id}) ran command ${command}`);
try {
const result = await cmd(message, args);
if (typeof result === "string") {
await client.createMessage(message.channel.id, result);
}
} catch (error) {
logger.error(error.stack);
await client.createMessage(message.channel.id, "Uh oh! I ran into an error while running this command. Please report the content of the attached file here: <https://github.com/TheEssem/esmBot-rewrite/issues>", [{
file: Buffer.from(`Message: ${error}\n\nStack Trace: ${error.stack}`),
name: "error.txt"
}]);
}
};

22
events/ready.js Normal file
View file

@ -0,0 +1,22 @@
const client = require("../utils/client.js");
const database = require("../utils/database.js");
const logger = require("../utils/logger.js");
const config = require("../config.json");
const misc = require("../utils/misc.js");
// run when ready
module.exports = async () => {
// make sure settings/tags exist
client.guilds.forEach(guild => {
database.settings.ensure(guild.id, misc.defaults);
database.tags.ensure(guild.id, misc.tagDefaults);
});
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
client.editStatus("dnd", { name: `${misc.random(config.activityMessages)} | @esmBot help` });
setTimeout(activityChanger, 900000);
})();
logger.log("info", `Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
};

6
events/warn.js Normal file
View file

@ -0,0 +1,6 @@
const logger = require("../utils/logger.js");
// run when eris encounters a warning
module.exports = async (warn, id) => {
logger.warn(`A warn event was sent by Eris in shard ${id}: \n${warn.toString()}`);
};