Added basic tweet component parsing, along with Twit error checking.
parent
5dd333285d
commit
fe63c29c30
71
index.js
71
index.js
|
@ -12,6 +12,33 @@ Tweet Transaction example:
|
||||||
a: You take the painting.
|
a: You take the painting.
|
||||||
b: @TwittMUD south
|
b: @TwittMUD south
|
||||||
a: You are on a balcony overlooking the ocean. There is a lighthouse. There are exits: north
|
a: You are on a balcony overlooking the ocean. There is a lighthouse. There are exits: north
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
How does the game world structure look?
|
||||||
|
|
||||||
|
Room-oriented:
|
||||||
|
|
||||||
|
start {
|
||||||
|
things: {
|
||||||
|
0: 'candle',
|
||||||
|
1: 'thing'
|
||||||
|
},
|
||||||
|
exits: {
|
||||||
|
'e': 'eastern_plaza'
|
||||||
|
},
|
||||||
|
locations: {
|
||||||
|
'lighthouse': {
|
||||||
|
distance: 0,
|
||||||
|
direction: 'w',
|
||||||
|
location: 'plateu'
|
||||||
|
}
|
||||||
|
'beach'
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
0: '123435388',
|
||||||
|
1: '123444441'
|
||||||
|
}
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
var Twit = require('twit');
|
var Twit = require('twit');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
@ -31,12 +58,17 @@ var gogogo = function() {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
client = new Twit({
|
try {
|
||||||
consumer_key: config.consumer_key,
|
client = new Twit({
|
||||||
consumer_secret: config.consumer_secret,
|
consumer_key: config.consumer_key,
|
||||||
access_token: config.access_token,
|
consumer_secret: config.consumer_secret,
|
||||||
access_token_secret: config.access_token_secret
|
access_token: config.access_token,
|
||||||
});
|
access_token_secret: config.access_token_secret
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
stream = client.stream('user', {with: 'user'});
|
stream = client.stream('user', {with: 'user'});
|
||||||
stream.on('follow', handleFollow);
|
stream.on('follow', handleFollow);
|
||||||
stream.on('unfollow', handleUnfollow);
|
stream.on('unfollow', handleUnfollow);
|
||||||
|
@ -45,13 +77,32 @@ var gogogo = function() {
|
||||||
};
|
};
|
||||||
/* ================ Handler Functions (events, tweets, etc.) ================ */
|
/* ================ Handler Functions (events, tweets, etc.) ================ */
|
||||||
/* handleTweet
|
/* handleTweet
|
||||||
Called on each tweet to this Twitter account.
|
Called on each tweet to this Twitter account. After some checks to ensure the tweet is intended for TwittMUD and is a command, it calls handleCommand, passing the contents of the message, who it was from, the desired lang, and the reply_id if it exists.
|
||||||
*/
|
*/
|
||||||
var handleTweet = function(tweet) {
|
var handleTweet = function(tweet) {
|
||||||
vol.last_tweet_id = tweet.id;
|
var from = tweet.user.id;
|
||||||
|
var id = tweet.id;
|
||||||
|
var id_str = tweet.id_str;
|
||||||
|
var reply_id = tweet.in_reply_to_status_id;
|
||||||
|
var text = tweet.text;
|
||||||
|
var lang = tweet.lang;
|
||||||
|
//vol.last_tweet_id = tweet.id;
|
||||||
// does the response match
|
// does the response match
|
||||||
var user = tweet.text.split
|
var exp = /^@(.*)\ (.*)/
|
||||||
console.log(tweet);
|
var res = exp.exec(text);
|
||||||
|
var to = res[1];
|
||||||
|
var msg = res[2];
|
||||||
|
// Conditions for handling messages as commands:
|
||||||
|
// 2. does the user follow us? (is in followers)
|
||||||
|
// * is the user active? (is in active users list)
|
||||||
|
// 3. is it a reply?
|
||||||
|
// *
|
||||||
|
// 4. Is the message parsable as a command?
|
||||||
|
// 1. is the message to us? (@TwittMUD)
|
||||||
|
var user = 'TwittMUD'; // TODO: replace with config.user_name
|
||||||
|
if (to.toLowerCase().indexOf(user.toLowerCase()) != -1) {
|
||||||
|
}
|
||||||
|
console.log(from + '=>' + to + ': ' + msg);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
/* handleFollow
|
/* handleFollow
|
||||||
|
|
Loading…
Reference in New Issue