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.
This commit is contained in:
parent
75e5069dd1
commit
86e94ec3d0
@ -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!");
|
||||
}));
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user