bot: add settings command
This commit is contained in:
parent
129d428a2c
commit
002092bcfd
1 changed files with 60 additions and 0 deletions
|
@ -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 <key>\` - 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);
|
||||
|
|
Loading…
Reference in a new issue