def __parse_commands(self, bot, line): # '[":hostname(sender)","PRIVMSG","reciever(#channel or nick)",":*",*]' try: nick, host = parse_hostmask(line[0]) if self.block.check(line[0]): return # Ignore messages from blocked users commandstr = line[3].lstrip(':') if commandstr in list(self.__commands.keys()): cmd = self.__commands[commandstr] if hasattr(cmd, 'alias'): logger.info('Alias command %s => %s', commandstr, cmd.alias) if cmd.alias not in list(self.__commands.keys()): raise CommandError('Invalid Alias') cmd = self.__commands[cmd.alias] if hasattr(cmd, 'disabled') and cmd.disabled is True: logger.debug('%s has been disabled', cmd.command) return else: cmd(self, {'nick': nick, 'host': host}, line) except CommandError as e: logger.exception('CommandError', exc_info=True) self.irc_notice(nick, e.__str__()) except Exception as e: logger.exception('Error processing commands\n%s', line, exc_info=True) self.irc_notice(nick, 'There was an error processing that command') if self._debugvar >= 2: raise
def test_hostname(self): nick, mask = parse_hostmask(':KFDM!~paul@purple') self.assertEqual(nick, 'KFDM') self.assertEqual(mask, '~paul@purple')
def test_invalid_hostname(self): with self.assertRaises(IndexError): parse_hostmask('foo')
def voice(bot,line): nick,host = parse_hostmask(line[0]) voicelist = bot.settings.get('VoicePlugin::list',[]) for voice in voicelist: if host == voice: bot.irc_mode('#japanese','+v %s'%nick)
def hostmask(self): # This should only be run for PRIVMSG/NOTICE but for now # I'll leave it without extra checks return parse_hostmask(self._parts[0])
def dest(self): if self._parts[2][0:1] == '#': return self._parts[2] else: nick, _ = parse_hostmask(self._parts[0]) return nick