예제 #1
0
파일: blockbot.py 프로젝트: xfix/BBot
    def privmsg(self, nick, data, channel):
        '''Check messages for spam'''
        self.msglist.insert(0, (nick, channel,
                                api.get_message(data), time.time()))

        if not api.check_if_super_user(data, config.superusers):
            # Check for spam strings
            ldata = data.lower()
            for each in self.findlist:
                if re.search(each, ldata):
                    self.kick(nick, channel, self.blacklistkickmsg)
                    return

            # Extract messages by this user
            user_msgs = []
            for msg in self.msglist:
                if msg[0] == nick:
                    user_msgs.append((nick, msg[1], msg[2], msg[3]))

            # Check for flooding
            if len(user_msgs) > 2 and self.get_mps(user_msgs) > self.mps_limit:
                self.kick(nick, channel, self.floodkickmsg)
                self.msglist.pop(0)

            # Check for repeats
            strings = []
            repeats = 0
            for msg in user_msgs:
                if msg[2] not in strings:
                    strings.append(msg[2])
                else:
                    repeats += 1
            if repeats > self.repeat_limit-1:
                self.kick(nick, channel, self.repeatkickmsg)
                self.msglist.pop(0)

            # Clear out old messages
            now = time.time()
            for msg in self.msglist:
                if now - msg[3] > self.storage_time:
                    self.msglist.remove(msg)

            # Check for highlights
            thread.start_new_thread(self.check_hilight, (nick, data, channel))
예제 #2
0
파일: factoids.py 프로젝트: aj00200/BBot
    def privmsg(self, nick, data, channel):
        if '#' not in channel:  # if message is a pm
            channel = nick
        ldata = data.lower()

        # Check if message is a command
        if self.command_start in data:
            cmd = data[data.find(self.command_start) + len(self.command_start):]
            cmd = cmd.lower()
            if ' ' in cmd:
                cmd = cmd[:cmd.find(' ')]

            # Superuser Commands
            if api.check_if_super_user(data):
                if ' > ' in data:
                    channel = data[data.find(' > ') + 3:]
                    data = data[:data.find(' > ')]

            # Normal Commands
            cmd = data[data.find(self.command_start) + self.cmd_len:]
            if ' | ' in cmd:
                nick = cmd[cmd.find(' | ') + 3:]
                cmd = cmd[:cmd.find(' | ')]
            self.query(cmd, nick, channel)

        # Check if I've been pinged
        if (' :%s: ' % config.nick.lower() in ldata) or (' :%s, ' % config.nick.lower() in ldata):
            msg = api.get_message(data).lower()
            q = msg[msg.find(config.nick.lower()) + len(config.nick.lower()) + 2:]
            self.query(q, nick, channel)

        # Answer basic questions
        ldata = ldata.replace('whats', 'what is')
        if re.search('(what|where|who) (is|was|are|am)', ldata):
            for word in self.stop_words:
                ldata = ldata.replace(word, ' ')
            for word in self.is_words:
                ldata = ldata.replace(word, ' is ')
            q = ldata[ldata.find(' is ') + 4:].strip('?')
            self.query(q, nick, channel)
예제 #3
0
파일: async.py 프로젝트: bbottheircbot/BBot
    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)
예제 #4
0
 def privmsg(self, nick, data, channel):
     if api.check_if_super_user(data, config.superusers):
         if ':?global ' in data:
             broadcast = data[data.find('global ')+8:]
             for each in config.autojoin:
                 self.msg(each, broadcast)
예제 #5
0
파일: async.py 프로젝트: aj00200/BBot
    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)