def handle_connect(self, irc, client): SockWriter(client) SockReader(client) Terminator(client, delim=b'\r\n') SockWriter(irc) SockReader(irc) Terminator(irc, delim=b'\r\n') irc.add_map(Terminator.FOUND, self.handle_found) client.add_map(Terminator.FOUND, self.handle_found) irc.arrow = client client.arrow = irc print('Client Connected', irc.getpeername()) print('Connection to %s:%s stablished.' % irc.getpeername())
def on_connect(self, con): area = self.create_area(self.addr) area.bind('<Destroy>', lambda event: send_cmd(con, 'QUIT :vy rules!'), add=True) Stdin(con) Stdout(con) Terminator(con) Irc(con) self.misc = Misc(con) xmap(con, CLOSE, lambda con, err: lose(con)) xmap(con, '*JOIN', self.create_channel) xmap( con, Terminator.FOUND, lambda con, data: area.append('%s\n' % data.decode(self.encoding))) xmap(con, 'PMSG', self.e_pmsg) xmap(con, '376', lambda con, *args: send_cmd(con, self.irccmd)) xmap(con, '376', self.auto_join) xmap( con, 'PING', lambda con, prefix, servaddr: send_cmd(con, 'PONG :%s' % servaddr)) send_cmd(con, 'NICK %s' % self.nick) send_cmd(con, 'USER %s' % self.user)
def create_process(self, args): from os import environ, setsid self.child = Popen(args, shell=0, stdout=PIPE, stdin=PIPE, preexec_fn=setsid, stderr=STDOUT, env=environ) self.stdout = Device(self.child.stdout) self.stdin = Device(self.child.stdin) Stdout(self.stdout) Terminator(self.stdout, delim='\n') Stdin(self.stdin) event.install(self.stdout) xmap(self.stdout, LOAD, lambda con, data: sys.stdout.write(data)) xmap(self.stdout, 'LINE', self.handle_line) xmap(self.stdout, 'DELETED_BREAKPOINT', self.handle_deleted_breakpoint) xmap(self.stdout, 'BREAKPOINT', self.handle_breakpoint) xmap(self.stdin, CLOSE, lambda dev, err: lose(dev)) xmap(self.stdout, CLOSE, lambda dev, err: lose(dev))
def handle_connect(server): Stdin(server) Stdout(server) Terminator(server) Irc(server) CTCP(server) Misc(server) adm.install(server) xmap( server, 'PING', lambda server, prefix, servaddr: send_cmd( server, 'PONG :%s' % servaddr)) xmap(server, CLOSE, lambda server, err: lose(server)) logcon(server) xmap(server, '376', auto_join) xmap(server, '376', get_myaddr) xmap(server, 'NICK', update_nick) plugmap(server) server.servaddr = servaddr server.port = port server.nick = nick server.user = user server.chan_list = chan_list server.nick_passwd = nick_passwd server.adm_passwd = adm_passwd server.plugmap = plugmap send_cmd(server, 'NICK %s' % nick) send_cmd(server, 'USER %s' % user)
def install_handles(self, device): Terminator(device, delim=b'\n') regstr0 = '\> (.+)\(([0-9]+)\).+' RegexEvent(device, regstr0, 'LINE', self.encoding) xmap(device, 'LINE', self.handle_line)
def handle_accept(self, server, client): Terminator(client, delim=b'\r\n') client.add_map(CLOSE, lambda client, err: self.pool.remove(client)) client.dump(b'Type a nick.\r\nNick:') client.nick, = yield client, Terminator.FOUND client.add_map(Terminator.FOUND, self.echo_msg) self.pool.append(client)
def install_handles(self, device): Terminator(device, delim=b'\n') regstr0 = 'break in (.+):([0-9]+)' RegexEvent(device, regstr0, 'LINE', self.encoding) xmap(device, 'LINE', self.handle_line) # Should be case insensitive. regstr1 = 'Break on .+ in (.+):([0-9]+)' RegexEvent(device, regstr1, 'LINE', self.encoding) xmap(device, 'LINE', self.handle_line)
def handle_accept(self, server, client): SockWriter(client) SockReader(client) Terminator(client, delim=b'\r\n') parser = CalcParser(client) client.add_map('add', self.on_add) client.add_map('sub', self.on_sub) client.add_map('mul', self.on_mul) client.add_map('div', self.on_div) client.add_map((parser.handle_found, ValueError), self.on_error) client.add_map(CLOSE, self.handle_close)
def handle_accept(self, server, client): Stdin(client) Stdout(client) Terminator(client, delim='\r\n') parser = CalcParser(client) xmap(client, 'add', self.on_add) xmap(client, 'sub', self.on_sub) xmap(client, 'mul', self.on_mul) xmap(client, 'div', self.on_div) xmap(client, (parser.handle_found, ValueError), self.on_error) xmap(client, CLOSE, self.handle_close)
def send_auth(con, nick, user, cmd, delay): SockWriter(con) SockReader(con) Terminator(con) Irc(con) logcon(con) def do_job(ssock, *args): for ind in cmd: send_cmd(ssock, ind) sleep(delay) con.add_map('376', do_job) con.add_map( 'PING', lambda con, prefix, servaddr: send_cmd(con, 'PONG :%s' % servaddr)) con.add_map(CLOSE, lambda con, err: lose(con)) send_cmd(con, 'NICK %s' % nick) send_cmd(con, 'USER %s' % user)
def setup(con): SockWriter(con) SockReader(con) Terminator(con) Irc(con) CTCP(con) con.add_map( 'PING', lambda con, prefix, servaddr: send_cmd(con, 'PONG :%s' % servaddr)) con.add_map('376', lambda con, *args: send_cmd(con, 'JOIN #ameliabot')) con.add_map('PRIVMSG', send_file) con.add_map('DCC SEND', check_file_existence) con.add_map('376', get_myaddr) con.add_map(CLOSE, lambda con, err: lose(con)) logcon(con) send_cmd(con, 'NICK %s' % NICK) send_cmd(con, 'USER %s' % USER)
def send_auth(self, con): # It is what we use to send data. send_msg function uses # ssock.dump function to dump commands. SockWriter(con) SockReader(con) # This protocol spawns FOUND whenever it finds \r\n. Terminator(con) Irc(con) con.add_map(CLOSE, lambda con, err: lose(con)) # Now, it basically means: when it '376' irc command is # issued by the server then calls self.auto_join. # We use auto_join to send the sequence of JOIN # commands in order to join channels. con.add_map('376', self.auto_join) # Below the remaining stuff follows the same pattern. con.add_map('JOIN', self.on_join) con.add_map('PING', self.on_ping) con.add_map('PART', self.on_part) con.add_map('376', self.on_376) con.add_map('NOTICE', self.on_notice) con.add_map('PRIVMSG', self.on_privmsg) con.add_map('332', self.on_332) con.add_map('001', self.on_001) con.add_map('001', self.on_002) con.add_map('003', self.on_003) con.add_map('004', self.on_004) con.add_map('333', self.on_333) con.add_map('353', self.on_353) con.add_map('366', self.on_366) con.add_map('474', self.on_474) con.add_map('302', self.on_302) send_cmd(con, 'NICK %s' % self.nick) send_cmd(con, 'USER %s' % self.user) send_msg(con, 'nickserv', 'identify %s' % self.password)
def handle_accept(self, server, client): Stdin(client) Stdout(client) Terminator(client, delim='\r\n') xmap(client, Terminator.FOUND, self.handle_found) xmap(client, CLOSE, self.down_connection) irc = Spin() Client(irc) Stdin(irc) Stdout(irc) Shrug(irc, delim='\r\n') xmap(irc, Terminator.FOUND, self.handle_found) xmap(irc, CONNECT, self.handle_connect) xmap(irc, CONNECT_ERR, self.down_connection) xmap(irc, CLOSE, self.down_connection) irc.arrow = client client.arrow = irc irc.connect_ex((self.irc_address, self.irc_port))
def handle_connect(self, client): Terminator(client) client.add_map(Terminator.FOUND, self.handle_found)