From 002092bcfd4ea095470798bd04d556fdf1842194 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Sat, 7 May 2022 16:48:48 -0600 Subject: [PATCH] bot: add settings command --- src/modules/bot.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/modules/bot.js b/src/modules/bot.js index 45c94f0..50e8edb 100644 --- a/src/modules/bot.js +++ b/src/modules/bot.js @@ -8,6 +8,8 @@ const {resolve} = require("path"); const {hastebin} = require("../lib/utils.js"); +const guildSettings = require("../lib/guildSettings.js"); + function spawn(args) { const shell = process.env.SHELL || (process.platform == "win32" ? "powershell" : "bash"); @@ -155,3 +157,61 @@ exec.callback = async function (msg, line) { }); }; hf.registerCommand(exec); + +const settings = new Command("settings"); +settings.category = CATEGORY; +settings.helpText = "Manage guild specific bot settings"; +settings.callback = async function (msg, line, cmd, key, value) { + if (!msg.guildID) "This command only works in guilds."; + + switch (cmd) { + case "get": + case "set": + return "TODO"; + case "flags": { + const flags = await guildSettings.getFlags(msg.guildID); + + return `\`\`\`\n${Object.keys(flags) + .map((key) => `${key} = ${flags[key]}`) + .join("\n")}\n\`\`\``; + } + case "enable": { + if ( + !msg.channel.permissionsOf(msg.author.id).has("manageGuild") && + !hf.config.elevated.includes(msg.author.id) + ) + return "You do not have `Manage Server` permissions"; + + if (!guildSettings.flags[key]) return "Unknown key."; + + const enabled = guildSettings.hasFlag(msg.guildID, key); + if (enabled) return "Already enabled."; + + await guildSettings.enableFlag(msg.guildID, key); + return {reaction: "\uD83D\uDC4C"}; + } + case "disable": { + if ( + !msg.channel.permissionsOf(msg.author.id).has("manageGuild") && + !hf.config.elevated.includes(msg.author.id) + ) + return "You do not have `Manage Server` permissions"; + + if (!guildSettings.flags[key]) return "Unknown key."; + + const enabled = guildSettings.hasFlag(msg.guildID, key); + if (!enabled) return "Already disabled."; + + await guildSettings.disableFlag(msg.guildID, key); + return {reaction: "\uD83D\uDC4C"}; + } + default: + return `__**Settings Subcommands**__ +\u2022 \`get \` - List all current values or a specific value +\u2022 \`set [key] [value]\` - Set a value +\u2022 \`flags\` - List flags +\u2022 \`enable [key]\` - Enable a flag +\u2022 \`disable [key]\` - Disable a flag`; + } +}; +hf.registerCommand(settings);