]> git.lizzy.rs Git - furrybot-discord.git/blobdiff - common.js
Add bad apple
[furrybot-discord.git] / common.js
index 371001884afd07395ae8642000680e2a21300efe..5bb4cff5badbfe47f3bb2a39ad2c7278c0d722de 100644 (file)
--- a/common.js
+++ b/common.js
@@ -2,14 +2,14 @@ const fs = require("fs")
 const google_images = require("free-google-images")
 
 const getPing = module.exports.getPing = (msg, ping, allowSelf) => {
-       if (ping && ping.startsWith("<@!") && ping.endsWith(">")) {
-               const id = ping.slice("<@!".length, -">".length)
+       if (ping && ping.startsWith("<\\@!") && ping.endsWith(">")) {
+               const id = ping.slice("<\\@!".length, -">".length)
 
                if (!allowSelf && id == msg.author.id) {
                        msg.reply("Please mention a user other than yourself")
                        return
                }
-               
+
                if (msg.guild.members.cache.get(id))
                        return id
        }
@@ -19,24 +19,27 @@ const getPing = module.exports.getPing = (msg, ping, allowSelf) => {
 
 module.exports.uppercase = str => str.slice(0, 1).toUpperCase() + str.slice(1)
 
-module.exports.requestCommand = (help, onRequest, onAccept) => new Object({
+module.exports.requestCommand = (help, info, onRequest, onAccept) => new Object({
        params: "<player>",
-       help: "Request to " + help + " another user",
+       help: "Request to " + help,
        func: (msg, [targetPing], {requests}) => {
                const target = getPing(msg, targetPing, false)
 
                if (target) {
                        const err = onRequest(msg, target)
 
-                       if (err)
+                       if (err) {
                                msg.reply(err)
-                       else
+                       } else {
+                               msg.channel.send(`<@!${target}>: <@!${msg.author.id}> ${info}. Type !accept to accept or !deny to deny.`)
+
                                requests[target] = {
                                        origin: msg.author.id,
                                        func: onAccept,
                                }
+                       }
                }
-                       
+
        }
 })
 
@@ -60,7 +63,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 +85,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}>.`)
                        }
                }