def create_connection(addr, port, msg): sock = socket(AF_INET, SOCK_STREAM) con = Spin(sock) Client(con) con.connect_ex((addr, port)) xmap(con, CONNECT, setup, msg)
def create_connection(addr, port): sock = socket(AF_INET, SOCK_STREAM) spin = Spin(sock) Client(spin) xmap(spin, CONNECT, is_open, port) spin.connect_ex((addr, port)) return spin
def create_connection(addr, port): con = Spin() Client(con) xmap(con, CONNECT, on_connect, addr, port) xmap(con, CONNECT_ERR, on_connect_err, addr, port) xmap(con, CONNECT, lambda con: die()) xmap(con, CONNECT_ERR, lambda con, err: die()) con.connect_ex((addr, port))
def __init__(self, addr, port, user, nick, irccmd, channels=[]): con = Spin() self.con = con con.connect_ex((addr, int(port))) Client(con) xmap(con, CONNECT, self.on_connect) xmap(con, CONNECT_ERR, self.e_connect_err) self.misc = None self.addr = addr self.port = port self.user = user self.nick = nick self.irccmd = irccmd self.channels = channels
def connect(servaddr, port, nick, user, nick_passwd, adm_passwd, chan_list, plugmap): sock = socket(AF_INET, SOCK_STREAM) ip = gethostbyname(servaddr) server = Spin(sock) Client(server) def auto_join(server, *args): send_cmd(server, nick_passwd) for ind in chan_list: send_cmd(server, 'JOIN %s' % ind) @coroutine def get_myaddr(server, servaddr, nick, msg): server.nick = nick send_cmd(server, 'USERHOST %s' % nick) args = yield server, '302' _, _, ident = args user, myaddr = ident.split('@') server.myaddr = myaddr def update_nick(server, nick_x, user, host, nick_y): if server.nick == nick_x: server.nick = nick_y 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) xmap(server, CONNECT, handle_connect) xmap(server, CONNECT_ERR, lambda server, err: lose(server)) server.connect_ex((ip, port)) return server