mirror of
https://github.com/Brandon-Rozek/Rozbot.git
synced 2024-11-07 20:30:34 -05:00
Made natural language functional again with a bit of a mess\n I forcibly added username and privateMessage variable to metadata\n I should look into having an interface for that instead in the User.js file\nShould work towards cleaning up the code soon
This commit is contained in:
parent
aebd5a9bb9
commit
0795d27b67
5 changed files with 44 additions and 63 deletions
16
Rozbot.js
16
Rozbot.js
|
@ -35,7 +35,9 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Gives Rozbot's response
|
//Gives Rozbot's response
|
||||||
this.respond = function(message, user) {
|
this.respond = function(message, user, extra) {
|
||||||
|
extra = extra || {};
|
||||||
|
extra.privateMessage = extra.privateMessage || false;
|
||||||
//Store whether or not an app wants to listen to the next message
|
//Store whether or not an app wants to listen to the next message
|
||||||
var inAppScope = user.inAppScope
|
var inAppScope = user.inAppScope
|
||||||
//Used to allow apps to get the next message
|
//Used to allow apps to get the next message
|
||||||
|
@ -44,11 +46,19 @@ module.exports = function() {
|
||||||
var args = [message, user.send];
|
var args = [message, user.send];
|
||||||
//Find the right command to run
|
//Find the right command to run
|
||||||
var command = this.commandList.find(function(cmd) {
|
var command = this.commandList.find(function(cmd) {
|
||||||
return cmd.condition(message) === true;
|
var userData = user.getData(cmd.name);
|
||||||
|
//Attach whether or not this is a private message
|
||||||
|
userData.privateMessage = extra.privateMessage;
|
||||||
|
return cmd.condition(message, userData ) === true;
|
||||||
});
|
});
|
||||||
//Run the command using user's contextual data (app by app basis)
|
//Run the command using user's contextual data (app by app basis)
|
||||||
if (command !== undefined) {
|
if (command !== undefined) {
|
||||||
command.respond.apply(command, args.concat(user.getData(command.name)));
|
var userData = user.getData(command.name);
|
||||||
|
//Attach whether or not this is a private message
|
||||||
|
userData.privateMessage = extra.privateMessage;
|
||||||
|
//Attach the username
|
||||||
|
userData.username = user.username;
|
||||||
|
command.respond.apply(command, args.concat(userData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
example.js
14
example.js
|
@ -15,22 +15,16 @@ rozbot.extend(require('./lib/commands/grabUpdates.js'));
|
||||||
rozbot.extend(require('./lib/commands/grabTweets.js'));
|
rozbot.extend(require('./lib/commands/grabTweets.js'));
|
||||||
rozbot.extend(require('./lib/commands/displayTweet.js'));
|
rozbot.extend(require('./lib/commands/displayTweet.js'));
|
||||||
rozbot.extend(require('./lib/commands/Hangman.js'));
|
rozbot.extend(require('./lib/commands/Hangman.js'));
|
||||||
|
rozbot.extend(require('./lib/commands/RockPaperScissors.js'));
|
||||||
rozbot.extend(require('./lib/commands/grabPictures.js'));
|
rozbot.extend(require('./lib/commands/grabPictures.js'));
|
||||||
rozbot.extend(require('./lib/commands/grabWikipedia.js'));
|
rozbot.extend(require('./lib/commands/grabWikipedia.js'));
|
||||||
rozbot.extend(require('./lib/commands/grabDefinition.js'));
|
rozbot.extend(require('./lib/commands/grabDefinition.js'));
|
||||||
rozbot.extend(require('./lib/commands/calculate.js'));
|
rozbot.extend(require('./lib/commands/calculate.js'));
|
||||||
rozbot.extend(require('./lib/commands/timer.js'));
|
rozbot.extend(require('./lib/commands/timer.js'));
|
||||||
rozbot.extend(require('./lib/commands/search.js'));
|
rozbot.extend(require('./lib/commands/search.js'));
|
||||||
//rozbot.extend(require('./lib/commands/naturalSpeech.js'));
|
rozbot.extend(require('./lib/commands/naturalSpeech.js'));
|
||||||
rozbot.extend(require('./lib/commands/queryDuckDuckGo.js'));
|
rozbot.extend(require('./lib/commands/queryDuckDuckGo.js'));
|
||||||
|
|
||||||
//rozbot.respond(process.argv[2], rozbot.getUser("Command Line") || rozbot.addUser("Command Line"));
|
rozbot.respond(process.argv[2], rozbot.getUser("Command Line") || rozbot.addUser("Command Line", function(msg) {
|
||||||
rozbot.respond("Let's play hangman!", rozbot.getUser("Command Line") || rozbot.addUser("Command Line", function(msg) {
|
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
}));
|
}), {privateMessage: true});
|
||||||
var letters = ["a", "e", "i", "o", "u", "b"]
|
|
||||||
rozbot.respond(letters[0], rozbot.getUser("Command Line"));
|
|
||||||
rozbot.respond(letters[1], rozbot.getUser("Command Line"));
|
|
||||||
rozbot.respond(letters[2], rozbot.getUser("Command Line"));
|
|
||||||
rozbot.respond(letters[3], rozbot.getUser("Command Line"));
|
|
||||||
rozbot.respond(letters[4], rozbot.getUser("Command Line"));
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ var cheeriop = require('../promise/cheerio.js');
|
||||||
var promise = require('promise-polyfill');
|
var promise = require('promise-polyfill');
|
||||||
var grabTokens = require('../helpers/grabTokens.js');
|
var grabTokens = require('../helpers/grabTokens.js');
|
||||||
|
|
||||||
var condition = function(text) {
|
var condition = function(text, userData) {
|
||||||
var tokens = grabTokens(text);
|
var tokens = grabTokens(text);
|
||||||
return tokens.contain('play') && tokens.contain('hangman');
|
return tokens.contain('play') && tokens.contain('hangman') && (tokens.contain("rozbot") || userData.privateMessage);
|
||||||
}
|
}
|
||||||
module.exports = new Command("Hangman", condition, function(text, send, userData) {
|
module.exports = new Command("Hangman", condition, function(text, send, userData) {
|
||||||
var GUESSES_ALLOWED = 7;
|
var GUESSES_ALLOWED = 7;
|
||||||
|
|
|
@ -2,9 +2,9 @@ var Command = require('./Command.js');
|
||||||
var grabTokens = require('../helpers/grabTokens.js');
|
var grabTokens = require('../helpers/grabTokens.js');
|
||||||
var promise = require('promise-polyfill');
|
var promise = require('promise-polyfill');
|
||||||
|
|
||||||
var condition = function(text) {
|
var condition = function(text, userData) {
|
||||||
var tokens = grabTokens(text);
|
var tokens = grabTokens(text);
|
||||||
return tokens.contain("play") && (tokens.contain("rock") && tokens.contain("paper") && tokens.contain("scissors"))
|
return tokens.contain("play") && (tokens.contain("rock") && tokens.contain("paper") && tokens.contain("scissors")) && (tokens.contain("rozbot") || userData.privateMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new Command("RockPaperScissors", condition, function(text, send, userData) {
|
module.exports = new Command("RockPaperScissors", condition, function(text, send, userData) {
|
||||||
|
|
|
@ -1,23 +1,27 @@
|
||||||
/***
|
|
||||||
Keep disabled until major rewrite has gone under way
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
***/
|
|
||||||
|
|
||||||
var Command = require('./Command.js');
|
var Command = require('./Command.js');
|
||||||
var grabTokens = require('../helpers/grabTokens.js');
|
var grabTokens = require('../helpers/grabTokens.js');
|
||||||
var greetings = "hello|hi|hey|yo|morning|afternoon|evening";
|
var greetings = "hello|hi|hey|yo|morning|afternoon|evening";
|
||||||
var wantSomething = /(\w+) (want|wants) ([^.&^\n]+)/i;
|
|
||||||
var happy = "yay|woo|yess|:D|:\\)"
|
var happy = "yay|woo|yess|:D|:\\)"
|
||||||
var url = "link|url";
|
var url = "link|url";
|
||||||
|
|
||||||
var condition = function(text) {
|
var condition = function(text, userData) {
|
||||||
|
var privateMessage = userData.privateMessage || false;
|
||||||
|
var tokens = grabTokens(text);
|
||||||
|
return (new RegExp(url).test(text) && tokens.contain("codeshare")) ||
|
||||||
|
(tokens.contain(":(")) ||
|
||||||
|
(tokens.superContain("thank") && (tokens.superContain("rozbot") || privateMessage)) ||
|
||||||
|
(text.toLowerCase() === "rozbot?") ||
|
||||||
|
((tokens.superContain("rozbot") || privateMessage) && tokens.superContain("hug")) ||
|
||||||
|
(new RegExp(happy, 'i').test(text)) ||
|
||||||
|
((tokens.contain("who") || tokens.contain("what")) && tokens.contain("brandon") && tokens.contain('rozek')) ||
|
||||||
|
((tokens.contain("how") || tokens.contain("doing") || tokens.contain("up")) && tokens.contain("brandon")) ||
|
||||||
|
((tokens.superContain('rozbot') || privateMessage) && new RegExp(greetings, 'i').test(text)) ||
|
||||||
|
((tokens.superContain("rozbot") || privateMessage) && tokens.superContain("what") && (tokens.contain("up") || tokens.contain("doing"))) ||
|
||||||
|
(tokens.superContain("rozbot") && tokens.superContain("what") && tokens.contain("job"))
|
||||||
}
|
}
|
||||||
module.exports = new Command("NaturalSpeech", condition, function(text, send, extra) {
|
module.exports = new Command("NaturalSpeech", condition, function(text, send, userData) {
|
||||||
var from = extra.from || "";
|
var from = userData.username || "";
|
||||||
var privateMessage = extra.privateMessage || false;
|
var privateMessage = userData.privateMessage || false;
|
||||||
var tokens = grabTokens(text);
|
var tokens = grabTokens(text);
|
||||||
/*
|
/*
|
||||||
Link to codeshare
|
Link to codeshare
|
||||||
|
@ -55,25 +59,11 @@ module.exports = new Command("NaturalSpeech", condition, function(text, send, ex
|
||||||
else if (new RegExp(happy, 'i').test(text)) {
|
else if (new RegExp(happy, 'i').test(text)) {
|
||||||
send("Yeah!");
|
send("Yeah!");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
[user] wants [item] -> Gives [user] [item]
|
|
||||||
*/
|
|
||||||
else if (wantSomething.test(text)) {
|
|
||||||
var responseTokens = wantSomething.exec(text);
|
|
||||||
var person = (responseTokens[1].toLowerCase() === "i")? from: responseTokens[1];
|
|
||||||
send("Gives " + person + " " + responseTokens[3]);
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Who is Brandon? -> Brandon is the most awesome person in the world.
|
Who is Brandon? -> Brandon is the most awesome person in the world.
|
||||||
*/
|
*/
|
||||||
else if ((tokens.contain("who") || tokens.contain("what")) && tokens.contain("brandon") && tokens.contain('rozek')) {
|
else if ((tokens.contain("who") || tokens.contain("what")) && tokens.contain("brandon") && tokens.contain('rozek')) {
|
||||||
send("Brandon is the most awesome person in the world.");
|
send("Brandon Rozek is the most awesome person in the world.");
|
||||||
}
|
|
||||||
/*
|
|
||||||
Who is Rozbot? -> A friendly neighborhood IRC bot
|
|
||||||
*/
|
|
||||||
else if (tokens.contain('who') || tokens.contain('what') && tokens.superContain("rozbot")&& !tokens.contain('radio')) {
|
|
||||||
send("A friendly neighborhood IRC bot");
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
What is Brandon up to? -> [Lists projects]
|
What is Brandon up to? -> [Lists projects]
|
||||||
|
@ -86,14 +76,10 @@ module.exports = new Command("NaturalSpeech", condition, function(text, send, ex
|
||||||
managing Math I/O\n\
|
managing Math I/O\n\
|
||||||
working on his apps codeshare or babbler.\n\
|
working on his apps codeshare or babbler.\n\
|
||||||
running his radio (https://radio.zeropointshift.com)\n\
|
running his radio (https://radio.zeropointshift.com)\n\
|
||||||
|
managing his raspberry pi infrastructure\n\
|
||||||
|
reading some books\n\
|
||||||
Hopefully, he's not working on me. Cuz' I'm perfect.");
|
Hopefully, he's not working on me. Cuz' I'm perfect.");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
How are you Rozbot? -> I'm awesome
|
|
||||||
*/
|
|
||||||
else if ((tokens.superContain("rozbot") || privateMessage) && tokens.contain("how")) {
|
|
||||||
send("I'm awesome.");
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
Good morning Rozbot! -> Hello [user]!
|
Good morning Rozbot! -> Hello [user]!
|
||||||
*/
|
*/
|
||||||
|
@ -101,10 +87,10 @@ module.exports = new Command("NaturalSpeech", condition, function(text, send, ex
|
||||||
send("Hello " + from + "!");
|
send("Hello " + from + "!");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
What are you up to Rozbot? -> Currently working on my job
|
What are you up to Rozbot? -> Just doing my job
|
||||||
*/
|
*/
|
||||||
else if ((tokens.superContain("rozbot") || privateMessage) && tokens.superContain("what") && (tokens.contain("up") || tokens.contain("doing"))) {
|
else if ((tokens.superContain("rozbot") || privateMessage) && tokens.superContain("what") && (tokens.contain("up") || tokens.contain("doing"))) {
|
||||||
send("Currently working on my job");
|
send("Just doing my job");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
What is your job Rozbot? -> Chilling on IRC doing whatever Brandon programs me to do
|
What is your job Rozbot? -> Chilling on IRC doing whatever Brandon programs me to do
|
||||||
|
@ -112,14 +98,5 @@ module.exports = new Command("NaturalSpeech", condition, function(text, send, ex
|
||||||
else if (tokens.superContain("rozbot") && tokens.superContain("what") && tokens.contain("job")) {
|
else if (tokens.superContain("rozbot") && tokens.superContain("what") && tokens.contain("job")) {
|
||||||
send("Chilling on IRC doing whatever Brandon programs me to do.");
|
send("Chilling on IRC doing whatever Brandon programs me to do.");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
Start Greenteam meeting -> [instructions for mumble]
|
|
||||||
*/
|
|
||||||
else if (tokens.contain("start") && tokens.contain("greenteam") && tokens.contain("meeting")) {
|
|
||||||
send("Everyone please connect to mumble\n\
|
|
||||||
Host: zeropointshift.com\n\
|
|
||||||
Leave port at default\n\
|
|
||||||
Give yourself a sensible username\n\
|
|
||||||
Label it whatever you want");
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue