From: Elias Fleckenstein Date: Sat, 5 Mar 2022 20:33:19 +0000 (+0100) Subject: Implement operators X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5fa566734ecd144d3bdc203a7ff3b131aa7dfadf;p=furrybot-discord.git Implement operators --- diff --git a/basic.js b/basic.js index b5a9232..0ef4f46 100644 --- a/basic.js +++ b/basic.js @@ -2,7 +2,7 @@ module.exports = { help: { params: "[]", help: "Display help for a commands or show list of available commands", - func: (msg, [cmd]) => { + func: (msg, [cmd], {commands}) => { if (cmd) { let def = commands[cmd] diff --git a/common.js b/common.js index 3710018..4e950e6 100644 --- a/common.js +++ b/common.js @@ -60,7 +60,7 @@ module.exports.interactiveRoleplayCommand = (help, action) => new Object({ module.exports.storageLoad = name => { try { - return require(`storage/${name}.json`) + return require(`./storage/${name}.json`) } catch {} } @@ -82,20 +82,20 @@ module.exports.chooseWeighted = (arr, rng = Math) => { module.exports.listCommand = (title, list) => new Object({ help: "Show list of " + title, - func: msg => msg.reply(`List of ${title}: ${Object.keys(list).join(", ")}`) + func: (msg, _, fb) => msg.reply(`List of ${title}: ${Object.keys(fb[list]).map(entry => "<@!" + entry + ">").join(", ")}`) }) -module.exports.listChangeCommand = (action, list, listName, status) => new Object({ +module.exports.listChangeCommand = (action, list, status) => new Object({ operator: true, - func: (msg, [targetPing]) => { + func: (msg, [targetPing], fb) => { const target = getPing(msg, targetPing, true) if (target) { - if (list[target] == status) { + if (fb[list][target] == status) { msg.reply(`<@!${target}> ${status ? "already" : "not"} ${action}.`) } else { - list[target] = status - module.exports.storageSave(listName, list) + fb[list][target] = status + module.exports.storageSave(list, fb[list]) msg.reply(`Successfully ${action} <@!${target}>.`) } } diff --git a/http.js b/http.js index 40dd185..36f2555 100644 --- a/http.js +++ b/http.js @@ -13,7 +13,7 @@ module.exports = { verse: { func: msg => fetch("https://labs.bible.org/api/?type=json&passage=random") .then(res => res.json()) - .then(data => msg.reply(`${data[0].text} [${data[0].bookname} ${data[0].chapter}, ${data[0].verse}]`)) + .then(data => msg.reply(`${data[0].text}\n\t${data[0].bookname} ${data[0].chapter}, ${data[0].verse}`)) }, define: { func: (msg, term) => term.length > 0 ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + term.join(" ")) diff --git a/init.js b/init.js index a812502..9bbc315 100644 --- a/init.js +++ b/init.js @@ -24,23 +24,20 @@ client.on("messageCreate", msg => { if (def.operator && !fb.operators[msg.author.id]) msg.reply(`Sorry, you need to be an operator run this command: ${cmd}`) else - def.func(msg, args) + def.func(msg, args, fb) } else { msg.reply(`Invalid command: ${cmd}`) } } }) -//const modules = ["nsfw", "random", "operator"] -const modules = ["basic", "bullshit", "marriage", "http", "roleplay", "death", "economy", "waifu"] +//const modules = ["nsfw", "random"] +const modules = ["basic", "bullshit", "marriage", "http", "roleplay", "death", "economy", "waifu", "operator"] for (let f of modules) { let m = require(`./${f}.js`) if (m) for (let k in m) - if (k != "__init") - fb.commands[k] = m[k] - - m?.__init?.(fb) + fb.commands[k] = m[k] } diff --git a/operator.js b/operator.js index 1c01e28..fda9e05 100644 --- a/operator.js +++ b/operator.js @@ -1,9 +1,10 @@ -let operators, ignored +const common = require("./common.js") -furrybot.list_change_command("op", "operators", "an operator", true) -furrybot.list_change_command("deop", "operators", "an operator", nil) -furrybot.list_command("oplist", "operators", "operators") - -furrybot.list_change_command("ignore", "ignored", "ignored", true) -furrybot.list_change_command("unignore", "ignored", "ignored", nil) -furrybot.list_command("ignorelist", "ignored", "ignored players") +module.exports = { + op: common.listChangeCommand("oped", "operators", true), + deop: common.listChangeCommand("oped", "operators", false), + oplist: common.listCommand("operators", "operators"), + ignore: common.listChangeCommand("ignored", "ignored", true), + unignore: common.listChangeCommand("ignored", "ignored", false), + ignorelist: common.listCommand("ignored users", "ignored"), +}