]> git.lizzy.rs Git - furrybot-discord.git/commitdiff
Implement operators
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 20:33:19 +0000 (21:33 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 20:33:19 +0000 (21:33 +0100)
basic.js
common.js
http.js
init.js
operator.js

index b5a9232d43f9f5a30cbbb01487eec9349326f59d..0ef4f4607d209c4ecd443ce36fdce8a0356241df 100644 (file)
--- a/basic.js
+++ b/basic.js
@@ -2,7 +2,7 @@ module.exports = {
        help: {
                params: "[<command>]",
                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]
 
index 371001884afd07395ae8642000680e2a21300efe..4e950e67e06c514032742c3261d9a94bda105689 100644 (file)
--- 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 40dd185aae1ced6f0899e28d276fd8e237ca5148..36f2555bf59134ec13817f426fcf2fe7355a8eb6 100644 (file)
--- 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 a8125024487f35169a33c35b31a4d66280df37ce..9bbc3156836d660b15d23f70fc601befb43abc31 100644 (file)
--- 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]
 }
index 1c01e28569aec9fea2b87464ce6535ee9873251d..fda9e0580bd8c56b55ad5abb009f9c0e8cdc1c12 100644 (file)
@@ -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"),
+}