aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic.js2
-rw-r--r--common.js83
-rw-r--r--http.js9
-rw-r--r--init.js9
-rw-r--r--operator.js (renamed from operator.lua)21
-rw-r--r--package-lock.json12
6 files changed, 40 insertions, 96 deletions
diff --git a/basic.js b/basic.js
index 0ef4f46..b5a9232 100644
--- 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]
diff --git a/common.js b/common.js
index a098c32..3710018 100644
--- 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 3de39ed..40dd185 100644
--- 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 75b5d57..a812502 100644
--- 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.lua b/operator.js
index 4503374..1c01e28 100644
--- a/operator.lua
+++ b/operator.js
@@ -1,19 +1,4 @@
-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,
-}
+let operators, ignored
furrybot.list_change_command("op", "operators", "an operator", true)
furrybot.list_change_command("deop", "operators", "an operator", nil)
@@ -22,7 +7,3 @@ 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
diff --git a/package-lock.json b/package-lock.json
index dd2f9b8..a38aca2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -313,9 +313,9 @@
}
},
"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",
@@ -707,9 +707,9 @@
}
},
"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",