Added command, reverted database service split
This commit is contained in:
parent
da709c485f
commit
9f36a79a2b
20 changed files with 119 additions and 91 deletions
|
@ -8,7 +8,7 @@ class ChannelCommand extends Command {
|
|||
if (this.args.length === 0) return "You need to provide whether I should be enabled or disabled in this channel!";
|
||||
if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!";
|
||||
|
||||
const guildDB = await db(this.ipc, "getGuild", this.message.channel.guild.id);
|
||||
const guildDB = await db.getGuild(this.message.channel.guild.id);
|
||||
|
||||
if (this.args[0].toLowerCase() === "disable") {
|
||||
let channel;
|
||||
|
@ -21,7 +21,7 @@ class ChannelCommand extends Command {
|
|||
channel = this.message.channel;
|
||||
}
|
||||
|
||||
await db(this.ipc, "disableChannel", channel);
|
||||
await db.disableChannel(channel);
|
||||
return `I have been disabled in this channel. To re-enable me, just run \`${guildDB.prefix}channel enable\`.`;
|
||||
} else if (this.args[0].toLowerCase() === "enable") {
|
||||
let channel;
|
||||
|
@ -34,7 +34,7 @@ class ChannelCommand extends Command {
|
|||
channel = this.message.channel;
|
||||
}
|
||||
|
||||
await db(this.ipc, "enableChannel", channel);
|
||||
await db.enableChannel(channel);
|
||||
return "I have been re-enabled in this channel.";
|
||||
}
|
||||
}
|
||||
|
|
36
commands/general/command.js
Normal file
36
commands/general/command.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const db = require("../../utils/database.js");
|
||||
const Command = require("../../classes/command.js");
|
||||
const collections = require("../../utils/collections.js");
|
||||
|
||||
class CommandCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
if (!this.message.member.permissions.has("administrator") && this.message.member.id !== process.env.OWNER) return "You need to be an administrator to enable/disable me!";
|
||||
if (this.args.length === 0) return "You need to provide what command to enable/disable!";
|
||||
if (this.args[0] !== "disable" && this.args[0] !== "enable") return "That's not a valid option!";
|
||||
|
||||
const guildDB = await db.getGuild(this.message.channel.guild.id);
|
||||
|
||||
if (this.args[0].toLowerCase() === "disable") {
|
||||
if (!collections.commands.has(this.args[1].toLowerCase()) && !collections.aliases.has(this.args[1].toLowerCase())) return "That isn't a command!";
|
||||
const command = collections.aliases.has(this.args[1].toLowerCase()) ? collections.aliases.get(this.args[1].toLowerCase()) : this.args[1].toLowerCase();
|
||||
if (guildDB.disabled_commands && guildDB.disabled_commands.includes(command)) return "That command is already disabled!";
|
||||
|
||||
await db.disableCommand(this.message.channel.guild.id, command);
|
||||
return `The command has been disabled. To re-enable it, just run \`${guildDB.prefix}command enable ${command}\`.`;
|
||||
} else if (this.args[0].toLowerCase() === "enable") {
|
||||
if (!collections.commands.has(this.args[1].toLowerCase()) && !collections.aliases.has(this.args[1].toLowerCase())) return "That isn't a command!";
|
||||
const command = collections.aliases.has(this.args[1].toLowerCase()) ? collections.aliases.get(this.args[1].toLowerCase()) : this.args[1].toLowerCase();
|
||||
if (guildDB.disabled_commands && !guildDB.disabled_commands.includes(command)) return "That command isn't disabled!";
|
||||
|
||||
await db.enableCommand(this.message.channel.guild.id, command);
|
||||
return `The command \`${command}\` has been re-enabled.`;
|
||||
}
|
||||
}
|
||||
|
||||
static description = "Enables/disables a command for a server";
|
||||
static aliases = ["cmd"];
|
||||
static arguments = ["[enable/disable]", "[command]"];
|
||||
}
|
||||
|
||||
module.exports = CommandCommand;
|
|
@ -6,7 +6,7 @@ class CountCommand extends Command {
|
|||
async run() {
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("addReactions")) return "I don't have the `Add Reactions` permission!";
|
||||
if (this.message.channel.guild && !this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
|
||||
const counts = await database(this.ipc, "getCounts");
|
||||
const counts = await database.getCounts();
|
||||
const countArray = [];
|
||||
for (const entry of Object.entries(counts)) {
|
||||
countArray.push(entry);
|
||||
|
|
|
@ -8,13 +8,13 @@ const Command = require("../../classes/command.js");
|
|||
|
||||
class HelpCommand extends Command {
|
||||
async run() {
|
||||
const { prefix } = this.message.channel.guild ? await database(this.ipc, "getGuild", this.message.channel.guild.id) : "N/A";
|
||||
const { prefix } = this.message.channel.guild ? await database.getGuild(this.message.channel.guild.id) : "N/A";
|
||||
const commands = collections.commands;
|
||||
const aliases = collections.aliases;
|
||||
if (this.args.length !== 0 && (commands.has(this.args[0].toLowerCase()) || aliases.has(this.args[0].toLowerCase()))) {
|
||||
const command = aliases.has(this.args[0].toLowerCase()) ? collections.aliases.get(this.args[0].toLowerCase()) : this.args[0].toLowerCase();
|
||||
const info = collections.info.get(command);
|
||||
const counts = await database(this.ipc, "getCounts");
|
||||
const counts = await database.getCounts();
|
||||
const embed = {
|
||||
"embed": {
|
||||
"author": {
|
||||
|
|
|
@ -4,10 +4,10 @@ const Command = require("../../classes/command.js");
|
|||
class PrefixCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
const guild = await database(this.ipc, "getGuild", this.message.channel.guild.id);
|
||||
const guild = await database.getGuild(this.message.channel.guild.id);
|
||||
if (this.args.length !== 0) {
|
||||
if (!this.message.member.permissions.has("administrator") && this.message.member.id !== process.env.OWNER) return "You need to be an administrator to change the bot prefix!";
|
||||
await database(this.ipc, "setPrefix", this.args[0], this.message.channel.guild);
|
||||
await database.setPrefix(this.args[0], this.message.channel.guild);
|
||||
return `The prefix has been changed to ${this.args[0]}.`;
|
||||
} else {
|
||||
return `The current prefix is \`${guild.prefix}\`.`;
|
||||
|
|
|
@ -7,12 +7,10 @@ class TagsCommand extends Command {
|
|||
// todo: find a way to split this into subcommands
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return "This command only works in servers!";
|
||||
const guild = await database(this.ipc, "getGuild", this.message.channel.guild.id);
|
||||
|
||||
if ((guild.tagsDisabled || guild.tags_disabled) && this.args[0].toLowerCase() !== ("enable" || "disable")) return;
|
||||
if (this.args.length === 0) return "You need to provide the name of the tag you want to view!";
|
||||
const tags = await database(this.ipc, "getTags", this.message.channel.guild.id);
|
||||
const blacklist = ["create", "add", "edit", "remove", "delete", "list", "random", "own", "owner", "enable", "disable"];
|
||||
const tags = await database.getTags(this.message.channel.guild.id);
|
||||
const blacklist = ["create", "add", "edit", "remove", "delete", "list", "random", "own", "owner"];
|
||||
switch (this.args[0].toLowerCase()) {
|
||||
case "create":
|
||||
case "add":
|
||||
|
@ -27,7 +25,7 @@ class TagsCommand extends Command {
|
|||
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to delete!";
|
||||
if (!tags[this.args[1].toLowerCase()]) return "This tag doesn't exist!";
|
||||
if (tags[this.args[1].toLowerCase()].author !== this.message.author.id && !this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return "You don't own this tag!";
|
||||
await database(this.ipc, "removeTag", this.args[1].toLowerCase(), this.message.channel.guild);
|
||||
await database.removeTag(this.args[1].toLowerCase(), this.message.channel.guild);
|
||||
return `The tag \`${this.args[1].toLowerCase()}\` has been deleted!`;
|
||||
case "edit":
|
||||
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to edit!";
|
||||
|
@ -72,11 +70,6 @@ class TagsCommand extends Command {
|
|||
return paginator(this.client, this.message, embeds);
|
||||
case "random":
|
||||
return tags[random(Object.keys(tags))].content;
|
||||
case "enable":
|
||||
case "disable":
|
||||
if (!this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return "You don't have permission to disable tags!";
|
||||
var toggleResult = await database(this.ipc, "toggleTags", this.message.channel.guild);
|
||||
return `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[this.args[0].toLowerCase()]) return "This tag doesn't exist!";
|
||||
return tags[this.args[0].toLowerCase()].content;
|
||||
|
@ -86,11 +79,11 @@ class TagsCommand extends Command {
|
|||
async setTag(content, name, message, edit = false) {
|
||||
if ((!content || content.length === 0) && message.attachments.length === 0) return "You need to provide the content of the tag!";
|
||||
if (message.attachments.length !== 0 && content) {
|
||||
await database(this.ipc, edit ? "editTag" : "setTag", name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }, message.channel.guild);
|
||||
await database[edit ? "editTag" : "setTag"](name, { content: `${content} ${message.attachments[0].url}`, author: message.author.id }, message.channel.guild);
|
||||
} else if (message.attachments.length !== 0) {
|
||||
await database(this.ipc, edit ? "editTag" : "setTag", name, { content: message.attachments[0].url, author: message.author.id }, message.channel.guild);
|
||||
await database[edit ? "editTag" : "setTag"](name, { content: message.attachments[0].url, author: message.author.id }, message.channel.guild);
|
||||
} else {
|
||||
await database(this.ipc, edit ? "editTag" : "setTag", name, { content: content, author: message.author.id }, message.channel.guild);
|
||||
await database[edit ? "editTag" : "setTag"](name, { content: content, author: message.author.id }, message.channel.guild);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -102,8 +95,7 @@ class TagsCommand extends Command {
|
|||
edit: "Edits a tag",
|
||||
list: "Lists all tags in the server",
|
||||
random: "Gets a random tag",
|
||||
owner: "Gets the owner of a tag",
|
||||
disable: "Disables/Enables the tag system"
|
||||
owner: "Gets the owner of a tag"
|
||||
};
|
||||
static aliases = ["t", "tag", "ta"];
|
||||
static arguments = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue