def connect(self): global ssl_enabled verbose("Calling on_start") for l in self.Listeners : wrap(l.on_start,self) prnt("== Connecting to remote server %s:%s..." % (self.server, self.port)) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.use_ssl and ssl_enabled: self.socket = ssl.wrap_socket(self.socket) # ca_certs="/etc/ssl/certs/ca-certificates.crt", # cert_reqs=ssl.CERT_REQUIRED) # Once I understand what's going wrong with the cert # verification, I'll uncomment these lines pass try: self.socket.connect((self.server, self.port)) pass except Exception as e : prnt("== Exception connecting to irc; retry in %d seconds: %s" % (self.reconnect_delay, e)) self.begin_reconnect() return prnt("== Connection successful.") self.reconnect_delay = RECONNECT_DELAY self.start_recv_loop() pass
def connect(self): global ssl_enabled verbose("Calling on_start") for l in self.Listeners: wrap(l.on_start, self) prnt("== Connecting to remote server %s:%s..." % (self.server, self.port)) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.use_ssl and ssl_enabled: self.socket = ssl.wrap_socket(self.socket) # ca_certs="/etc/ssl/certs/ca-certificates.crt", # cert_reqs=ssl.CERT_REQUIRED) # Once I understand what's going wrong with the cert # verification, I'll uncomment these lines pass try: self.socket.connect((self.server, self.port)) pass except Exception as e: prnt( "== Exception connecting to irc server, retrying in %d seconds: %s" % (self.reconnect_delay, e)) self.begin_reconnect() return prnt("== Connection successful.") self.reconnect_delay = RECONNECT_DELAY self.start_recv_loop() pass
def connect(self): verbose("Calling on_start") for l in self.Listeners : wrap(l.on_start,self) prnt("== Connecting to remote server %s:%s..." % (self.server, self.port)) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.socket.connect((self.server, self.port)) pass except Error as e : raise IrcError(e) prnt("== Connection successful.") self.start_recv_loop() pass
def process_command(self,command, prefix, params): if not(self.connected): self.connected = True verbose("Calling on_connect") for l in self.Listeners: wrap(l.on_connect,self) pass pass debug("Command:",command,"Prefix:",prefix,"Params",params) paramgroups = re.match(PARAMGRP, params).groups() paramlist = [] if not(paramgroups[0] == None): paramlist.extend(re.split(SPACE,paramgroups[0])[:-1]) pass if not(paramgroups[1] == None): paramlist.append(paramgroups[1]) pass debug("Parameters:",", ".join(str(p) for p in paramlist)) if prefix == None: server, nick, user, host = None, None, None, None sender = () pass else: server, nick, user, host = re.match(PREFIXGRP,prefix).groups() if server == None: sender = (nick, user, host) pass else: sender = (server,) pass pass verbose("Command:",command) if command.isdigit(): for l in self.Listeners: wrap(l.on_numeric_cmd, self, sender, int(command), paramlist) pass pass elif command.lower() == "privmsg": isact = privmsg.startswith(ircutil.ACTION) # either a channel OR personal message if re.match(NICK, paramlist[0]): for l in self.Listeners: wrap(l.on_priv_msg, self, sender, paramlist[1], isact) pass pass else: for l in self.Listeners: wrap(l.on_chan_msg, self, sender, paramlist[0], paramlist[1], isact) pass pass pass elif command.lower() == "mode": # either a channel OR user mode if re.match(NICK, paramlist[0]): if not(self.registered ): self.registered = True debug("Calling on_register") for l in self.Listeners: wrap(l.on_register, self) pass pass for l in self.Listeners: wrap(l.on_user_mode, self, sender, paramlist[1]) pass pass else: for l in self.Listeners: wrap(l.on_chan_mode, self, sender, paramlist[0], paramlist[1]) pass pass pass elif command.lower() == "notice": for l in self.Listeners: wrap(l.on_notice, self, sender, paramlist[0], paramlist[1]) pass pass elif command.lower() == "ping": for l in self.Listeners: wrap(l.on_ping, self, sender, paramlist[0]) pass pass elif command.lower() == "join": for l in self.Listeners: wrap(l.on_join, self, sender, paramlist[0]) pass pass else: raise IrcError("Unknown command: " + str(command)) pass
def process_command(self, command, prefix, params): if not (self.connected): self.connected = True verbose("Calling on_connect") for l in self.Listeners: wrap(l.on_connect, self) pass pass debug("Command:", command, "Prefix:", prefix, "Params", params) paramgroups = re.match(PARAMGRP, params).groups() paramlist = [] if not (paramgroups[0] == None): paramlist.extend(re.split(SPACE, paramgroups[0])[:-1]) pass if not (paramgroups[1] == None): paramlist.append(paramgroups[1]) pass if not (paramgroups[2] == None): paramlist.append(paramgroups[2]) pass debug("Parameters:", ", ".join(str(p) for p in paramlist)) if prefix == None: server, nick, user, host = None, None, None, None sender = () pass else: server, nick, user, host = re.match(PREFIXGRP, prefix).groups() if server == None: sender = (nick, user, host) pass else: sender = (server, ) pass pass verbose("Command:", command) if command.isdigit(): for l in self.Listeners: wrap(l.on_numeric_cmd, self, sender, int(command), paramlist) pass pass elif command.lower() == "privmsg": isact = ircutil.isaction(paramlist[1]) # either a channel OR personal message if re.match(NICK, paramlist[0]): for l in self.Listeners: wrap(l.on_priv_msg, self, sender, ircutil.unaction(paramlist[1]), isact) pass pass else: for l in self.Listeners: wrap(l.on_chan_msg, self, sender, paramlist[0], ircutil.unaction(paramlist[1]), isact) pass pass pass elif command.lower() == "mode": # either a channel OR user mode if re.match(NICK, paramlist[0]): if not (self.registered): self.registered = True debug("Calling on_register") for l in self.Listeners: wrap(l.on_register, self) pass pass for l in self.Listeners: wrap(l.on_user_mode, self, sender, paramlist[1]) pass pass else: for l in self.Listeners: wrap(l.on_chan_mode, self, sender, paramlist[0], paramlist[1]) pass pass pass elif command.lower() == "notice": for l in self.Listeners: wrap(l.on_notice, self, sender, paramlist[0], paramlist[1]) pass pass elif command.lower() == "ping": for l in self.Listeners: wrap(l.on_ping, self, sender, paramlist[0]) pass pass elif command.lower() == "join": for l in self.Listeners: wrap(l.on_join, self, sender, paramlist[0]) pass pass elif command.lower() == "part": message = "" if len(paramlist) > 1: message = paramlist[1] pass for l in self.Listeners: wrap(l.on_part, self, sender, paramlist[0], message) pass pass elif command.lower() == "quit": message = "" if len(paramlist) > 0: message = paramlist[0] pass for l in self.Listeners: wrap(l.on_quit, self, sender, message) pass pass elif command.lower() == "pong": self.last_pong = paramlist[1] pass elif command.lower() == "nick": if len(paramlist) > 0: message = paramlist[0] for l in self.Listeners: wrap(l.on_nick, self, sender, message) pass pass pass elif command.lower() == "topic": if len(paramlist) > 1: channel = paramlist[0] topic = paramlist[1] for l in self.Listeners: wrap(l.on_topic, self, sender, channel, topic) pass pass pass else: raise IrcError("Unknown command: " + str(command)) pass