Added support for using both MongoDB and PostgreSQL, changed image api timeouts, removed all moderation commands

This commit is contained in:
TheEssem 2020-12-17 20:32:19 -06:00
parent 69d8100f23
commit ef945adf09
21 changed files with 683 additions and 371 deletions

View file

@ -1,31 +0,0 @@
const client = require("../utils/client.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("banMembers")) return `${message.author.mention}, you need to have the \`Ban Members\` permission on this server to ban people!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("banMembers") && !message.channel.permissionsOf(client.user.id).has("banMembers")) return `${message.author.mention}, I don't have the \`Ban Members\` permission!`;
const member = message.mentions[0];
if (member) {
try {
await message.channel.guild.banMember(member.id, 0, `Ban command used by @${message.author.username}#${message.author.discriminator}`);
return `Successfully banned ${member.mention}.`;
} catch (e) {
return `${message.author.mention}, I was unable to ban the member. They might not exist or I don't have the permissions to do so.`;
}
} else if (args[0].match(/^<?[@#]?[&!]?\d+>?$/) && args[0] >= 21154535154122752) {
try {
const id = args[0].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "");
await message.channel.guild.banMember(id, 0, `Banned by ID, command used by @${message.author.username}#${message.author.discriminator}`);
return `Successfully banned user with ID \`${id}\`.`;
} catch (e) {
return `${message.author.mention}, I was unable to ban the member. They might not exist or I don't have the permissions to do so.`;
}
} else {
return `${message.author.mention}, you need to provide a member to ban!`;
}
};
exports.aliases = ["hackban", "prevent", "preban"];
exports.category = 2;
exports.help = "Bans a server member";
exports.params = "[mention/id]";

View file

@ -5,28 +5,34 @@ 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 (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!`;
const guildDB = await db.guilds.findOne({id: message.channel.guild.id});
const guildDB = await db.getGuild(message.channel.guild.id);
if (args[0].toLowerCase() === "disable") {
let channel;
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
const id = args[1].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "");
if (guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.disabledChannels.push(id);
if (guildDB.disabled.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
channel = message.channel.guild.channels.get(id);
} else {
if (guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.disabledChannels.push(message.channel.id);
if (guildDB.disabled.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
channel = message.channel;
}
await guildDB.save();
await db.disableChannel(channel);
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") {
let channel;
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
const id = args[1].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "");
if (!guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== id);
if (!guildDB.disabled.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
channel = message.channel.guild.channels.get(id);
} else {
if (!guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm not disabled in this channel!`;
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== message.channel.id );
if (!guildDB.disabled.includes(message.channel.id)) return `${message.author.mention}, I'm not disabled in this channel!`;
channel = message.channel;
}
await guildDB.save();
await db.enableChannel(channel);
return `${message.author.mention}, I have been re-enabled in this channel.`;
}
};

View file

