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

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 (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.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[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
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!`;
guildDB.rows[0].disabled.push(id);
if (guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.disabledChannels.push(id);
} else {
if (guildDB.rows[0].disabled.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
guildDB.rows[0].disabled.push(message.channel.id);
if (guildDB.disabledChannels.includes(message.channel.id)) return `${message.author.mention}, I'm already disabled in this channel!`;
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]);
return `${message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.rows[0].prefix}channel enable\`.`;
await guildDB.save();
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") {
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
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!`;
guildDB.rows[0].disabled = guildDB.rows[0].disabled.filter(item => item !== id);
if (!guildDB.disabledChannels.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== id);
} else {
if (!guildDB.rows[0].disabled.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 );
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 );
}
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.`;
}
};

View file

@ -5,13 +5,13 @@ const database = require("../utils/database.js");
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("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 sortedValues = counts.rows.sort((a, b) => {
return b.count - a.count;
const sortedValues = [...counts.entries()].sort((a, b) => {
return b[1] - a[1];
});
for (const { command, count } of sortedValues) {
countArray.push(`**${command}**: ${count}`);
for (const [key, value] of sortedValues) {
countArray.push(`**${key}**: ${value}`);
}
const embeds = [];
const groups = countArray.map((item, index) => {

View file

@ -1,5 +1,6 @@
const magick = require("../build/Release/image.node");
const { promisify } = require("util");
const fs = require("fs");
const emojiRegex = require("emoji-regex");
const emoji = require("node-emoji");
@ -11,6 +12,14 @@ exports.run = async (message, args) => {
const flag = emoji.unemojify(args[0]).replace(/:/g, "").replace("flag-", "");
let path = `./assets/images/region-flags/png/${flag.toUpperCase()}.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);
return {
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."];
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 aliases = collections.aliases;
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",
"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",
"description": info.description,
"color": 16711680,
@ -94,7 +94,7 @@ exports.run = async (message, args) => {
},
"fields": [{
"name": "Prefix",
"value": guildDB.rows[0].prefix
"value": guild.prefix
}, {
"name": "Tip",
"value": misc.random(tips)

View file

@ -1,14 +1,14 @@
const database = require("../utils/database.js");
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 (!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!`;
await database.query("UPDATE guilds SET prefix = $1 WHERE guild_id = $2", [args[0], message.channel.guild.id]);
guild.set("prefix", args[0]);
await guild.save();
return `The prefix has been changed to ${args[0]}.`;
} 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) => {
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 tags = guildDB.rows[0].tags;
const guild = await database.guilds.findOne({ id: message.channel.guild.id });
const tags = guild.tags;
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
switch (args[0].toLowerCase()) {
case "create":
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[args[1].toLowerCase()]) return `${message.author.mention}, this tag already exists!`;
var result = await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guildDB);
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, 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[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!`;
delete tags[args[1].toLowerCase()];
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [tags, message.channel.guild.id]);
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.author.id !== process.env.OWNER) return `${message.author.mention}, you don't own this tag!`;
tags.set(args[1].toLowerCase(), undefined);
await guild.save();
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[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!`;
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guildDB);
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 && 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, 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[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}\`).`;
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}\`).`;
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 = Object.keys(tags).map((item, index) => {
return index % pageSize === 0 ? Object.keys(tags).slice(index, index + pageSize) : null;
var groups = [...tags.keys()].map((item, index) => {
return index % pageSize === 0 ? [...tags.keys()].slice(index, index + pageSize) : null;
}).filter((item) => {
return item;
});
@ -68,21 +67,23 @@ exports.run = async (message, args) => {
case "random":
return random([...tags])[1].content;
default:
if (!tags[args[0].toLowerCase()]) return `${message.author.mention}, this tag doesn't exist!`;
return tags[args[0].toLowerCase()].content;
if (!tags.has(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
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 (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) {
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 {
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;
};

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 member = memberCheck ? memberCheck : client.users.get(args[0].replace(/\D/g, ""));
if (member) {
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]);
const array = guildDB.rows[0].warns[member.id] ? guildDB.rows[0].warns[member.id] : [];
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") {
args.shift();
array.push({
@ -16,8 +16,11 @@ exports.run = async (message, args) => {
time: new Date(),
creator: message.author.id
});
guildDB.rows[0].warns[member.id] = array;
await database.query("UPDATE guilds SET warns = $1 WHERE guild_id = $2", [guildDB.rows[0].warns, message.channel.guild.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();
//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(" ")}\`.`;
} 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!`;
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} (${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 embeds = [];