Guest User

Untitled

a guest
Jun 27th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import irclib
  2. import urllib2
  3. import re
  4.  
  5. network = 'irc.redbrick.dcu.ie'
  6. port = 6667
  7. channel = '#lobby'
  8. nick = 'TinyURL'
  9. name = 'TinyURL'
  10. owner = 'lithium'
  11. apiurl = "http://tinyurl.com/api-create.php?url="
  12. irc = irclib.IRC()
  13. s = irc.server()
  14.  
  15. s.connect(network, port, nick, ircname=name)
  16. s.join(channel)
  17.  
  18. def handleTiny(connection, event):
  19.     if event.arguments()[0].lower().find('http') == 0:
  20.         line = event.arguments()[0]
  21.         if len(line) > 90:
  22.             u = re.match(r'http:\/\/([\w.]+\/?)\S*', line, re.M|re.I)
  23.             url = u.group()
  24.             tinyurl = urllib2.urlopen(apiurl + url).read()
  25.             s.privmsg(channel, tinyurl)
  26.  
  27. irc.add_global_handler('pubmsg', handleTiny)
  28.        
  29. irc.process_forever()
Add Comment
Please, Sign In to add comment