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.
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
}
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.
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. :)
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.
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. =]
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.