
Untitled
By: a guest on
Jun 27th, 2012 | syntax:
Python | size: 0.68 KB | hits: 36 | expires: Never
import irclib
import urllib2
import re
network = 'irc.redbrick.dcu.ie'
port = 6667
channel = '#lobby'
nick = 'TinyURL'
name = 'TinyURL'
owner = 'lithium'
apiurl = "http://tinyurl.com/api-create.php?url="
irc = irclib.IRC()
s = irc.server()
s.connect(network, port, nick, ircname=name)
s.join(channel)
def handleTiny(connection, event):
if event.arguments()[0].lower().find('http') == 0:
line = event.arguments()[0]
if len(line) > 90:
u = re.match(r'http:\/\/([\w.]+\/?)\S*', line, re.M|re.I)
url = u.group()
tinyurl = urllib2.urlopen(apiurl + url).read()
s.privmsg(channel, tinyurl)
irc.add_global_handler('pubmsg', handleTiny)
irc.process_forever()