Made it a lot easier to update and add more commands
This commit is contained in:
		
							parent
							
								
									248ee63072
								
							
						
					
					
						commit
						1d469480c0
					
				| @ -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!"); | ||||
|     })); | ||||
|  | ||||
							
								
								
									
										48
									
								
								dodsorfas/Skypebot/commands.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								dodsorfas/Skypebot/commands.js
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||
| }; | ||||
							
								
								
									
										9
									
								
								dodsorfas/Skypebot/helper.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								dodsorfas/Skypebot/helper.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| exports.send = function(session, texta) { | ||||
| 	texta.forEach(function(text) { | ||||
| 		session.send(text); | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| exports.regex = function(command) { | ||||
| 	return RegExp ("^(<at id=\"\\S+\">Dodsorbot<\\/at>\\s)?(" + command + ")", "i"); | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user