Esempio n. 1
0
define.init = function (client) {
    var pluginCfg   = client.config.plugins.define;    
    define.waClient = wa.createClient(pluginCfg.appID);
    
    client.ame.on('actionableMessageAddressingBot', function (info) {
        var cmd   = info.words[1];
        var query = info.words.slice(2).join(' ');

        if (cmd === 'define' && query && query.length > 0) {
            define.getDefinition(query, function (err, result) {
                if (!err && result && result.length > 0) {
                    var msg = define.processWaResult(result);
                    
                    if (msg) {
                        client.say(info.channel, msg);
                    }
                    
                } else {
                    client.say(info.channel, 'No results');
                    console.log('define error:', err);
                }
            });
        }
    });
};
exports.create = function(name, chatBot, options) {
	var trigger = new WolframAlphaTrigger(type, name, chatBot, options);

	trigger.client = trigger.options.client || wolfram.createClient(trigger.options.appId);

	return trigger;
};
Esempio n. 3
0
    function Plugin(bot, config) {
        this.name = 'wolframalpha';
        this.title = 'Wolframalpha';
        this.description = "Wolframalpha plugin for Modubot";
        this.version = '0.1';
        this.author = 'Kamal Nasser';

        this.bot = bot;
        this.database = bot.database;
        this.client = bot.client;
        this.config = config;
        this.commands = {
            'wolframalpha': 'onCommandWolframalpha',
            'wa': 'onCommandWolframalpha'
        };

        this.wolfram = wolfram.createClient(config.applicationId);
    }
Esempio n. 4
0
module.exports.init = function(stringword, callback){

	var engine = wa.createClient('YQ552E-RLQRKXP5LU');

	var defer = q.defer();

	engine.query(stringword, function(err, response){
		if (err) {
			defer.reject({message: 'failed'});
		}
		else{
			
			if(response.length < 1){
				//fetchfromgoogle(stringword)
			}
			else{
				console.log(response[1].subpods[0].value)
				defer.resolve(response[1].subpods[0].value.replace(/wolfram\|alpha/ig, "Pearson one air").replace(/stephen.*/ig, "Team Ninjas").replace(/^\d\s[years].*/ig, "Just a day old baby") || "Im not ready to answer this question.");
			}	
		}
	});

	callback(defer.promise);
};
Esempio n. 5
0
var login = require("facebook-chat-api");
var fs = require("fs");
var secret = JSON.parse(fs.readFileSync(__dirname + "/secret.json"));
var wolfram = require("wolfram");
var wolframClient = wolfram.createClient(secret.wolfKey);
var firebase = require("firebase");


var userDB = {};
var sendDB = [];
var lastLine = null
var lastSubject;
var keyArray;
var printed = false;


firebase.initializeApp({
  databaseURL: "https://project-6564761374345501298.firebaseio.com",
  serviceAccount: "serviceAccountCredentials.json"
});


//recieving stuff from firebase
var commentsRef = firebase.database().ref('subjects');
commentsRef.on('value', function(snapshot){
       keyArray = Object.keys(snapshot.val());
       keyArray.forEach(function (usertext){
            var subjectRef = firebase.database().ref('subjects/'+usertext);
            subjectRef.on('value', function(user){
                var nameArray = Object.keys(user.val());
                printed = false;
Esempio n. 6
0
var login = require("facebook-chat-api");
var wolfram = require('wolfram');
var pt = require("periodic-table");
var fs = require("fs");
var secretData = JSON.parse(fs.readFileSync(__dirname+"/secretData.json"));
console.log(secretData);
var wolframClient = wolfram.createClient(secretData.WOLFRAM_API_KEY);

var elementData = pt.all();

login({email: secretData.FACEBOOK_EMAIL, password: secretData.FACEBOOK_PASSWORD}, function callback (err, api) {
    if(err) return console.error(err); 
 
    api.listen(function callback(err, message) {
    	// help message
    	if(message.body.trim() == "help"){
    		api.sendMessage("Available commands:\n\t<element symbol> - finds the element with that symbol and returns relevant information"
    			+"\n\tmm <compound> - returns the molar mass of a compound. Requires proper capitalization."
    			+"\n\tbalance <equation> - returns a balanced form of a chemical equation. Requires proper capitalization."
    			+"\n\thelp - displays this message.", message.threadID);
    		return;
    	}

    	// balance chemical equations
    	if(message.body.startsWith("balance")){
    		api.sendMessage("Attempting to "+message.body+"...", message.threadID);
			wolframClient.query(message.body, function(err, result) {
				if(err) throw err;
				try{
					api.sendMessage(result[1].subpods[0].value, message.threadID);
				}catch(e){