cardboardbox/commands/System/conf.js

74 lines
2.5 KiB
JavaScript
Raw Normal View History

const { inspect } = require("util");
2019-12-24 01:59:14 +00:00
exports.run = async (client, message, [action, key, ...value], level) => {
const defaults = client.settings.get("default");
if (action === "add") {
2019-12-24 01:59:14 +00:00
if (!key) return message.reply("please specify a key to add.");
if (defaults[key]) return message.reply("this key already exists in the default settings!");
if (value.length < 1) return message.reply("please specify a value.");
defaults[key] = value.join(" ");
client.settings.set("default", defaults);
2019-12-24 01:59:14 +00:00
message.reply(`${key} successfully added with the value of ${value.join(" ")}.`);
} else
if (action === "edit") {
2019-12-24 01:59:14 +00:00
if (!key) return message.reply("please specify a key to edit.");
if (!defaults[key]) return message.reply("this key does not exist in the settings!");
if (value.length < 1) return message.reply("please specify a new value!");
defaults[key] = value.join(" ");
client.settings.set("default", defaults);
2019-12-24 01:59:14 +00:00
message.reply(`${key} successfully edited to ${value.join(" ")}.`);
} else
if (action === "del") {
2019-12-24 01:59:14 +00:00
if (!key) return message.reply("please specify a key to delete.");
if (!defaults[key]) return message.reply("this key does not exist in the settings!");
const response = await client.awaitReply(message, `Are you sure you want to permanently delete ${key} from all guilds? This **CANNOT** be undone.`);
if (["y", "yes"].includes(response)) {
delete defaults[key];
client.settings.set("default", defaults);
for (const [guildid, conf] of client.settings.filter((setting, id) => setting[key] && id !== "default")) {
delete conf[key];
client.settings.set(guildid, conf);
}
message.reply(`${key} was successfully deleted.`);
} else
if (["n","no","cancel"].includes(response)) {
2019-12-24 01:59:14 +00:00
message.reply("action cancelled.");
}
} else
if (action === "get") {
2019-12-24 01:59:14 +00:00
if (!key) return message.reply("please specify a key to view.");
if (!defaults[key]) return message.reply("this key does not exist in the settings!");
message.reply(`the value of ${key} is currently ${defaults[key]}.`);
} else {
await message.channel.send(`***__Bot Default Settings__***\n\`\`\`json\n${inspect(defaults)}\n\`\`\``);
}
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: ["defaults"],
permLevel: "Bot Admin"
};
exports.help = {
name: "conf",
category: "System",
description: "Modify the default configuration for all guilds.",
usage: "conf <view/get/edit> <key> <value>"
};