mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Hello,

I've got a twitter script and it shows the last tweet and stats.
This is how it shows a last tweet:

14.15.40 <DJ-Serv> (Last tweet) @riccremer Hihihi oke maar ik moet wel van m'n pappie voor het donker thuis zijn hoor :$

I'd like to have the mentions (the names starting with @, in thic case '@riccremer') colored. Only I don't know how.

It should be like this: 14.15.40 <DJ-Serv> (Last tweet) @riccremer Hihihi oke maar ik moet wel van m'n pappie voor het donker thuis zijn hoor :$

I also like to have the same with the hashtags, #words #starting #with #this #char.

Can anyone help?

Script:
Code:
on *:CONNECT: {
  var %twitter_file  $+(twitter_,$network)
  hmake %twitter_file 100
  if ($isfile($+(%twitter_file,.dat))) { hload %twitter_file $+(%twitter_file,.dat) }
}
ON *:DISCONNECT: {
  var %twitter_file  $+(twitter_,$network)
  if ($hget(%twitter_file)) { hsave -o %twitter_file $+(%twitter_file,.dat) }
}

on *:TEXT:.twitter*:#: {
  unset %t_*
  set %t_nick $nick
  set %t_chan $chan
  set %t_network $network
  set %t_2 $2
  set %t_3 $3
  if ($3 == s) || ($3 == stats) || ($3 == status) { set %t_3 stats | set %t_info_req ON }
  if ($3 == last) || ($3 == time) { set %t_3 last | set %t_info_req ON }

  if $2 == $null {
    msg $chan  $+ %sc2 $+ ( $+ %sc $+ Twitter $+ %sc2 $+ ) Please specify a command, ex.:
    msg $chan  $+ %sc2 $+ ( $+ %sc $+ Twitter $+ %sc2 $+ ) .twitter  $+ %sc2 $+ username/ircnick,  $+ %sc2 $+ username/ircnick stats,  $+ %sc2 $+ register username/ircnick or  $+ %sc2 $+ remove username/ircnick
    msg $chan  $+ %sc2 $+ ( $+ %sc $+ Twitter $+ %sc2 $+ ) The command  $+ %sc2 $+ register will associate your current IRC Nickname with the given twitter username.  $+ %sc2 $+ Remove will remove the association and  $+ %sc2 $+ stats will show the statics of the given twitter username.
    halt
  }

  if (%t_2 != $null) {
    var %twitter_reg $($+(twitter_,$network))
    if (%t_2 == register) && (%t_3 != $null) {
      hadd -m %twitter_reg %t_nick %t_3
      .msg %t_nick You are now linked to %t_3
      set %t_2 $hget(%twitter_reg,%t_nick)
      halt
    }
    if (%t_2 == remove) && (%t_3 != $null) {
      hdel %twitter_reg %t_nick
      .msg %t_nick You twitter association was removed
      twitter_cleanup
      halt
    }
    if ($hget(%twitter_reg,%t_2) != $null ) {
      set %t_2 $hget(%twitter_reg,%t_2)
    }
    set %t_url $+(/statuses/user_timeline.xml?screen_name=,%t_2)
  }
  sockopen twitter www.twitter.com 80
}

on *:sockopen:twitter: {
  sockwrite -n $sockname GET %t_url
  sockwrite -n $sockname www.twitter.com
}

on *:sockread:twitter: {
  sockread %t_temp
  if (<id> isin %t_temp) && (%t_id == $null) set %t_id $remove(%t_temp,<id>,</id>,$chr(9),$chr(32))
  if (<name> isin %t_temp) && (%t_name == $null) set %t_name $remove(%t_temp,<name>,</name>,$chr(9))
  if (<screen_name> isin %t_temp) && (%t_screen_name == $null) set %t_screen_name $remove(%t_temp,<screen_name>,</screen_name>,$chr(9),$chr(32))
  if (<location> isin %t_temp) && (%t_location == $null) set %t_location $remove(%t_temp,<location>,</location>,$chr(9),$chr(32))
  if (<description> isin %t_temp) set %t_description $remove(%t_temp,<description>,</description>,$chr(9))

  if (<followers_count> isin %t_temp) && (%t_followers_count == $null) set %t_followers_count $remove(%t_temp,<followers_count>,</followers_count>,$chr(9),$chr(32))
  if (<friends_count> isin %t_temp) && (%t_friends_count == $null) set %t_friends_count $remove(%t_temp,<friends_count>,</friends_count>,$chr(9),$chr(32))
  if (<favourites_count> isin %t_temp) && (%t_favourites_count == $null) set %t_favourites_count $remove(%t_temp,<favourites_count>,</favourites_count>,$chr(9),$chr(32))
  if (<time_zone> isin %t_temp) && (%t_time_zone == $null) set %t_time_zone $remove(%t_temp,<time_zone>,</time_zone>,$chr(9),$chr(32))
  if (<statuses_count> isin %t_temp) && (%t_statuses_count == $null) set %t_statuses_count $remove(%t_temp,<statuses_count>,</statuses_count>,$chr(9),$chr(32))

  if (<status> isin %t_temp) inc %t_i
  if (<created_at> isin %t_temp) set %t_created_at $remove(%t_temp,<created_at>,</created_at>,$chr(9))
  if (<text> isin %t_temp) set $+(%,t_text,%t_i) $remove(%t_temp,<text>,</text>,$chr(9))
  if (<source> isin %t_temp) set $+(%,t_source,%t_i) $remove(%t_temp,<source>,</source>,$chr(9))
  if (<error> isin %t_temp) set %t_error ON
}


