]> git.lizzy.rs Git - furrybot-discord.git/commitdiff
Safe search
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 20:01:36 +0000 (21:01 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 5 Mar 2022 20:01:36 +0000 (21:01 +0100)
basic.js
common.js
http.js
init.js
operator.js [new file with mode: 0644]
operator.lua [deleted file]
package-lock.json

index 0ef4f4607d209c4ecd443ce36fdce8a0356241df..b5a9232d43f9f5a30cbbb01487eec9349326f59d 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], {commands}) => {
+               func: (msg, [cmd]) => {
                        if (cmd) {
                                let def = commands[cmd]
 
index a098c329037462bac933c837fd14944006649504..371001884afd07395ae8642000680e2a21300efe 100644 (file)
--- a/common.js
+++ b/common.js
@@ -1,67 +1,6 @@
 const fs = require("fs")
 const google_images = require("free-google-images")
 
-/*
-const furrybot.list_change_command(cmd, list_name, title, status)
-       furrybot.commands[cmd] = {
-               operator = true,
-               func = function(name, target)
-                       if target then
-                               if furrybot[list_name][target] == status then
-                                       furrybot.error_message(name, "Player " .. (status and "already" or "not") .. " " .. title .. ": ", target)
-                               else
-                                       furrybot[list_name][target] = status
-                                       storage:set_string(list_name, minetest.serialize(furrybot[list_name]))
-                                       furrybot.ping_message(name, "Successfully " .. cmd .. (cmd:sub(#cmd, #cmd) == "e" and "" or "e") .. "d " .. target, furrybot.colors.system)
-                               end
-                       else
-                               furrybot.error_message(name, "You need to specify a player")
-                       end
-               end,
-       }
-end
-
-function furrybot.list_command(cmd, list_name, title)
-       furrybot.commands[cmd] = {
-               func = function()
-                       local names = {}
-
-                       for name in pairs(furrybot[list_name]) do
-                               table.insert(names, name)
-                       end
-
-                       furrybot.send("List of " .. title .. ": " .. table.concat(names, ", "), furrybot.colors.system)
-               end,
-       }
-end
-
-function furrybot.choose(list, color)
-       return furrybot.colors.random .. list[math.random(#list)] .. color
-end
-
-function furrybot.random(min, max, color)
-       return furrybot.colors.random .. math.random(min, max) .. color
-end
-
-function furrybot.strrandom(str, seed, ...)
-       local v = 0
-       local pr = PseudoRandom(seed)
-       for i = 1, #str do
-               v = v + str:byte(i) * pr:next()
-       end
-       return PseudoRandom(v):next(...)
-end
-
-function furrybot.repeat_string(str, times)
-       local msg = ""
-       for i = 1, times do
-               msg = msg .. str
-       end
-       return msg
-end
-
-*/
-
 const getPing = module.exports.getPing = (msg, ping, allowSelf) => {
        if (ping && ping.startsWith("<@!") && ping.endsWith(">")) {
                const id = ping.slice("<@!".length, -">".length)
@@ -140,3 +79,25 @@ module.exports.chooseWeighted = (arr, rng = Math) => {
        const r = Math.floor(rng.random() * accum)
        return arr.find((_, k) => r < edges[k])[0]
 }
+
+module.exports.listCommand = (title, list) => new Object({
+       help: "Show list of " + title,
+       func: msg => msg.reply(`List of ${title}: ${Object.keys(list).join(", ")}`)
+})
+
+module.exports.listChangeCommand = (action, list, listName, status) => new Object({
+       operator: true,
+       func: (msg, [targetPing]) => {
+               const target = getPing(msg, targetPing, true)
+
+               if (target) {
+                       if (list[target] == status) {
+                               msg.reply(`<@!${target}> ${status ? "already" : "not"} ${action}.`)
+                       } else {
+                               list[target] = status
+                               module.exports.storageSave(listName, list)
+                               msg.reply(`Successfully ${action} <@!${target}>.`)
+                       }
+               }
+       }
+})
diff --git a/http.js b/http.js
index 3de39edcae66b4c9ea41d105c31602d50af798e6..40dd185aae1ced6f0899e28d276fd8e237ca5148 100644 (file)
--- a/http.js
+++ b/http.js
@@ -6,10 +6,9 @@ module.exports = {
        google: {
                params: "<keyword> [...]",
                help: "Google Image Search",
-               func: (msg, keywords) => {
-                       google_images.searchRandom(keywords.join(" "))
+               func: (msg, keywords) =>
+                       google_images.searchRandom(keywords.join(" "), true)
                                .then(result => msg.reply(result.image.url))
-               }
        },
        verse: {
                func: msg => fetch("https://labs.bible.org/api/?type=json&passage=random")
@@ -17,7 +16,7 @@ module.exports = {
                        .then(data => msg.reply(`${data[0].text} [${data[0].bookname} ${data[0].chapter}, ${data[0].verse}]`))
        },
        define: {
-               func: (msg, [word]) => word ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + word)
+               func: (msg, term) => term.length > 0 ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + term.join(" "))
                        .then(res => res.json())
                        .then(data => {
                                let def = data[0]
@@ -35,7 +34,7 @@ module.exports = {
                        : msg.reply("You need to specify a word")
        },
        urban: {
-               func: (msg, [word]) => word ? fetch("https://api.urbandictionary.com/v0/define?term=" + word)
+               func: (msg, term) => term.length > 0 ? fetch("https://api.urbandictionary.com/v0/define?term=" + term.join(" "))
                        .then(res => res.json())
                        .then(data => {
                                let def = common.choose(data.list)
diff --git a/init.js b/init.js
index 75b5d57cd488b1e5efbb8699c50641db9c165094..a8125024487f35169a33c35b31a4d66280df37ce 100644 (file)
--- a/init.js
+++ b/init.js
@@ -24,14 +24,14 @@ 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, fb)
+                               def.func(msg, args)
                } else {
                        msg.reply(`Invalid command: ${cmd}`)
                }
        }
 })
 
-//const modules = ["nsfw", "random", "http", "operator"]
+//const modules = ["nsfw", "random", "operator"]
 const modules = ["basic", "bullshit", "marriage", "http", "roleplay", "death", "economy", "waifu"]
 
 for (let f of modules) {
@@ -39,5 +39,8 @@ for (let f of modules) {
 
        if (m)
                for (let k in m)
-                       fb.commands[k] = m[k]
+                       if (k != "__init")
+                               fb.commands[k] = m[k]
+
+       m?.__init?.(fb)
 }
diff --git a/operator.js b/operator.js
new file mode 100644 (file)
index 0000000..1c01e28
--- /dev/null
@@ -0,0 +1,9 @@
+let operators, ignored
+
+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")
diff --git a/operator.lua b/operator.lua
deleted file mode 100644 (file)
index 4503374..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-local http, env, storage
-local C = minetest.get_color_escape_sequence
-
-furrybot.commands.reload = {
-       operator = true,
-       func = function()
-               furrybot.reload()
-       end,
-}
-
-furrybot.commands.disconnect = {
-       operator = true,
-       func = function()
-               minetest.disconnect()
-       end,
-}
-
-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")
-
-return function(_http, _env, _storage)
-       http, env, storage = _http, _env, _storage
-end
index dd2f9b8da98d875e8d2edc7e8014fd3a7226ce42..a38aca2cb34ebf902f5c17965e3354f16eabec0c 100644 (file)
       }
     },
     "node_modules/free-google-images": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/free-google-images/-/free-google-images-1.1.1.tgz",
-      "integrity": "sha512-tvMekRNXz8HZbOYO5YbmuVPWOTl2g7/njk24qziEZbXiH+Biy+WYpb+oEJLb7O+owkYPcIMSdL5i8i2Z0spshg==",
+      "version": "1.2.0",
+      "resolved": "https://registry.npmjs.org/free-google-images/-/free-google-images-1.2.0.tgz",
+      "integrity": "sha512-hncHlKgWOgmGNjwSA0QEU25bThPAjfn+7XCBju7vf+PawCGn4k76+FRJ/HBrvPyrys3B06G3+Apli6v/4Cg0kQ==",
       "dependencies": {
         "cheerio": "^1.0.0-rc.10",
         "jsonic": "^1.0.1",
       }
     },
     "free-google-images": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/free-google-images/-/free-google-images-1.1.1.tgz",
-      "integrity": "sha512-tvMekRNXz8HZbOYO5YbmuVPWOTl2g7/njk24qziEZbXiH+Biy+WYpb+oEJLb7O+owkYPcIMSdL5i8i2Z0spshg==",
+      "version": "1.2.0",
+      "resolved": "https://registry.npmjs.org/free-google-images/-/free-google-images-1.2.0.tgz",
+      "integrity": "sha512-hncHlKgWOgmGNjwSA0QEU25bThPAjfn+7XCBju7vf+PawCGn4k76+FRJ/HBrvPyrys3B06G3+Apli6v/4Cg0kQ==",
       "requires": {
         "cheerio": "^1.0.0-rc.10",
         "jsonic": "^1.0.1",