All pastes #707324 Raw Edit

Unbenannt

public python v1 · immutable
#707324 ·published 2007-09-22 20:13 UTC
rendered paste body
import sys, os, socket, asyncore, asynchat, time, thread, stringclass Bot(asynchat.async_chat):         def __init__(self, nick, uid, name, channels):            asynchat.async_chat.__init__(self)            self.buffer = ''            self.set_terminator('\n')            self.nick = nick            self.msgstack = []            self.uid = uid            self.name = name            self.channels = channels         def write(self, args, text=None):            if text is not None:               self.push(' '.join(args) + ' :' + text + '\r\n')            else: self.push(' '.join(args) + '\r\n')         def handle_connect(self):            self.write(('NICK', self.nick))            self.write(('USER', self.uid, '+iw', self.nick), self.name)            for channel in self.channels:                self.write(('JOIN',channel))         def collect_incoming_data(self, data):            self.buffer += data         def found_terminator(self):            line = self.buffer            self.buffer = ''                        if line.startswith(':'):               origin, line = line[1:].split(' ', 1)            else: origin = None            if ' :' in line:               args, text = line.split(' :', 1)            else: args, text = line, ''            args = args.split()                        print origin            print args            if text:                text = text.replace('\x01','')                split_text = string.split(text)                if split_text[0]=='PING':                    self.write(('PONG', split_text[1]))                    print 'PING PONG'                print text                if text[0]=='.' and args[0]=='PRIVMSG':                    print text[1:5]                    if text[1:5]=='help':                        self.write(('PRIVMSG',args[1]),'avaible commands: .help')         def todo(self, args, *text):            command = ' '.join(args)            if text:                command = '%s : %s' % (command, ' '.join(text))            command = re.sub(r"\n", "", command)            command = re.sub(r"\r", "", command)            self.push(command + CRLF)         def run(self, host, port):            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)            time.sleep(0.5)            self.connect((host, port))            time.sleep(0.5)            thread.start_new_thread( asyncore.loop, ())            shouldrun = True            while shouldrun:                myinput = raw_input('>')                if myinput:                    if myinput=='quit':                        break                    self.write(('PRIVMSG','#zeq2team'),myinput)            self.close()            del asyncore.looptest = Bot('zeq2bot','zeq2bot', 'zeq2bot', ['#zeq2team turtleblast','#zeq2'])test.run('irc.enterthegame.com', 6668 )