on *:sockclose:twitter: {
  if (%t_error == ON) {
    msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Twitter $+ %sc2 $+ ) Sorry, %t_2 wasn't found.
    twitter_cleanup
  }
  if (%t_error == $null) {
    if (%t_3 == bio) {
      if %t_description == $null {
        msg %t_chan test ik ben leeg.
      }
      else {
        msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Biography $+ %sc2 $+ ) %t_description
        halt
      }
    }
    if (%t_info_req != ON) msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Last tweet $+ %sc2 $+ ) $replace(%t_text1,&#235;,ë)
    if (%t_3 == stats) msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Twitter $+ %sc2 $+ ) %t_screen_name is  $+ %sc2 $+ following  $+ %sc $+ %t_friends_count $+  people, is having  $+ %sc $+ %t_followers_count $+   $+ %sc2 $+ follower(s) and has posted  $+ %sc $+ %t_statuses_count $+   $+ %sc2 $+ tweet(s).
  }
  twitter_cleanup
}

alias twitter_cleanup {
  unset %t_*
}





EDIT:
I just found something that doesnt work well. Maybe someone can help with this to? The script does NOT get the LATEST updates. It gets ALL updates. That's not a huge problem, but it is with the following:

if (<description> isin %t_temp) set %t_description $remove(%t_temp,<description>,</description>,$chr(9))



Here it gets the information 'description' from the .xml file (example: http://twitter.com/statuses/user_timeline/riccremer.xml)

But the .xml file contains not 1 'description', but more and now the script doesn't get the FIRST 'decsription' in the .xml file, it gets the one wayyyy down the page. (Sorry for my bad english. It just needs to get the first 'description' of the .xml file')

Someone can help with this too? I hope so! The decsription part is used at


if %t_description == $null {
msg %t_chan test ik ben leeg.
}
else {
msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Biography $+ %sc2 $+ ) %t_description
halt
}

Last edited by DuXxXieJ; 12/12/10 01:51 PM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
To only get the first description or anything else, you have a couple of options. You can change all of your variable lines to be something like this:

Code:
  if (<description> isin %t_temp && !%t_description) set %t_description $remove(%t_temp,<description>,</description>,$chr(9))


Then, just make sure you use your cleanup alias before running the script again. I'd suggest adding the !%t_variable part to everything you have if there is a chance they will appear more than once and if you only want the first one.

Or, you can just close the socket as soon as you see </status>:

Code:
  if (</status> isin %t_temp) sockclose twitter


That goes in your sockread event. It will close the socket as soon as the first status is read. It's the way I'd recommend unless you need something further down the XML file.

As far as replacing your @ and # words with colors, you can use this...

For any variable that will need those colored, use:

Code:
noop $regsub(%t_variable,/(@\w.*?\b)/g,04\1,%t_variable)
noop $regsub(%t_variable,/(#\w.*?\b)/g,04\1,%t_variable)


Replace the 04 with the color you want (line 1 is @ words and line 2 is # words). And replace %t_variable with your variable name(s) that you need. Note that the variable is in each line twice. Put these before any msg line.

** There may be a way to combine these into one command, but I'm not sure how. Maybe someone else knows and can explain how.

Last edited by Riamus2; 12/12/10 02:33 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Thanks! It works, just got one small issue right now. When ë,á,é etc.etc. isn't read well it goes like: &#235;. I had that fixed using replace, only it doesn't replace it anymore because of the noop thing.

Chlo&#235; <--

Any help?

Code:
    if (%t_info_req != ON) {
      noop $regsub(%t_text1,/(@\w.*?\b)/g,14\1,%t_text1)
      noop $regsub(%t_text1,/(#\w.*?\b)/g,14\1,%t_text1)
      msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Last tweet $+ %sc2 $+ ) $replace(%t_text1,&#235;,ë)
    }




EDIT: never mind! got it fixed. tried this:

Code:
      
      var %t_text1 $replace(%t_text1,&#235;,ë)
      noop $regsub(%t_text1,/(@\w.*?\b)/g,14\1,%t_text1)
      noop $regsub(%t_text1,/(#\w.*?\b)/g,14\1,%t_text1)
      msg %t_chan  $+ %sc2 $+ ( $+ %sc $+ Last tweet $+ %sc2 $+ ) $replace(%t_text1,&#235;,ë)


(The var thing). now it works, never mind smile

Last edited by DuXxXieJ; 18/12/10 03:11 PM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Why do you have two same $replace? You only need one, because you already have done that for var %t_text1


Link Copied to Clipboard