Twitter Stream
Platform: mIRC
Published Feb 14, 2010
Updated Oct 27, 2012
Script was written at the request of lilibox
This script was made to post your friends timeline on a irc channel so that people who have twitter.com blocked at work can still see their updates.
While this script does accomplish this task, I designed it to have an @Twitter window that will keep track of your friends timeline so you don't have to open your browser to see their updates.
In addition, any non-command that you type in the @Twitter window will automatically update the twitter account that you added in the setup.
START HERE:
- Go here -->> http://dev.twitter.com/apps/new
- Fill in all the boxes
- Application Name: Will Posted after each tweet (ie via Application Name)
- Description: Anything you want here.
- Application Website: Will be linked to the application name in each tweet. (spam your website here)
- Anything you want here. Only shows on the apps page.
- Application Type: Click "Client".
- Default Access type: Click "Read & Write".
- Application Icon: You can skip this for now.
- Enter the Captcha
- Click "Register Application"
Now you have registered your first app :)
You can always go to
http://dev.twitter.com/apps/ and see your apps.
Now you just need to get the keys and secrets and put them in the script:
- Copy the code from this page and paste it to a new remote in the mIRC script editor. (keep this window open)
- Click on your application (if needed)
- Scroll down to Consumer key
- Copy the key and paste it over top of "PutYourConsumerKeyHere" in the consumer_key alias at the top of the mIRC script.
- Scroll to Consumer secret
- Copy and paste it over "PutYourConsumerSecretHere" in the consumer_secret alias.
- Now - On the right pane of your applications page - Click "My Access Token"
- Copy the token under "Access Token (oauth_token)" and paste it over "PutYourOauthTokenHere" in the oauth_token alias.
- Copy the token under "Access Token Secret (oauth_token_secret)" over "PutYourOauthTokenSecretHere" in the oauth_token_secret alias.
- Save the script with a unique filename and you are ready to Start :)
- Right click Channel or Status, Scroll to "Twitter Stream" and turn the script ON.
**All Done. @Twitter will open in about 60 seconds :)
Advanced Options:
**You can change the delay from setup but the minimum is 30 seconds.
**You can change the output from @Twitter to echo -at
**You can change the output to a #channel.(Make sure you open the menu from the network the #channel is in to change this setting.)
Example Output:
**Updated**
**Changed Edit box from Single line to Multi-Line.
**Added a Window to show your @Name highlights.
**Added Support for Re-tweets. Double Click [RT] To re-tweet.
**Added Double click to Shout. Just Double click a name and it will add @Name to the start of the edit box.
;Twitter Channel by Ford_Lawnmower irc.GeekShed.net #Script-Help
;;;;;;;;;;;;;;;;;
;::Start Setup::;
;;;;;;;;;;;;;;;;;
;Edit the lines below to reflect your Twitter Application info.
alias -l consumer_key return PutYourConsumerKeyHere
alias -l consumer_secret return PutYourConsumerSecretHere
alias -l oauth_token return PutYourOauthTokenHere
alias -l oauth_token_secret return PutYourOauthTokenSecretHere
;;;;;;;;;;;;;;;
;::End Setup::;
;;;;;;;;;;;;;;;
menu * {
.Twitter Stream
..$iif($timer(mIRCTwitter),Off,On): {
if ($timer(mIRCTwitter)) {
.timermIRCTwitter off
hadd -m mIRCTwitter Status 0
}
else {
mIRCTwitter
.timermIRCTwitter -o 0 $iif($hget(mIRCTwitter,Delay),$hget(mIRCTwitter,Delay),60) mIRCTwitter
hadd -m mIRCTwitter Status 1
}
}
..SetUp
...Set Delay:hadd -m mIRCTwitter Delay $iif($$?="Enter Delay in Seconds" > 29,$!,60) | mtsave
...Set Method of Output
....Bot Message(.msg #Channel):hadd mIRCTwitter Method $network .msg $$?="Enter the Channel Name including the #prefix" | mtsave
....Message(msg #Channel):hadd mIRCTwitter Method $network msg $$?="Enter the Channel Name including the #prefix" | mtsave
....Echo(Echo -at):hadd mIRCTwitter Method echo -at | mtsave
....Window(Echo -t @Twitter):hadd mIRCTwitter Method echo -t @Twitter | mtsave
}
alias -l mIRCTwitter mTwitterGetStatus echo -a $consumer_key $consumer_secret $oauth_token $oauth_token_secret
alias mIRCTweet mTwitterUpdate echo -a $consumer_key $consumer_secret $oauth_token $oauth_token_secret $1-
;Syntax mTwitterUpdate echo -a consumer_key consumer_secret oauth_token oauth_token_secret status update here
;Note that echo -a can be changed to msg $chan or notice $nick ( must be two words )
alias -l mTwitterUpdate {
var %ots $ctime, %sockname mTwitterUpdate, %once $md5(%sockname)
var %os $signature(post,http://api.twitter.com/1/statuses/update.xml,$3,$4,$5,$6,%once,%ots,$+(status=,$tuenc($7-)))
.sockclose %sockname
sockopen %sockname api.twitter.com 80
sockmark %sockname $1-2 $space2comma($+(oauth_nonce=,$qt(%once)) $osmqt $+(oauth_timestamp=,$qt(%ots)) $+(oauth_consumer_key=,$qt($tuenc($3))) $&
$+(oauth_token=,$qt($tuenc($5))) $+(oauth_signature=,$qt($suenc(%os))) $overqt) $+(status=,$tuenc($7-))
}
on *:sockopen:mTwitterUpdate: {
if ($sockerr) echo -st Socket Error $nopath($script)
else {
tokenize 32 $sock($sockname).mark
sockwrite -n $sockname POST /1/statuses/update.xml HTTP/1.1
sockwrite -n $sockname Host: api.twitter.com
sockwrite -n $sockname User-Agent: Lawnmower 9.64
sockwrite -n $sockname Authorization: OAuth realm="/1/statuses/update.xml", $3
sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
sockwrite -n $sockname Content-Length: $len($4)
sockwrite -n $sockname
sockwrite -n $sockname $4
sockwrite -n $sockname
}
}
on *:sockread:mTwitterUpdate: {
if ($sockerr) { $gettok($sock($sockname).mark,1-2,32) Unknown Socket error $nopath($script) }
else {
var %mTwitterUpdatevar | sockread %mTwitterUpdatevar
if (HTTP/1.1 401 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Password/Username Error --> %mTwitterUpdatevar
sockclose $sockname | return
}
elseif (HTTP/1.1 502 isin %mTwitterUpdatevar) || (HTTP/1.1 503 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Server Busy Error --> %mTwitterUpdatevar
sockclose $sockname | return
}
elseif (HTTP/1.1 500 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Server Side Error --> %mTwitterUpdatevar
sockclose $sockname | return
}
elseif (HTTP/1.1 403 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Connection Actively Refused --> %mTwitterUpdatevar
sockclose $sockname | return
}
elseif (HTTP/1.1 400 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Unknown Error --> %mTwitterUpdatevar
sockclose $sockname | return
}
elseif (HTTP/1.1 200 isin %mTwitterUpdatevar) {
$gettok($sock($sockname).mark,1-2,32) Updating Status Please Wait.........
}
elseif (</status> isin %mTwitterUpdatevar) {
.timer 1 3 $gettok($sock($sockname).mark,1-2,32) Your Status has been updated :)
sockclose $sockname | return
}
}
}
alias -l mTwitterGetStatus {
var %ots $ctime, %sockname mTwitterGetStatus, %once $md5(%sockname), %sinceid $iif($hget(mirctwitter,last_id),$v1,1)
var %os $signature(GET,http://api.twitter.com/1/statuses/home_timeline.rss,$3,$4,$5,$6,%once,%ots,$+(since_id=,%sinceid))
.sockclose %sockname
sockopen %sockname api.twitter.com 80
sockmark %sockname $1-2 $space2comma($+(oauth_nonce=,$qt(%once)) $osmqt $+(oauth_timestamp=,$qt(%ots)) $+(oauth_consumer_key=,$qt($tuenc($3))) $&
$+(oauth_token=,$qt($tuenc($5))) $+(oauth_signature=,$qt($suenc(%os))) $overqt $+(since_id=,%sinceid)) 1 1
}
on *:sockopen:mTwitterGetStatus: {
if ($sockerr) echo -st Socket Error $nopath($script)
else {
tokenize 32 $sock($sockname).mark
sockwrite -n $sockname GET /1/statuses/home_timeline.rss? $+ $+(since_id=,$iif($hget(mirctwitter,last_id),$v1,1)) HTTP/1.1
sockwrite -n $sockname Host: api.twitter.com
sockwrite -n $sockname User-Agent: Lawnmower 9.64
sockwrite -n $sockname Authorization: OAuth realm="/1/statuses/home_timeline.rss", $3
sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
sockwrite -n $sockname $crlf
}
}
On *:sockread:mTwitterGetStatus: {
if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
else {
var %mTwitterGetStatus | sockread %mTwitterGetStatus
if (<item> isin %mTwitterGetStatus) { sockmark $sockname $puttok($sock($sockname).mark,1,3,32) }
elseif ($regex(%mTwitterGetStatus,/<title>Twitter\s\/\s(.*)\swith\sfriends<\/title>/i)) hadd -m mIRCTwitter Name $+(@,$regml(1))
elseif ($gettok($sock($sockname).mark,4,32)) && ($regex(%mTwitterGetStatus,/<guid>http:\/\/twitter\.com\/.*\/statuses\/(.*?)<\/guid>/i)) {
hadd mirctwitter Last_ID $regml(1)
sockmark $sockname $puttok($sock($sockname).mark,0,4,32)
}
elseif ($gettok($sock($sockname).mark,3,32)) && ($regex(%mTwitterGetStatus,<title>(.*)</title>)) {
sockmark $sockname $puttok($sock($sockname).mark,$calc($gettok($sock($sockname).mark,5,32) + 1),5,32)
var %Method $hget(mIRCTwitter,Method), %match $regml(1)
if (%Method == echo -at) { %Method $fix&#($+(09<07,$gettok(%match,1,58),09>04) $gettok(%match,2-,58)) }
elseif ($me ison $gettok(%Method,3,32)) {
.timer 1 $gettok($sock($sockname).mark,5,32) $gettok(%Method,2-,32) $fix&#($+(09<07,$gettok(%match,1,58),09>04) $gettok(%match,2-,58))
}
else {
if (!$window(@Twitter)) { window -E @Twitter }
var %NextTweet $fix&#($+(09<07,$gettok($regml(1),1,58),09>04) $gettok($regml(1),2-,58)) 02,08[04RT02]
echo -t @Twitter %NextTweet
if ($istok(%NextTweet,$hget(mIRCTwitter,Name),32)) {
if (!$window($hget(mIRCTwitter,Name))) { window -E $hget(mIRCTwitter,Name) }
echo -t $hget(mIRCTwitter,Name) %NextTweet
noop $tip($hget(mIRCTwitter,Name),Twitter $hget(mIRCTwitter,Name),%NextTweet,60,,,,)
}
}
}
}
}
;Syntax $signature(POST/GET,URL,consumer_key,consumer_secret,oauth_token,oauth_token_secret,oauth_nonce,oauth_timestamp,PostData)
alias -l signature {
var %method $+($upper($1),&), %url $+($tuenc($2),&), %ck $tuenc&($+(oauth_consumer_key=,$3)), %ot $tuenc&($+(oauth_token=,$5))
var %once $tuenc&($+(oauth_nonce=,$7)), %ots $tuenc&($+(oauth_timestamp=,$8)), %post $iif($9-,$tuenc($+(&,$9-)))
return $hmacsha1($+($4,&,$iif($6,$6)),$+(%method,%url,%ck,%once,$tuenc&($osm),%ots,%ot,$tuenc($over),%post))
}
alias -l osm return oauth_signature_method=HMAC-SHA1
alias -l osmqt return oauth_signature_method="HMAC-SHA1"
alias -l over return oauth_version=1.0
alias -l overqt return oauth_version="1.0"
alias -l tuenc return $regsubex($replace($1-,+,$chr(32)),/([^a-z0-9._-])/ig,% $+ $base($asc(\t),10,16,2))
alias -l suenc return $regsubex($1-,/([^a-z0-9._-])/ig,% $+ $base($asc(\t),10,16,2))
alias -l space2comma return $replace($1-,$chr(32),$chr(44))
alias -l tuenc& return $tuenc($+($1,&))
;hmacsha1 by Ford_Lawnmower irc.GeekShed.net #Script-Help
;Syntax hmacsha1 key message or $hmacsha1(key,message)
alias -l hmacsha1 {
var %key $1, %data $2
bset -c &key 1 $regsubex(%key,/(.)/g, $asc(\1) $chr(32))
bset -c &data 1 $regsubex(%data,/(.)/g, $asc(\1) $chr(32))
if ($bvar(&key,0) > 64) bset -c &key 1 $hex2chr($sha1(&key,1))
bset -c &ipad 1 $xorall($str($+(54,$chr(32)),64),$bvar(&key,1-))
bset -c &opad 1 $xorall($str($+(92,$chr(32)),64),$bvar(&key,1-))
bcopy &ipad $calc($bvar(&ipad,0) + 1) &data 1 -1
bset -c &ipad 1 $hex2chr($sha1(&ipad,1))
bcopy &opad $calc($bvar(&opad,0) + 1) &ipad 1 -1
bset -c &return 1 $hex2chr($sha1(&opad,1))
noop $encode(&return, mb)
$iif($isid,return,$iif(#,say,echo -a)) $bvar(&return, 1-).text
}
alias -l hex2chr return $regsubex($1-,/(.{2})/g, $base(\t,16,10) $chr(32))
alias -l xorall {
var %p $1, %k $2, %end $iif($regex($1,/([\d]{1,})/g) > $regex($2,/([\d]{1,})/g),$v1,$v2)
return $regsubex($str(.,%end),/(.)/g,$+($xor($iif($gettok(%p,\n,32),$v1,0),$iif($gettok(%k,\n,32),$v1,0)),$chr(32)))
}
On *:input:$($+($hget(mIRCTwitter,Name),$chr(44),@Twitter)): {
if ($left($1,1) != /) {
haltdef
echo -t $active $+(07<09,$mid($hget(mIRCTwitter,Name),2-),07>09) $1-
mIRCTweet $1-
}
}
alias -l fix&# {
return $regsubex($replace($regsubex($1-,/\&\#([0-9]{1,});/g,$utf8(\t)),",",&,&,>,>,<,<,',',$chr(9),$chr(32)),$&
/([$\|%\[\]\}\{][^\s]*)/g,$+($chr(2),$chr(2),\t))
}
alias -l UTF8 {
if ($version >= 7) return $chr($1)
elseif ($1 < 255) { return $chr($1) }
elseif ($1 >= 256) && ($1 < 2048) { return $+($chr($calc(192 + $div($1,64))),$chr($calc(128 + $mod($1,64)))) }
elseif ($1 >= 2048) && ($1 < 65536) { return $+($chr($calc(224 + $div($1,4096))),$chr($calc(128 + $mod($div($1,64),64))),$chr($calc(128 + $mod($1,64)))) }
elseif ($1 >= 65536) && ($1 < 2097152) {
return $+($chr($calc(240 + $div($1,262144))),$chr($calc(128 + $mod($div($1,4096),64))),$chr($calc(128 + $mod($div($1,64),64))),$&
$chr($calc(128 + $mod($1,64))))
}
}
alias -l div { return $int($calc($1 / $2)) }
alias -l mod {
var %int $int($calc($1 / $2))
return $calc($1 - (%int * $2))
}
alias -l H2U { return $utf8($base($1,16,10)) }
alias -l mtsave {
if ($hget(mIRCTwitter,Status)) {
.timermIRCTwitter -o 0 $iif($hget(mIRCTwitter,Delay),$hget(mIRCTwitter,Delay),60) mIRCTwitter
}
if ($hget(mIRCTwitter)) { hsave mIRCTwitter mIRCTwitter.hsh }
}
on ^$*:HOTLINK:/^<([^<>]*)>/S:$($+($hget(mIRCTwitter,Name),$chr(44),@Twitter)):{
if ($1) { return }
halt
}
on ^$*:HOTLINK:/^\[RT\]/S:$($+($hget(mIRCTwitter,Name),$chr(44),@Twitter)):{
if ($1) { return }
halt
}
on $*:HOTLINK:/^<([^<>]*)>/S:$($+($hget(mIRCTwitter,Name),$chr(44),@Twitter)):{
if ($mouse.key) { editbox $active $+(@,$strip($regml(1))) }
halt
}
on $*:HOTLINK:/^\[RT\]/S:$($+($hget(mIRCTwitter,Name),$chr(44),@Twitter)):{
if ($mouse.key) {
noop $regex($hotline,/<([^<>]*)>(.*)\[RT\]/S)
editbox $active RT $strip($+(@,$regml(1)) $regml(2))
}
halt
}
On *:Start: {
hmake mIRCTwitter 1
if ($isfile(mIRCTwitter.hsh)) { hload mIRCTwitter mIRCTwitter.hsh | mtsave }
}
On *:Unload: {
if ($hget(mIRCTwitter)) { hfree mIRCTwitter }
if ($isfile(mIRCTwitter.hsh)) { .remove mIRCTwitter.hsh }
}