User:Lost Labyrinth/rcbot.py

server = 'irc.freenode.net' port = 6667 nickname = 'BawtRC' channels = ['##AnvilBot'] import re regexps = [re.compile(r':.*? PRIVMSG (?P .*) :\x0314\[\[\x0307(?P .*?)\x0314\]\]\x034 (?P .*?)\x0310 \x0302http:\/\/.*?\/w\/index\.php\?title=.*?&diff=(?P [0-9]*)&oldid=(?P [0-9]*)(&rcid=(?P [0-9]*))?\x03 \x035\*\x03 \x0303(?P .*?)\x03 \x035\*\x03 \(\x02?(?P [+-][0-9]*)\x02?\) \x0310(?P .*)\x03\r\n'), re.compile(r':.*? PRIVMSG (?P .*) :\x0314\[\[\x0307(?P .*?)\x0314\]\]\x034 (?P .*?N)\x0310 \x0302http:\/\/.*?\/w\/index\.php\?title=.*?&rcid=(?P [0-9]*)\x03 \x035\*\x03 \x0303(?P .*?)\x03 \x035\*\x03 \(\x02?(?P [+-][0-9]*)\x02?\) \x0310(?P .*)\x03\r\n'), re.compile(r':.*? PRIVMSG (?P .*) :\x0314\[\[\x0307(?P .*?)\x0314\]\]\x034 (?P .*?N)\x0310 \x0302http:\/\/.*?\/wiki/.*?\x03 \x035\*\x03 \x0303(?P .*?)\x03 \x035\*\x03 \(\x02?(?P [+-][0-9]*)\x02?\) \x0310(?P .*)\x03\r\n'), re.compile(r':.*? PRIVMSG (?P .*) :\x0314\[\[\x0307(?P .*?)\x0314\]\]\x034 (?P .*?)\x0310 \x0302\x03 \x035\*\x03 \x0303(?P .*?)\x03 \x035\*\x03 \x0310(?P .*)\x03\r\n')] import socket, random def rcbot: rc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) rc.connect((str(server), int(port))) rc.recv(4096) def identify: rand = str(random.randint(120, 9999)) nick = '%s%s' %(nickname[0:9-len(rand)], rand) rc.send('NICK %s\r\n' %nick) rc.send('USER %s %s %s :%s\r\n' %(nick, nick, nick, nick)) for channel in channels: if not str(channel)[0] in '&#!+': channel = '#%s' %channel rc.send('JOIN %s\r\n' %channel) return nick nick = identify while True: try: d = rc.recv(4096) if 'PING' in d:				rc.send('PONG ' + d.split[1] + '\r\n') elif d.endswith('433 * %s :Nickname is already in use.\r\n' %nick): nick = identify elif d == '': try: rc.send('QUIT\r\n') except socket.error: pass rcbot return d = d.decode('utf-8', 'replace') for r in regexps: m = r.match(d) if m:					data = m.groupdict print data break except KeyboardInterrupt: rc.send('QUIT\r\n') return if __name__ == '__main__': rcbot
 * 1) IRC CONFIGURATION ########