From 1d469480c012886016384f0793326bdf49aa62b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Sun, 21 Aug 2016 13:53:33 +0200 Subject: [PATCH] Made it a lot easier to update and add more commands --- dodsorfas/Skypebot/app.js | 31 +++++++++++----------- dodsorfas/Skypebot/commands.js | 48 ++++++++++++++++++++++++++++++++++ dodsorfas/Skypebot/helper.js | 9 +++++++ 3 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 dodsorfas/Skypebot/commands.js create mode 100644 dodsorfas/Skypebot/helper.js diff --git a/dodsorfas/Skypebot/app.js b/dodsorfas/Skypebot/app.js index 9eaac07..8dcfd27 100644 --- a/dodsorfas/Skypebot/app.js +++ b/dodsorfas/Skypebot/app.js @@ -1,10 +1,20 @@ +var fs = require('fs'); var restify = require('restify'); var builder = require('botbuilder'); +var cmd = require('./commands.js'); +var helper = require('./helper.js'); + // Bot setup // restify setup -var server = restify.createServer(); +var https_options = { + key: fs.readFileSync('/etc/ssl/privkey.pem'), + certificate: fs.readFileSync('/etc/ssl/fullchain.pem'), + ca: fs.readFileSync('/etc/ssl/chain.pem') +}; + +var server = restify.createServer(https_options); server.listen(process.env.port || process.env.PORT || 3978, function() { console.log('%s listening to %s', server.name, server.url); }); @@ -18,22 +28,13 @@ var bot = new builder.UniversalBot(connector); server.post('/api/messages', connector.listen()); // Bot Dialogs -var texts = {}; -texts.help = "Hey there! My available commands are:\n\n\ -about - Gives you information about the bot\n\n\ -ping - pong!\n\n\ -"; bot.dialog('/', new builder.IntentDialog() - .matches(/^ping/i, function(session) { - session.send("pong"); - }) - .matches(/^about/i, function(session) { - session.send("I am a general purpose bot created by Daniel, "); - }) - .matches(/^help/i, function(session) { - session.send(texts.help); - }) + .matches(helper.regex("ping"), function(s) {cmd.ping(s)}) + .matches(helper.regex("stuff"), function(s) {cmd.stuff(s)}) + .matches(helper.regex("games"), function(s) {cmd.games(s)}) + .matches(helper.regex("about"), function(s) {cmd.about(s)}) + .matches(helper.regex("help"), function(s) {cmd.help(s)}) .onDefault(function(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 new file mode 100644 index 0000000..f58c22c --- /dev/null +++ b/dodsorfas/Skypebot/commands.js @@ -0,0 +1,48 @@ +var helper = require('./helper.js'); + +exports.ping = function(session) { + session.send("pong"); +}; + + +var text = {}; +text.stuff = [ + "Plug.dj: https://plug.dj/don-t-starve-1" +]; + +exports.stuff = function(session) { + helper.send(session, text.stuff); +}; + + +text.games = [ + "Minecraft Survival Server: dandellion.xyz", + "Minecraft World map (Updates every 24h): https://dandellion.xyz/minecraft/map" +] + +exports.games = function(session) { + helper.send(session, text.games); +}; + + +text.about = [ + "I am a general purpose bot created by Daniel, written with nodejs and the skype bot framework.", + "You can find my sourcecode at https://github.com/dali99/Misc-small-projects/tree/master/dodsorfas/Skypebot" +]; + +exports.about = function(session) { + helper.send(session, text.about); +}; + + +text.help = [ + "Hey there! My available commands are:", + "about - Gives you information about the bot", + "ping - pong!", + "stuff - Information about different services we use", + "games - IPs and other related information about game servers we use" +]; + +exports.help = function(session) { + helper.send(session, text.help); +}; \ No newline at end of file diff --git a/dodsorfas/Skypebot/helper.js b/dodsorfas/Skypebot/helper.js new file mode 100644 index 0000000..8490ff5 --- /dev/null +++ b/dodsorfas/Skypebot/helper.js @@ -0,0 +1,9 @@ +exports.send = function(session, texta) { + texta.forEach(function(text) { + session.send(text); + }) +} + +exports.regex = function(command) { + return RegExp ("^(Dodsorbot<\\/at>\\s)?(" + command + ")", "i"); +} \ No newline at end of file