Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: Python  |  size: 0.68 KB  |  hits: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()