@ -5,9 +5,9 @@ const database = require("../utils/database.js");
exports.run = async (message) => {
if (message.channel.guild && !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 && !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.global.findOne({})).cmdCounts;
const counts = await database.getCounts();
const countArray = [];
const sortedValues = [...counts.entries()].sort((a, b) => {
const sortedValues = counts.sort((a, b) => {
return b[1] - a[1];
});
for (const [key, value] of sortedValues) {

View file

@ -6,13 +6,18 @@ 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.", "esmBot is hosted and paid for completely out-of-pocket by the main developer. If you want to support development, please consider donating! https://patreon.com/TheEssem"];
exports.run = async (message, args) => {
const { prefix } = message.channel.guild ? await database.guilds.findOne({ id: message.channel.guild.id }) : "N/A";
const { prefix } = message.channel.guild ? await database.getGuild(message.channel.guild.id) : "N/A";
const commands = collections.commands;
const aliases = collections.aliases;
if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) {
const command = aliases.has(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase();
const info = collections.info.get(command);
const counts = (await database.global.findOne({})).cmdCounts;
const countDB = await database.getCounts();
const counts = countDB.reduce((acc, val) => {
const [key, value] = val;
acc[key] = value;
return acc;
}, {});
const embed = {
"embed": {
"author": {
@ -28,7 +33,7 @@ exports.run = async (message, args) => {
"value": info.aliases ? info.aliases.join(", ") : "None"
}, {
"name": "Times Used",
"value": counts.get(command),
"value": counts[command],
"inline": true
}, {
"name": "Parameters",

View file

@ -1,23 +0,0 @@
const client = require("../utils/client.js");
exports.run = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("kickMembers")) return `${message.author.mention}, you need to have the \`Kick Members\` permission on this server to kick people!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("kickMembers") && !message.channel.permissionsOf(client.user.id).has("kickMembers")) return `${message.author.mention}, I don't have the \`Kick Members\` permission!`;
const member = message.mentions[0];
if (member) {
try {
await message.channel.guild.kickMember(member.id, `kick command used by @${message.author.username}#${message.author.discriminator}`);
return `Successfully kicked ${member.mention}.`;
} catch (error) {
throw error;
//return `${message.author.mention}, I was unable to kick the member. Have you given me permissions?`;
}
} else {
return `${message.author.mention}, you need to provide a member to kick!`;
}
};
exports.category = 2;
exports.help = "Kicks a member";
exports.params = "[mention]";

View file

@ -2,11 +2,10 @@ const database = require("../utils/database.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const guild = await database.getGuild(message.channel.guild.id);
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!`;
guild.set("prefix", args[0]);
await guild.save();
await database.setPrefix(args[0], message.channel.guild);
return `The prefix has been changed to ${args[0]}.`;
} else {
return `${message.author.mention}, the current prefix is \`${guild.prefix}\`.`;

View file

@ -1,16 +0,0 @@
const client = require("../utils/client.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to purge messages!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("manageMessages") && !message.channel.permissionsOf(client.user.id).has("manageMessages")) return `${message.author.mention}, I don't have the \`Manage Messages\` permission!`;
if (args.length === 0 || !args[0].match(/^\d+$/)) return `${message.author.mention}, you need to provide the number of messages to purge!`;
const numberOfMessages = parseInt(args[0]) + 1;
const number = await message.channel.purge(numberOfMessages);
return `Successfully purged ${number - 1} messages.`;
};
exports.aliases = ["prune"];
exports.category = 2;
exports.help = "Purges messages in a channel";
exports.params = "[number]";

View file

@ -5,45 +5,45 @@ const { random } = require("../utils/misc.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
if (guild.tagsDisabled && args[0].toLowerCase() !== ("enable" || "disable")) return;
const guild = await database.getGuild(message.channel.guild.id);
if ((guild.tagsDisabled || guild.tags_disabled) && args[0].toLowerCase() !== ("enable" || "disable")) return;
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
const tags = guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
const tags = guild.tags instanceof Map ? Object.fromEntries(guild.tags) : guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random", "own", "owner", "enable", "disable"];
switch (args[0].toLowerCase()) {
case "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 (tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
if (tags[args[1].toLowerCase()]) return `${message.author.mention}, this tag already exists!`;
var result = await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
if (result) return result;
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been added!`;
case "delete":
case "remove":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to delete!`;
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && !message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
tags.set(args[1].toLowerCase(), undefined);
await guild.save();
if (!tags[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("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
await database.removeTag(args[1].toLowerCase(), message.channel.guild);
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been deleted!`;
case "edit":
if (args[1] === undefined) return `${message.author.mention}, you need to provide the name of the tag you want to edit!`;
if (!tags.has(args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
if (tags.get(args[1].toLowerCase()).author !== message.author.id && !message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
if (!tags[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("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
return `${message.author.mention}, the tag \`${args[1].toLowerCase()}\` has been edited!`;
case "own":
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 (!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.get(args[1].toLowerCase()).author).username}#${client.users.get(tags.get(args[1].toLowerCase()).author).discriminator}** (\`${tags.get(args[1].toLowerCase()).author}\`).`;
if (!tags[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}\`).`;
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("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 embeds = [];
var groups = [...tags.keys()].map((item, index) => {
return index % pageSize === 0 ? [...tags.keys()].slice(index, index + pageSize) : null;
var groups = Object.keys(tags).map((item, index) => {
return index % pageSize === 0 ? Object.keys(tags).slice(index, index + pageSize) : null;
}).filter((item) => {
return item;
});
@ -67,36 +67,26 @@ exports.run = async (message, args) => {
if (embeds.length === 0) return `${message.author.mention}, I couldn't find any tags!`;
return paginator(message, embeds);
case "random":
return random([...tags])[1].content;
return tags[random(Object.keys(tags))].content;
case "enable":
case "disable":
if (!message.member.permission.has("manageMessages") && message.author.id !== process.env.OWNER) return `${message.author.mention}, you don't have permission to disable tags!`;
var status;
if (guild.tagsDisabled) {
status = false;
} else {
status = true;
}
guild.set("tagsDisabled", status);
await guild.save();
return `${message.author.mention}, tags for this guild have been ${status ? "disabled" : "enabled"}. To ${status ? "enable" : "disable"} them again, run ${guild.prefix}tags ${status ? "enable" : "disable"}.`;
var toggleResult = await database.toggleTags(message.channel.guild);
return `${message.author.mention}, tags for this guild have been ${toggleResult ? "disabled" : "enabled"}. To ${toggleResult ? "enable" : "disable"} them again, run ${guild.prefix}tags ${toggleResult ? "enable" : "disable"}.`;
default:
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
return tags.get(args[0].toLowerCase()).content;
if (!tags[args[0].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`;
return tags[args[0].toLowerCase()].content;
}
};
const setTag = async (content, name, message, guild) => {
const setTag = async (content, name, message) => {
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) {
guild.tags.set(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id });
await guild.save();
await database.setTag(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }, message.channel.guild);
} else if (message.attachments.length !== 0) {
guild.tags.set(name, { content: message.attachments[0].url, author: message.author.id });
await guild.save();
await database.setTag(name, { content: message.attachments[0].url, author: message.author.id }, message.channel.guild);
} else {
guild.tags.set(name, { content: content, author: message.author.id });
await guild.save();
await database.setTag(name, { content: content, author: message.author.id }, message.channel.guild);
}
return;
};

View file

@ -1,76 +0,0 @@
const database = require("../utils/database.js");
const client = require("../utils/client.js");
const paginator = require("../utils/pagination/pagination.js");
exports.run = async (message, args) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.permission.has("manageMessages")) return `${message.author.mention}, you need to have the \`Manage Messages\` permission on this server to warn people!`;
if (!args[0]) return `${message.author.mention}, you need to provide a member to warn!`;
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, ""));
if (member) {
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
if (args[1].toLowerCase() === "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("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const warnArray = [];
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} (${value.time.toUTCString()})`);
}
const pageSize = 15;
const embeds = [];
const groups = warnArray.map((item, index) => {
return index % pageSize === 0 ? warnArray.slice(index, index + pageSize) : null;
}).filter((item) => {
return item;
});
for (const [i, value] of groups.entries()) {
embeds.push({
"embed": {
"title": "Warn List",
"color": 16711680,
"footer": {
"text": `Page ${i + 1} of ${groups.length}`
},
"description": value.join("\n"),
"author": {
"name": member.username,
"icon_url": member.avatarURL
}
}
});
}
if (embeds.length === 0) return `${message.author.mention}, I couldn't find any warns for this user!`;
return paginator(message, embeds);
} else if (args[1].toLowerCase() === "remove") {
if (args[2] < 1 || !array[args[2] - 1]) return `${message.author.mention}, there aren't any warns with that ID!`;
array.splice(args[2] - 1, 1);
guild.warns.set(member.id, {
count: guild.warns.get(member.id).count - 1,
warns: array
});
await guild.save();
return `Successfully removed the warning for ${member.mention}.`;
} else {
args.shift();
array.push({
message: args.join(" "),
time: new Date(),
creator: message.author.id
});
guild.warns.set(member.id, {
count: (guild.warns.get(member.id) ? guild.warns.get(member.id).count : 0) + 1,
warns: array
});
await guild.save();
return `Successfully warned ${member.mention} for \`${args.join(" ")}\`.`;
}
} else {
return `${message.author.mention}, you need to provide a member to warn!`;
}
};
exports.category = 2;
exports.help = "Warns a server member";
exports.params = "[mention] {reason/list/remove} {number}";