Exemple #1
0
  socket.on('chat message', function(incomingMsg){
  	console.log("Server got a message! ", incomingMsg);
  	if (incomingMsg.indexOf("INIT") != -1) {
  		if (incomingMsg.indexOf("Quotebot") != -1){
  			console.log("QUOTEBOT REQUESTED");
  			var quotebot = require('child_process').spawn(__dirname + '/node_modules/bot/bin/bot', {stdio: ['pipe', 'pipe', 'pipe']});
			quotebot.stdin.setEncoding = 'utf-8'; 
			quotebot.stdout.setEncoding = 'utf-8';
			socket.on('chat message', function(myMsg){
  			quotebot.stdin.write(myMsg + '\n');
    		console.log("I sent the bot a message: ", myMsg);
    		//io.emit('chat message', myMsg);
		});
  
  		quotebot.stdout.on('data', function(botMsg){
    	botMsg = botMsg.toString();
    	if (botMsg.indexOf('[36') != -1 ) {
    		console.log("{36 found!");
    		var ending = botMsg.lastIndexOf('[35');
    		console.log("Ending: ", ending)
        if (ending != -1) {
          botMsg = botMsg.substring(0, ending);
        }
    		botMsg = botMsg.substring(15);
    		console.log("the bot said: ", botMsg);
    		io.emit('quotebot message', botMsg);
    		}
 		});
  		} else if (incomingMsg.indexOf("Alice") != -1){
  			console.log("ALICE REQUESTED!");
  			var alicebot = new RiveScript();
  			alicebot.loadDirectory("./robot_data/alice_rivescript", loading_done, loading_error);
  			function loading_error(err){
  				console.log("ERROR JACK: ", err);
  			} 
  			function loading_done(){
          console.log("Alice loading done!")
  				alicebot.sortReplies();
  				socket.on('chat message', function(myMsg){
  					io.emit('alice message', alicebot.reply('User', myMsg) )
  				});
  			}

  		}
  	}
  	if (incomingMsg === 'marco') {
  		io.emit('bot message', 'polo');
  	}
  });
import co from 'co'
import RiveScript from 'rivescript'
import _ from 'lodash'
import natural from 'natural'
import moment from 'moment'
import Article from '../models/Article'
import Media from '../models/Media'
import User from '../models/User'
import queueOutgoingMessage from './outgoingMessageQueue'

const CONTEXT_FLAGS = ['quickReplies', 'sendArticles', 'sendAgain', 'rawMessage']
const BOT_WPM = 300

let bot = new RiveScript()
bot.loadDirectory('brain', () => {
  bot.sortReplies()
})

bot.setSubroutine('quickReply', (rs, [text]) => {
  let currentUser = rs.currentUser()
  let vars = rs.getUservars(currentUser)
  let quickReplies = vars.quickReplies || []
  quickReplies.push(text)
  rs.setUservars(currentUser, {quickReplies: quickReplies})
  return ''
})

bot.setSubroutine('sendArticles', (rs) => {
  let currentUser = rs.currentUser()
  rs.setUservars(currentUser, {sendArticles: true})
  return ''
Exemple #3
0
var express = require('express');
var bodyParser = require('body-parser');
var router = require('./routes/basic');
var rive = require('rivescript');

var bot = new rive();

bot.loadDirectory("./brain", l_done, l_err);

function l_done(l_c){
	console.log("Load # "+l_c+" completed!");

	bot.sortReplies();

	var app = express();

	app.use(bodyParser.json());


	app.post("/", getRep);

	app.set('port', process.env.PORT || 8000);

	var server = app.listen(app.get('port'), function(){
	console.log('Express Server Listening on Port ' +server.address().port);

});
}

function l_err(l_c , err)
{
Exemple #4
0
var express = require('express'),
    path = require('path'),
    fs = require('fs'),
    bodyParser = require('body-parser'),
    rsServices = require('./services'),
    RiveScript = require('rivescript');

var bot = new RiveScript();
rsServices(bot);
bot.loadDirectory("brain", success_handler, error_handler);

function success_handler(loadcount) {
  console.log("Load #" + loadcount + " completed!");

  bot.sortReplies();

	// Set up the Express app.
	var app = express();

	// Parse application/json inputs.
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
	app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(express.static(path.join(__dirname, 'public')));
	app.set("json spaces", 4);

	// Set up routes.
	app.post("/reply", getReply);
	app.get("/", function(req, res) {
    return res.render('index', {