Twitter Eggdrop script

I’ve started to play around the the Twitter API a little and created a small script to grab the contents of a spammed tweet link and display it in the channel.
Requires an API key etc for Oauth which you can request here: https://apps.twitter.com/

Hopefully add more features soon since the API has quite a few knobs to play with 🙂 At the moment the script can be grabbed [here] and looks like the code below:

#########################################################################################
# Name          m00nie::twitter
# Description   Uses twitter API to automatically grab tweet details and spam in chan for
#       any tweets linked to.
#
# Version       1.0 - Initial release
# Website       https://www.m00nie.com
# Notes         Create ypu own API keys here: https://apps.twitter.com/
#       requires .chanset #chan +twitter
#########################################################################################
namespace eval m00nie {
namespace eval twitter {
package require oauth
package require json
bind pubm - * m00nie::twitter::autoinfo
variable version "1.0"
setudef flag twitter
# Setup your own app and keys at the URL above
oauth::config -consumerkey {-GET-YOUR-OWN-} -consumersecret {-GET-YOUR-OWN-} -accesstoken {-GET-YOUR-OWN-} -accesstokensecret {-GET-YOUR-OWN-}
variable regex {(?:http(?:s|).{3}|)(?:www.|)(?:twitter.com\/?.*status\/)([\d-]{1,100})}

proc autoinfo {nick uhost hand chan text} {
if {[channel get $chan twitter] && [regexp -nocase -- $m00nie::twitter::regex $text url id]} {
putlog "m00nie::twitter::autoinfo is running"
set response [oauth::query https://api.twitter.com/1.1/statuses/show.json?id=$id]
set response [lindex $response 1]
set response [dict get [json::json2dict $response]]
set tweet_txt [dict get $response text]
set tweet_user [dict get $response user screen_name]
putlog "m00nie::twitter::autoinfo @$tweet_user said: $tweet_txt"
puthelp "PRIVMSG $chan :\002@$tweet_user\002: $tweet_txt"
}
}
}
}
putlog "m00nie::twitter $m00nie::twitter::version loaded"

Any comments/suggestions as always are more then welcome 🙂

m00nie

Leave a Reply