From 86e94ec3d04631bab6bd9d458e4ce819ea083a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Mon, 22 Aug 2016 21:59:20 +0200 Subject: [PATCH] Added ability to send random meme WARNING: HACK I have to break down the meme function a bit better. Next thing up is a refactor of that thing. --- dodsorfas/Skypebot/app.js | 2 ++ dodsorfas/Skypebot/commands.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dodsorfas/Skypebot/app.js b/dodsorfas/Skypebot/app.js index 80dce84..2d6c45b 100644 --- a/dodsorfas/Skypebot/app.js +++ b/dodsorfas/Skypebot/app.js @@ -37,6 +37,8 @@ bot.dialog('/', new builder.IntentDialog() .matches(helper.regex("help"), function(s) {cmd.help(s)}) .matches(helper.regex("meme \\w+"), function(s) {cmd.meme(s)}) .matches(helper.regex("memes"), function(s) {cmd.memes(s)}) + .matches(helper.regex("debug"), function(s) {cmd.debug(s)}) .onDefault(function(session) { + console2.log(session); session.send("I didn't understand. Say 'help' to get a list of commands!"); })); diff --git a/dodsorfas/Skypebot/commands.js b/dodsorfas/Skypebot/commands.js index 870c175..ca27975 100644 --- a/dodsorfas/Skypebot/commands.js +++ b/dodsorfas/Skypebot/commands.js @@ -55,10 +55,16 @@ exports.help = function(session) { // This application runs in a docker container, the memes folder on my web server is mounted inside this path as well. // Bad solution, but it'll work. -- Note to future self, maybe put a real webserver to serve the image files instead... exports.meme = function(session) { + var file; var memewhitelist = fs.readdirSync("/usr/src/app/memes/"); - var file = session.message.text.replace(helper.regex("meme "), ""); + if (session.message.text.match(helper.regex("meme random")) != null) { + var image = Math.floor(Math.random() * 9999999) % memewhitelist.length; + file=(memewhitelist[image]); + } + else { + file = session.message.text.replace(helper.regex("meme "), ""); + } console.log(file); - if (!memewhitelist.includes(file)) { session.send("That meme isnt added to my folder :( Contact dan to add it :D"); }