Migrated database to PostgreSQL, updated packages
This commit is contained in:
parent
0760136ded
commit
2a67b76169
15 changed files with 362 additions and 570 deletions
|
@ -1,12 +1,15 @@
|
|||
const db = require("../utils/database.js");
|
||||
const { writeFile } = require("fs");
|
||||
const { promisify } = require("util");
|
||||
const tweets = require("../tweets.json");
|
||||
const twitter = require("../utils/twitter.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (message.author.id !== process.env.OWNER) return `${message.author.mention}, only the bot owner can add tweets!`;
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to add to the tweet database!`;
|
||||
if (args[1] === undefined) return `${message.author.mention}, you need to provide the content you want to add!`;
|
||||
const tweets = (await db.tweets.find({ enabled: true }).exec())[0];
|
||||
tweets[args[0]].push(args.slice(1).join(" "));
|
||||
await tweets.save();
|
||||
twitter.tweets = tweets;
|
||||
await promisify(writeFile)("../tweets.json", JSON.stringify(tweets, null, 2));
|
||||
return `${message.author.mention}, the content has been added.`;
|
||||
};
|
||||
|
||||
|
|
|
@ -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.guilds.find({id: message.channel.guild.id}).exec())[0];
|
||||
const guildDB = await db.query("SELECT * FROM guilds WHERE guild_id = $1", [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.disabledChannels.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
|
||||
guildDB.disabledChannels.push(id);
|
||||
if (guildDB.rows[0].disabled.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
|
||||
guildDB.rows[0].disabled.push(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.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);
|
||||
}
|
||||
await guildDB.save();
|
||||
return `${message.author.mention}, I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
|
||||
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\`.`;
|
||||
} 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.disabledChannels.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
|
||||
guildDB.disabledChannels = guildDB.disabledChannels.filter(item => item !== id);
|
||||
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);
|
||||
} 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.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 );
|
||||
}
|
||||
await guildDB.save();
|
||||
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 re-enabled in this channel.`;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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.global.findOne({}).lean().exec()).cmdCounts;
|
||||
const counts = await database.query("SELECT * FROM counts");
|
||||
const countArray = [];
|
||||
const sortedValues = Object.entries(counts).sort((a, b) => {
|
||||
return b[1] - a[1];
|
||||
const sortedValues = counts.rows.sort((a, b) => {
|
||||
return b.count - a.count;
|
||||
});
|
||||
for (const [key, value] of sortedValues) {
|
||||
countArray.push(`**${key}**: ${value}`);
|
||||
for (const { command, count } of sortedValues) {
|
||||
countArray.push(`**${command}**: ${count}`);
|
||||
}
|
||||
const embeds = [];
|
||||
const groups = countArray.map((item, index) => {
|
||||
|
|
|
@ -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 guild = (await database.guilds.find({ id: message.channel.guild.id }).lean().exec())[0];
|
||||
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [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": `${guild.prefix}${aliases.has(args[0].toLowerCase()) ? collections.aliases.get(args[0].toLowerCase()) : args[0].toLowerCase()}`,
|
||||
"title": `${guildDB.rows[0].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": guild.prefix
|
||||
"value": guildDB.rows[0].prefix
|
||||
}, {
|
||||
"name": "Tip",
|
||||
"value": misc.random(tips)
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
const database = require("../utils/database.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [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();
|
||||
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]);
|
||||
return `The prefix has been changed to ${args[0]}.`;
|
||||
} else {
|
||||
return `${message.author.mention}, the current prefix is \`${guild.prefix}\`.`;
|
||||
return `${message.author.mention}, the current prefix is \`${guildDB.rows[0].prefix}\`.`;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -5,43 +5,44 @@ 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 guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const tags = guild.tags;
|
||||
const guildDB = await database.query("SELECT * FROM guilds WHERE guild_id = $1", [message.channel.guild.id]);
|
||||
const tags = guildDB.rows[0].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.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 (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 (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.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.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]);
|
||||
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 && 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);
|
||||
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);
|
||||
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,23 +68,21 @@ exports.run = async (message, args) => {
|
|||
case "random":
|
||||
return random([...tags])[1].content;
|
||||
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, guildDB) => {
|
||||
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();
|
||||
guildDB.rows[0].tags[name] = { content: `${content} ${message.attachments[0].url}`, author: message.author.id };
|
||||
} else if (message.attachments.length !== 0) {
|
||||
guild.tags.set(name, { content: message.attachments[0].url, author: message.author.id });
|
||||
await guild.save();
|
||||
guildDB.rows[0].tags[name] = { content: message.attachments[0].url, author: message.author.id };
|
||||
} else {
|
||||
guild.tags.set(name, { content: content, author: message.author.id });
|
||||
await guild.save();
|
||||
guildDB.rows[0].tags[name] = { content: content, author: message.author.id };
|
||||
}
|
||||
await database.query("UPDATE guilds SET tags = $1 WHERE guild_id = $2", [guildDB.rows[0].tags, message.channel.guild.id]);
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,10 +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 guild = (await database.guilds.find({
|
||||
id: message.channel.guild.id
|
||||
}).exec())[0];
|
||||
const array = guild.warns.get(member.id) ? guild.warns.get(member.id).warns : [];
|
||||
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] : [];
|
||||
if (args[1].toLowerCase() !== "list") {
|
||||
args.shift();
|
||||
array.push({
|
||||
|
@ -18,11 +16,8 @@ exports.run = async (message, args) => {
|
|||
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();
|
||||
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]);
|
||||
//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 {
|
||||
|
@ -30,7 +25,8 @@ 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} (${value.time.toUTCString()})`);
|
||||
console.log(value);
|
||||
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()})`);
|
||||
}
|
||||
const pageSize = 15;
|
||||
const embeds = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue