Skip to content

Commit

Permalink
[api] Added !mute and !unmute for twitter stream
Browse files Browse the repository at this point in the history
  • Loading branch information
avian authored and avian committed May 18, 2011
1 parent d3e8fd7 commit 967e756
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"author": "",
"author": "AvianFlu",
"name": "Kohai",
"version": "0.0.0",
"repository": {
Expand Down
54 changes: 37 additions & 17 deletions plugins/alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,49 @@ module.exports = function (config) {
var client = this
var whitelist = config.plugins.alias.whitelist
client.triggers = {
"insultme" : function (message) {
config.channels.forEach(function (channel, index) {
client.say(channel, message + " is a scurrilous knave!")
})
"insultme" : function (channel, name, message) {
client.say(channel, name + " is a wombat-loving heifer-puncher!")
},

"gtfo" : function () { process.exit() }
}
client.on("message",function triggerListener(name,to,message) {
for (var i=0; i<whitelist.length; i++) {
if (whitelist[i] == name) {
var trigger_match = message.match(/^[!](\S+)(.*|$)?/)
if(trigger_match) {
var trigger = trigger_match[1]
"gtfo" : function (channel, name, message) { process.exit() },

"mute" : function (channel) {
if(!beQuiet) {
beQuiet = true
setTimeout(function(){
beQuiet = false
client.say(channel, "Twitter mute expired")
}, 60000)
client.say(channel, "Twitter stream muted for next 60 seconds.")
}
else { client.say(channel, "Already muted!") }
},

var handler = client.triggers[trigger]
if(handler) {
var args = arghelper(trigger_match[2])
handler.apply(client,[name,to,message].concat(args));
"unmute" : function (channel) {
if(beQuiet){
beQuiet = false
client.say(channel, "Twitter mute cancelled")
}
else { client.say(channel, "Not currently muted!") }
}
}
config.channels.forEach(function (channel, index) {
client.on("message" + channel,function triggerListener(from, message) {
for (var i=0; i<whitelist.length; i++) {
if (whitelist[i] == from) {
var trigger_match = message.match(/^[!](\S+)(.*|$)?/)
if(trigger_match) {
var trigger = trigger_match[1]

var handler = client.triggers[trigger]
if(handler) {
var args = arghelper(trigger_match[2])
handler.apply(client,[channel,from,message].concat(args));
}
}
}
}
}
})
})


Expand Down
14 changes: 8 additions & 6 deletions plugins/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(config){
var tracking = config.plugins.twitter.track
if(!tracking) { tracking=[] }
else { tracking = tracking.concat() }
beQuiet = false
twit = new twitter(config.auth.twitter);

try {
Expand All @@ -22,11 +22,13 @@ module.exports = function(config){
twit.stream('user', {track:config.plugins.twitter.track}, function(stream) {
stream.on('data', function (data) {
//console.log(sys.inspect(data));
if((data.text)&&((!data.text.match(/.*\bRT:?.*/i))&&(!data.retweeted))) {
config.channels.forEach(function (channel, index) {
client.say(channel, "@" + data.user.screen_name + ": " + data.text)
})
console.log("@" + data.user.screen_name + ": " + data.text)
if(!beQuiet) {
if((data.text)&&((!data.text.match(/.*\bRT:?.*/i))&&(!data.retweeted))) {
config.channels.forEach(function (channel, index) {
client.say(channel, "@" + data.user.screen_name + ": " + data.text)
})
console.log("@" + data.user.screen_name + ": " + data.text)
}
}
})
})
Expand Down

0 comments on commit 967e756

Please sign in to comment.