var request = require('request');
var twitterApi = function(api, action, callback){
	request('http://api.twitter.com/1/' + api + '/' + encodeURIComponent(action) + '.json', function(error, response, body){
		var data;
		try{
			data = JSON.parse(body);
		}catch(e){
			data = {};
		}
		if(typeof callback == 'function'){
			callback(data);
		}
	});
};
var formatTweet = function(tweet){
	var out, unDumbed;
	if(tweet && tweet.text && tweet.user){
		unDumbed = tweet.text.replace(/\&lt;/g, '<').replace(/\&gt;/g, '>').replace(/\&amp;/g, '&');
		out =  '<@' + tweet.user.screen_name + '> ' + unDumbed;
	}
	return out;
};
module.exports = function(bot){
	bot.addCommand('twitter', 'Twitter', '<type> <user/status>', USER_LEVEL_NORMAL, false, function(event){
		var type = event.params[0];
		switch(type){
			case 'user':
				if(event.params && event.params[1]){
					var user = event.params[1];
					twitterApi('statuses/user_timeline', user, function(data){
						console.log(data);
						var tweet = formatTweet(data[0]);
						if(tweet){
							bot.message(event.target, tweet);
						}else{
							bot.message(event.target, 'Could not find tweet for: ' + user);
						}
					});
				}
			break;
			case 'status':
				if(event.params && event.params[1]){
					var status = event.params[1];
					twitterApi('statuses/show', status, function(data){
						console.log(data);
						var tweet = formatTweet(data);
						if(tweet){
							bot.message(event.target, tweet);
						}else{
							bot.message(event.target, 'Could not find tweet ' + status);
						}
					});
				}
			break;
		}
	});
}
@@ -795,16 +795,381 @@
 (type)%7B%0A
+%09%09%09default:%0A%09%09%09%09if(event.params && event.params%5B0%5D)%7B%0A%09%09%09%09%09var user = event.params%5B0%5D;%0A%09%09%09%09%09twitterApi('statuses/user_timeline', user, function(data)%7B%0A%09%09%09%09%09%09var tweet = formatTweet(data%5B0%5D);%0A%09%09%09%09%09%09if(tweet)%7B%0A%09%09%09%09%09%09%09bot.message(event.target, tweet);%0A%09%09%09%09%09%09%7Delse%7B%0A%09%09%09%09%09%09%09bot.message(event.target, 'Could not find tweet for: ' + user);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D);%0A%09%09%09%09%7D%0A%09%09%09break;%0A
 %09%09%09case 
@@ -1318,33 +1318,8 @@
 a)%7B%0A
-%09%09%09%09%09%09console.log(data);%0A
 %09%09%09%09

improve twitter plugin