Example #1
0
    def get_notice(self, nick, channel, data):
        # Add notice to the message lsit
        self.msglist.insert(0, (nick, channel, api.get_message(data), time.time()))

        # Check notice for spam strings
        for each in self.findlist:
            if re.search(each, data):
                self.kick(nick, channel, 'You have matched a spam string and have been banned. If this was a mistake, please contact a channel op to get unbanned')
                self.mode(nick, channel, '+b')
Example #2
0
File: proxy.py Project: xfix/BBot
 def privmsg(self, nick, data, channel):
     if channel == self.chan1 and self.__address__ == self.net1:
         self.to = self.net2
     elif channel == self.chan2 and self.__address__ == self.net2:
         self.to = self.net1
     else:
         self.to = self.net1
     try:
         api.backend.connections[self.to].push('PRIVMSG %s :<%s> %s\r\n' %
                                    (channel, nick, api.get_message(data)))
     except Exception:
         pass
Example #3
0
    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))
Example #4
0
def reaction_added_event(request):
    parsed = request.json
    team_id = parsed['team_id']
    event = parsed['event']
    if event['reaction'] in ('ididit', 'udidit'):
        item = event['item']
        event_user_id = event['user']
        if item['type'] == 'message':
            channel = item['channel']
            msg_ts = item['ts']
            msg_resp = get_message(team_id, channel, msg_ts)
            msg = msg_resp['messages'][0]
            msg_team_id, msg_user_id, text = msg['team'], msg['user'], msg[
                'text']
            if event['reaction'] == 'ididit':
                reflect(msg_team_id, msg_user_id, text)
            elif event['reaction'] == 'udidit':
                reflect(msg_team_id, event_user_id, text)
    return "Ok"
Example #5
0
    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)
Example #6
0
 def privmsg(self, nick, data, channel):
     data = api.get_message(data)
     if re.search('\[\[.*\]\]', data):
         word = data[data.find('[[') + 2:data.find(']]')]
         self.msg(channel, self.wiki_url % word)
Example #7
0
    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)
Example #8
0
 def test_get_message(self):
     '''Test if the get_message function is working'''
     self.assertEqual(api.get_message(':a!b@c PRIVMSG #d :msg'), 'msg')
Example #9
0
    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)
Example #10
0
File: wikibot.py Project: xfix/BBot
 def privmsg(self, nick, data, channel):
     data = api.get_message(data)
     if re.search("\[\[.*\]\]", data):
         word = data[data.find("[[") + 2 : data.find("]]")]
         self.msg(channel, self.wiki_url % word)