<commit_before>from logging import debug, info
from slackclient import SlackClient
from src.settings import SLACK_TOKEN, SLACK_PROXIES, SLACK_BOT_ID
from src.utils.healthchecks import api_check, bot_check, dbaas_check, \
    persistence_check


class Bot(object):

    def __init__(self):
        self.slack_client = SlackClient(SLACK_TOKEN, SLACK_PROXIES)
        self.name = '<@{}>'.format(SLACK_BOT_ID)
        self.rtm_reconnect_url = None

    @property
    def my_channels(self):
        response = self.slack_client.api_call("channels.list")

        channels = []
        for channel in response['channels']:
            if channel['is_member']:
                channels.append(channel['id'])

        return channels

    def send_message_in_channel(self, message, channel):
        self.slack_client.api_call(
            "chat.postMessage", channel=channel, text=message, as_user=True
        )

    def send_message(self, message):
        for channel in self.my_channels:
            self.send_message_in_channel(message, channel)

    def receive_command(self):
        try:
            commands = self.slack_client.rtm_read()
        except Exception as e:
            if not self.rtm_reconnect_url:
                return e

            info('Trying to reconnect in {}'.format(self.rtm_reconnect_url))
            self.slack_client.server.connect_slack_websocket(
                self.rtm_reconnect_url
            )
            self.rtm_reconnect_url = None
            return self.receive_command()


        debug(commands)

        self.get_reconnect_url(commands)

        return commands

    def get_reconnect_url(self, commands):
        for command in commands:
            if 'type' not in command:
                continue

            if command['type'] != 'reconnect_url':
                continue

            self.rtm_reconnect_url = command['url']


    def get_direct_messages(self):
        commands = self.receive_command()
        if not commands:
            return None

        for command in commands:
            if not('type' in command and 'text' in command):
                debug('Content invalid in {}'.format(command))
                continue
<commit_msg>Return empty messages when do not have direct mentions<commit_after>from logging import debug, info
from slackclient import SlackClient
from src.settings import SLACK_TOKEN, SLACK_PROXIES, SLACK_BOT_ID
from src.utils.healthchecks import api_check, bot_check, dbaas_check, \
    persistence_check


class Bot(object):

    def __init__(self):
        self.slack_client = SlackClient(SLACK_TOKEN, SLACK_PROXIES)
        self.name = '<@{}>'.format(SLACK_BOT_ID)
        self.rtm_reconnect_url = None

    @property
    def my_channels(self):
        response = self.slack_client.api_call("channels.list")

        channels = []
        for channel in response['channels']:
            if channel['is_member']:
                channels.append(channel['id'])

        return channels

    def send_message_in_channel(self, message, channel):
        self.slack_client.api_call(
            "chat.postMessage", channel=channel, text=message, as_user=True
        )

    def send_message(self, message):
        for channel in self.my_channels:
            self.send_message_in_channel(message, channel)

    def receive_command(self):
        try:
            commands = self.slack_client.rtm_read()
        except Exception as e:
            if not self.rtm_reconnect_url:
                return e

            info('Trying to reconnect in {}'.format(self.rtm_reconnect_url))
            self.slack_client.server.connect_slack_websocket(
                self.rtm_reconnect_url
            )
            self.rtm_reconnect_url = None
            return self.receive_command()


        debug(commands)

        self.get_reconnect_url(commands)

        return commands

    def get_reconnect_url(self, commands):
        for command in commands:
            if 'type' not in command:
                continue

            if command['type'] != 'reconnect_url':
                continue

            self.rtm_reconnect_url = command['url']


    def get_direct_messages(self):
        commands = self.receive_command()
        if not commands:
            return []

        for command in commands:
            if not('type' in command and 'text' in command):
                debug('Content invalid in {}'.format(command))
                continue

{'fraction_non_alphanumeric': 0.08323959505061868, 'fraction_numerical': 0.0, 'mean_word_length': 2.21940622737147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3791102', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1228, 'n_words': 287}