Moved from Enmap/SQLite to MongoDB
This commit is contained in:
parent
7d1ca165b7
commit
606c1ea1dc
11 changed files with 214 additions and 112 deletions
|
@ -1,6 +1,6 @@
|
|||
const database = require("../utils/database.js");
|
||||
|
||||
exports.run = async (message) => {
|
||||
const guildConf = database.settings.get(message.channel.guild.id);
|
||||
return `${message.author.mention}, my command list can be found here: https://essem.space/esmBot/commands.html?dev=true\nThis server's prefix is \`${guildConf.prefix}\`.`;
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
return `${message.author.mention}, my command list can be found here: https://essem.space/esmBot/commands.html?dev=true\nThis server's prefix is \`${guild.prefix}\`.`;
|
||||
};
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
const database = require("../utils/database.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
if (args.length !== 0) {
|
||||
if (!message.member.permission.has("administrator") && message.member.id !== "198198681982205953") return `${message.author.mention}, you need to be an administrator to change the bot prefix!`;
|
||||
database.settings.set(message.channel.guild.id, args[0], "prefix");
|
||||
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 \`${database.settings.get(message.channel.guild.id, "prefix")}\`.`;
|
||||
return `${message.author.mention}, the current prefix is \`${guild.prefix}\`.`;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,41 +1,44 @@
|
|||
const tags = require("../utils/database.js").tags;
|
||||
const database = require("../utils/database.js");
|
||||
const config = require("../config.json");
|
||||
const client = require("../utils/client.js");
|
||||
const paginator = require("../utils/pagination/pagination.js");
|
||||
const { random } = require("../utils/misc.js");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
const guild = (await database.find({ id: message.channel.guild.id }).exec())[0];
|
||||
const tags = guild.tags;
|
||||
const blacklist = ["add", "edit", "remove", "delete", "list", "random"];
|
||||
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.indexOf(args[1].toLowerCase()) > -1) return `${message.author.mention}, you can't make a tag with that name!`;
|
||||
if (tags.has(message.channel.guild.id, args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message);
|
||||
if (tags.exists(args[1].toLowerCase())) return `${message.author.mention}, this tag already exists!`;
|
||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message, guild);
|
||||
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(message.channel.guild.id, args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags.get(message.channel.guild.id, args[1].toLowerCase()).author !== message.author.id && tags.get(message.channel.guild.id, args[1].toLowerCase()).author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
tags.delete(message.channel.guild.id, args[1].toLowerCase());
|
||||
if (!tags.exists(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 !== config.botOwner) 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.has(message.channel.guild.id, args[1].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags.get(message.channel.guild.id, args[1].toLowerCase()).author !== message.author.id && tags.get(message.channel.guild.id, args[1].toLowerCase()).author !== config.botOwner) return `${message.author.mention}, you don't own this tag!`;
|
||||
await setTag(args.slice(2).join(" "), args[1].toLowerCase(), message);
|
||||
if (!tags.exists(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 !== config.botOwner) 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 "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.get(message.channel.guild.id)).map((item, index) => {
|
||||
return index % pageSize === 0 ? Object.keys(tags.get(message.channel.guild.id)).slice(index, index + pageSize) : null;
|
||||
}).filter((item) => {
|
||||
return item;
|
||||
console.log(Array.from(tags.keys()));
|
||||
var groups = Array.from(tags.keys()).map((item, index) => {
|
||||
return index % pageSize === 0 ? Array.from(tags.keys()).slice(index, index + pageSize) : null;
|
||||
});
|
||||
console.log(groups);
|
||||
for (const [i, value] of groups.entries()) {
|
||||
embeds.push({
|
||||
"embed": {
|
||||
|
@ -55,21 +58,22 @@ 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 tags.get(message.channel.guild.id, random(Object.keys(tags.get(message.channel.guild.id)))).content;
|
||||
return tags[random(Object.keys(tags))].content;
|
||||
default:
|
||||
if (args.length === 0) return `${message.author.mention}, you need to specify the name of the tag you want to view!`;
|
||||
if (!tags.has(message.channel.guild.id, args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
return tags.get(message.channel.guild.id, `${args[0].toLowerCase()}.content`);
|
||||
if (!tags.exists(args[0].toLowerCase())) return `${message.author.mention}, this tag doesn't exist!`;
|
||||
return tags[`${args[0].toLowerCase()}.content`];
|
||||
}
|
||||
};
|
||||
|
||||
const setTag = async (content, name, message) => {
|
||||
const setTag = async (content, name, message, guild) => {
|
||||
if (content === undefined || content.length === 0) return `${message.author.mention}, you need to provide the content of the tag!`;
|
||||
if (message.attachments.length !== 0) {
|
||||
tags.set(message.channel.guild.id, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }, name);
|
||||
guild.tags.set(name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id });
|
||||
} else {
|
||||
tags.set(message.channel.guild.id, { content: content, author: message.author.id }, name);
|
||||
guild.tags.set(name, { content: content, author: message.author.id });
|
||||
}
|
||||
await guild.save();
|
||||
};
|
||||
|
||||
exports.aliases = ["t", "tag", "ta"];
|
Loading…
Add table
Add a link
Reference in a new issue