Twitter Directory (With Twitter Stats)

By MaxEvans on Mar 08, 2009

I created this out of boredom. it's a little script that allows chatters to connect via Twitter, by letting people put their Twitter URL in the Directory, which the script writes as a txt file. And upon requesting the Directory, by typing !Twitter, you'll get a pm from the bot listing all the Nicks and Twitter URLs in the Directory.

(I do not recommend you use this script if you have 100+ people who'd use it. Thus causing lag.)

Usage:

1: Typing !MyTwitter UserNameHere will add your Twitter URL to the Directory. Do not type http://twitter.com, as the script will already write it into the file.

2: You will get a notice from the bot confirming your URL has been added to the directory.

3: To request the directory, type !Twitter. The bot will send you a query with the URLs in the Directory.

  1. Typing !Twitter Username will return stats about the username entered. (Number of followers Username has, number of people Username is following, and number of updates Username has.)

Tested and working 100%, working on adding an additional feature, stay tuned for changes. Any problems let me know.

Thanks goes to Blitzjager for helping with the sockets. =]

on *:TEXT:!MyTwitter *:#: {
 if ($nick isvoice $chan) {
write Twitter.txt $nick $+ : http://twitter.com/ $+ $$2
notice $nick Your Twitter URL Has Been Added To The Directory.
}
 else {
 notice $nick You must be using a registered nickname and voiced in $chan to use the Twitter Directory.
}
 }

on *:TEXT:!Twitter:#: {
.play $nick Twitter.txt
.timer 1 3 notice $nick I sent you a pm with the directory.
}

alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | 

return %x }
alias twit {
  if (!$sock(twitter)) {
    sockopen twitter twitter.com 80
    sockmark twitter $chan $1
  }
}

on *:sockopen:twitter: {
  sockwrite -nt $sockname GET / $+ $gettok($sock(twitter).mark,2,32) HTTP/1.1
  sockwrite -nt $sockname Host: twitter.com $+ $crlf $+ $crlf
}
on *:sockread:twitter: {
  sockread %twitter
  if (<span id="follower_count" class="stats_count numeric"> isin %twitter) {
    set %followers $htmlfree(%twitter)
  }
  if (<span id="following_count" class="stats_count numeric"> isin %twitter) {
    set %following $htmlfree(%twitter)
  }
  if (<span id="update_count" class="stats_count numeric"> isin %twitter) {
    set %updates $htmlfree(%twitter)
  }
}
on *:sockclose:twitter: {
  msg $sock(twitter).mark has %followers followers, is following %following people, with %updates updates.
}
on *:TEXT:!Twitter*:#: {
  twit $$2
}

Comments

Sign in to comment.
MaxEvans   -  Dec 02, 2009

Yeah, I haven't had time to figure all of it out yet, dealing with moving and such. So, I would need a little help. =)

 Respond  
FordLawnmower   -  Dec 02, 2009

Using the API for this would be much easier and resource friendly. The API page is here -->> http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
And this allows for 150 uses per hour. There is a separate count for authenticated usage of the API as well, so authenticated requests to the API are not included in this number. I addition, REST API POST requests are not counted on any limit.
Limits:
Authenticated 150 per Userid
Unauthenticated 150 per Ipaddress
POST Requests(such as update, direct message, etc) Unlimited.

If you need any help with this MaxEvans, I already have aliases for almost all of Twitters REST API.

 Respond  
GrimReaper   -  Dec 02, 2009

The socket to get the info is incorrect.

alias twit {
  if (!$sock(twitterstats)) {
    sockopen twitterstats twitter.com 80
    sockmark twitterstats $chan $1
  }
}

on *:sockopen:twitterstats: {
  sockwrite -nt $sockname GET / $+ $gettok($sock(twitterstats).mark,2,32) HTTP/1.0
  sockwrite -nt $sockname Host: twitter.com $+ $crlf $+ $crlf
}
on *:sockread:twitterstats: {
  sockread %twitterstats
  if (<span id="follower_count" class="stats_count numeric"> isin %twitterstats) {
    set %twitterfollowers $htmlfree(%twitterstats)
  }
  if (<span id="following_count" class="stats_count numeric"> isin %twitterstats) {
    set %twitterfollowing $htmlfree(%twitterstats)
  }
  if (<span id="lists_count" class="stats_count numeric"> isin %twitterstats) {
    set %twitterlistscount $htmlfree(%twitterstats)
  }
  if (<span id="update_count" class="stat_count"> isin %twitterstats) {
    set %twitterupdates $remove($htmlfree(%twitterstats),Tweets)
  }
}
on *:sockclose:twitterstats: {
  msg $sock(twitterstats).mark has %twitterfollowers followers, following %twitterfollowing people, They are on %twitterlistscount lists and have sent %twitterupdates updates.
}
on *:TEXT:!TwitStats *:#: {
  twit $2-
}

alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | 

return %x }

Here is an updated one that I have done. I have also added the Lists that people are in as well.

Hope thats ok with everyone. :)

 Respond  
billythekid   -  Mar 15, 2009

I was using the API for an IRC updater but went the route of scraping/GET/POST sockets for the simple reason I was using up the 100 API allowance on busy days in IRC as everytime someone changed topic or did !quote or whatever was linked to the bot made a call. Then the n00bs say hey what's that do? They have a play around and before you know it you're APId out!

I agree the API is cleaner and add also it's a fair bit faster(perhaps obviously) it just wasn't handy for 'that' particular bot.

 Respond  
Hawkee   -  Mar 13, 2009

MaxEvans, you should look at the Twitter API and use that rather than scrape the site. It'll give you the data in a much cleaner format.

 Respond  
Firstmate   -  Mar 13, 2009

I made one of these a while back but never posted it. ha
One thing I had was a search option.
search.twitter.com
^^ socket to that. It's fairly simple getting the results too

Also you should check if the nick already put his twitter in your .txt

 Respond  
MaxEvans   -  Mar 12, 2009

I can't figure out the latest tweet addition. The "<li id" is unique for each tweet, and can't be put in lest it reads only one person's tweet. I did get it to show more than one tweet, however. It just cuts it off at some point, so it may read half of one tweet or something. If I'm missing something, let me know. And I'm working on that idea, Hawkee. I'll get it up soon. =]

 Respond  
Hawkee   -  Mar 12, 2009

Nice work. Now maybe there should be an option to look somebody up by their IRC handle based on the association in Twitter.txt. So rather than checking the entire list to find out somebody's Twitter URL I can just !Twitter -i somebodys_IRC_nick

 Respond  
Blitzjager   -  Mar 12, 2009

It'd be nice to see the most recent comment on someones page. ;)

And you should combine the 2 on text !twitters.
if (!$2) { play etc }
else { twit etc }

 Respond  
Jonesy44   -  Mar 12, 2009

Seems you got it ;)

 Respond  
MaxEvans   -  Mar 11, 2009

Funny thing is.. I had the same idea. Just didn't know how to do it. =]

 Respond  
Hawkee   -  Mar 11, 2009

Sounds good jonesy44, can't wait to see what you come up with

 Respond  
Jonesy44   -  Mar 11, 2009

Hawkee, stfu! You're releasing my script ideas before i can release the scripts!

 Respond  
Aucun50   -  Mar 11, 2009

DJTwittr you putting in your remotes right? If so then you yourself can't trigger it because it's a on text event not an on input event.

 Respond  
DJTwittr   -  Mar 11, 2009

this doesnt work for me... I added it to remotes... and it never even responds

 Respond  
MaxEvans   -  Mar 10, 2009

That's a great idea, It may take me a while, since I'm not advanced in scripting yet. But, if someone would like to help, I'd appreciate it. =]

 Respond  
Hawkee   -  Mar 09, 2009

Great! Now you might want to expand on this a bit by grabbing some stats on each user. You could use sockets to grab the number of follows, followers and updates for each user in the list. Maybe introduce "!Twitter nick" which will offer this information. Lots of neat functionality with the Twitter API.

 Respond  
MaxEvans   -  Mar 09, 2009

I agree, I changed it to just !Twitter. It is quite a bit to type the other way.

 Respond  
Hawkee   -  Mar 09, 2009

I'm glad to see some Twitter related snippets, hope to see many more! I just think the command should be a bit shorter, maybe just !Twitter instead of !Twitter Directory. That's a bit much to type.

 Respond  
MaxEvans   -  Mar 08, 2009

I'm going to add a limit for it soon. That should keep it from lagging too much.

 Respond  
Aucun50   -  Mar 08, 2009

This could get your bot lagged to no return.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.