Bit.ly URL Shortener

By MartyniP on Nov 13, 2010

This code can be easliy applied to a bot with no editing of the code.
Bot command: !bitly http://site.tld
Client command /bitly http://site.tld

; Created by Martyn Watton
; Copyright MartyniP, Martyni Productions and www.nartynip.co.uk
; Technoid IRC Network www.technoid-irc.net
alias bitlylogin {
  ; API INFO MUST BE SET BELOW!
  ; GET API INFO FROM http://bit.ly/a/your_api_key/
  set %bitly.login YOURBITLYLOGIN
  set %bitly.api YOURBITLYAPIKEY
  ; Set to 1 if your running it on a bot with a command such as !bitly link, As it will msg the channel it was posted in
  set %bot 0
}
; Default bot command, you can remove this for client use, but it will not be triggered if %bitly.bot is 0
on *:TEXT:!bitly *:#: {
if (%bitly.bot == 1) {
/bitly $2
}
}
; Do not edit beond here!
on *:SockOpen:bitly: {
  bitlylogin
  sockwrite -nt bitly GET $+(/v3/shorten?login=,%bitly.login,&apiKey=,%bitly.api,&longUrl=,%bitly.url,&format=txt) HTTP/1.1
  sockwrite -n bitly Host: api.bit.ly
  sockwrite -n bitly $crlf
}
on *:SockRead:bitly: {
  var %bitly.read
  sockRead  %bitly.read
  if (http://* iswm %bitly.read) {
    echo 9 -ta Shortened URL: %bitly.read
    if (%bitly.bot == 1) {
      /msg %bitly.chan Shorened URL: %bitly.read
    }
    unset %bitly.*
  }
}
alias bitly {
  sockClose bitly
  %bitly.url = $1-
  %bitly.chan = $chan
  sockOpen bitly api.bit.ly 80
}

Comments

Sign in to comment.
Sorasyn   -  Nov 13, 2010

For information requests like

  set %bitly.login YOURBITLYLOGIN
  set %bitly.api YOURBITLYAPIKEY
  set %bot 0

you could use an on load with $input() instead of editing the code

on *:LOAD:{ bitlylogin }
 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.