Пример #1
0
    def __init__(self):
        self.admins = []
        self.channels = []
        self.nickserv_pass = None
        self.trigger = None
        self.parser = None

        settings = json.loads(open('settings.json', 'r').read())

        self.server        = settings.get('server',        None    )
        self.port          = settings.get('port',          6667    )
        self.channels      = settings.get('channels',      [ ]     )
        self.nickname      = settings.get('nickname',      'MooBot')
        self.nickserv_pass = settings.get('nickserv_pass', None    )
        self.trigger       = settings.get('trigger',       'moobot').lower()
        self.admins        = settings.get('admins',        [ ]     )

        try:
            self.parser = commands.CommandParser(self)
        except:
            self.error('CommandParser failed to load')

        IRCClient.__init__(self)

        if self.nickserv_pass: self.PRIVMSG('NickServ', 'identify ' + self.nickserv_pass)

        for c in self.channels:
            self.JOIN(c)
Пример #2
0
    def recv_WHOWAS(self, args):
        if self.parser:
            try:
                self.parser.response_whowas(args)
            except:
                self.error('Exception raised when processing whowas response')

        IRCClient.recv_WHOWAS(self, args)
Пример #3
0
    def recv_PRIVMSG(self, args):
        IRCClient.recv_PRIVMSG(self, args)

        command = args[3][1:].split(None, 1)
        carg = command[1].strip() if len(command) == 2 else ''
        try:
            command = command[0].lower()
        except:
            command = ''

        regex = r'^!({0}\.)?(.*?)$'.format(self.trigger)
        match = re.search(regex, command)

        if not match: return

        command = match.group(2)


        sender  = args[0][1:].split('!', 1)[0]
        channel = args[2] if args[2] != self.nickname else sender

        # admin commands

        if sender in self.admins:
            cmd = {
                'quit':   self.cmd_quit,
                'reload': self.cmd_reload
            }.get(command, False)

            if cmd:
                cmd(sender, channel, carg, args)
                return

        # dynamically loaded commands

        if self.parser:
            try:
                if self.parser.parseMessage(command, sender, channel, carg, args): return
            except:
                self.error('Exception raised when processing command: ' + args[3][1:])
                self.PRIVMSG(sender, 'Exception raised when processing command: {0} | {1}'.format(sys.exc_info()[0], sys.exc_info()[1]))
                return