def test_get_ident(self): '''Test if the get_ident function is working''' self.assertEqual(api.get_ident(':a!ident@c PRIVMSG #d :e'), 'ident')
def found_terminator(self): data = self.get_data().decode('utf8') # Check if we should ignore this message if re.search(config.ignore, data.lower()): return self.output('R%s' % data) # Take an accion based on the command command = data.split(' ', 2)[1] if data[:4] == 'PING': self.push('PONG %s\r\n' % data[5:]) elif command == 'PRIVMSG': nick = data[1:data.find('!')] channel = data[data.find(' PRIVMSG ')+9:data.find(' :')] for module in self.modules: self.modules[module].privmsg(nick, data, channel) # Command Hooks if channel == config.nick: channel = nick if ' :%s' % config.cmd_char in data: prm = None msg = api.get_message(data) cmd = msg[msg.find(config.cmd_char)+1:] user = User(nick) user.ident = api.get_ident(data) user.host = api.get_host(data) if ' ' in cmd: prm = cmd[cmd.find(' ')+1:] cmd = cmd[:cmd.find(' ')] if cmd in api.hooks[self.__address__]: api.hooks[self.__address__][cmd](user, channel, prm) # Superuser Hooks if api.check_if_super_user(data): if cmd in api.su_hooks[self.__address__]: api.su_hooks[self.__address__][cmd](user, channel, prm) elif command == 'NOTICE': nick = data[1:data.find('!')] channel = data[data.find(' NOTICE ')+8:data.find(' :')] print('channel: "%s"' % channel) for module in self.modules: self.modules[module].get_notice(nick, data, channel) elif command == 'JOIN': nick = data.split('!')[0][1:] if nick.find('#') == -1: channel = data[data.find(' :#')+2:] host = data[data.find('@')+1:data.find(' JOIN ')] user1 = data[data.find('!'):data.find('@')] user = user1.replace("!", "") for module in self.modules: self.modules[module].get_join(nick, user, host, channel) elif command == 'MODE': nick = api.get_nick(data) channel = data[data.find(' MODE ')+6:] mode = channel[channel.find(' ')+1:] channel = channel[:channel.find(' ')] for hook in api.mode_hooks[self.__address__]: hook(nick, channel, mode) elif re.search('[0-9]+ *' + config.nick, data): code = data.split()[1] for module in self.modules: self.modules[module].get_raw('CODE', (code, data)) if code == '001': if bbot.api.get_config_bool('main', 'use-services'): self.push('PRIVMSG NickServ :IDENTIFY %s %s\r\n' % (config.username, config.password)) time.sleep(config.sleep_after_id) for channel in config.autojoin: self.push('JOIN %s\r\n' % channel)
def found_terminator(self): data = self.get_data().decode("utf8") # Check if we should ignore this message if re.search(config.ignore, data.lower()): return self.output("R%s" % data) # Take an accion based on the command command = data.split(" ", 2)[1] if data[:4] == "PING": self.push("PONG %s\r\n" % data[5:]) elif command == "PRIVMSG": nick = data[1 : data.find("!")] channel = data[data.find(" PRIVMSG ") + 9 : data.find(" :")] for module in self.modules: self.modules[module].privmsg(nick, data, channel) # Command Hooks if channel == config.nick: channel = nick if " :%s" % config.cmd_char in data: prm = None msg = api.get_message(data) cmd = msg[msg.find(config.cmd_char) + 1 :] user = User(nick) user.ident = api.get_ident(data) user.host = api.get_host(data) if " " in cmd: prm = cmd[cmd.find(" ") + 1 :] cmd = cmd[: cmd.find(" ")] if cmd in api.hooks[self.__address__]: api.hooks[self.__address__][cmd](user, channel, prm) # Superuser Hooks if api.check_if_super_user(data): if cmd in api.su_hooks[self.__address__]: api.su_hooks[self.__address__][cmd](user, channel, prm) elif command == "NOTICE": nick = data[1 : data.find("!")] channel = data[data.find(" NOTICE ") + 8 : data.find(" :")] for module in self.modules: self.modules[module].get_notice(nick, data, channel) elif command == "JOIN": nick = data.split("!")[0][1:] if nick.find("#") == -1: channel = data[data.find("#") :] host = data[data.find("@") + 1 : data.find(" JOIN ")] user1 = data[data.find("!") : data.find("@")] user = user1.replace("!", "") for module in self.modules: self.modules[module].get_join(nick, user, host, channel) elif command == "MODE": nick = api.get_nick(data) channel = data[data.find(" MODE ") + 6 :] mode = channel[channel.find(" ") + 1 :] channel = channel[: channel.find(" ")] for hook in api.mode_hooks[self.__address__]: hook(nick, channel, mode) elif re.search("[0-9]+ *" + config.nick, data): code = data.split()[1] for module in self.modules: self.modules[module].get_raw("CODE", (code, data)) if code == "001": if bbot.api.get_config_bool("main", "use-services"): self.push("PRIVMSG NickServ :IDENTIFY %s %s\r\n" % (config.username, config.password)) time.sleep(config.sleep_after_id) for channel in config.autojoin: self.push("JOIN %s\r\n" % channel)