<commit_before>import logging, os

from functools import partial
from channels import Channel
from slacker import Slacker
from slacker import Error as SlackError
from website.models import Team, SharedChannel
from django.shortcuts import get_object_or_404

logger = logging.getLogger('basicLogger')

def event(message):
    logger.debug("Processing event.")

    payload = message.content
    logger.debug(payload)

    event = payload['event']

    local_team = get_object_or_404(Team, team_id=payload['team_id'])
    local_team_interface = Slacker(local_team.app_access_token)

    if event['type'] != "message":
        logger.warning('Not sure what "{}" event is...'.format(event['type']))
    elif event.get('subtype') == 'bot_message':
        logger.info("Ignoring stuff by other bots...")
    elif event.get("subtype") == "channel_join":
        logger.info("Bot was added to channel {} on team {}".format(event['channel'], local_team.team_id))
        SharedChannel.objects.get_or_create(channel_id=event['channel'],
                                            local_team=local_team)
    elif event.get('user') == 'USLACKBOT':
        if "removed from" in event['text']:
            logger.info("Bot was removed from channel {} on team {}".format(event['channel'], local_team.team_id))
            left = SharedChannel.objects.get(channel_id=event['channel'],
                                             local_team=local_team)
            left.delete()
        else:
            logger.info("Ignoring slackbot updates")
            return
    else:
        user_info = local_team_interface.users.info(event['user']).body['user']<commit_msg>Fixing buggy AF channel removal logic...<commit_after>import logging, os, re

from functools import partial
from channels import Channel
from slacker import Slacker
from slacker import Error as SlackError
from website.models import Team, SharedChannel
from django.shortcuts import get_object_or_404

logger = logging.getLogger('basicLogger')

def event(message):
    logger.debug("Processing event.")

    payload = message.content
    logger.debug(payload)

    event = payload['event']

    local_team = get_object_or_404(Team, team_id=payload['team_id'])
    local_team_interface = Slacker(local_team.app_access_token)

    if event['type'] != "message":
        logger.warning('Not sure what "{}" event is...'.format(event['type']))
    elif event.get('subtype') == 'bot_message':
        logger.info("Ignoring stuff by other bots...")
    elif event.get("subtype") == "channel_join":
        logger.info("Bot was added to channel {} on team {}".format(event['channel'], local_team.team_id))
        SharedChannel.objects.get_or_create(channel_id=event['channel'],
                                            local_team=local_team)
    elif event.get('user') == 'USLACKBOT':
        if "You have been removed from" in event['text']:
            ch_name = re.findall(r'#(\w+)', event['text'])[0]
            ch_id = local_team_interface.channels.get_channel_id(ch_name)
            logger.info('Bot was removed from channel "{}" ({}) on team {}'.format(ch_name, ch_id, local_team.team_id))
            left = SharedChannel.objects.get(channel_id=ch_id,
                                             local_team=local_team)
            left.delete()
        else:
            logger.info("Ignoring slackbot updates")
            return
    else:
        user_info = local_team_interface.users.info(event['user']).body['user']
{'fraction_non_alphanumeric': 0.12316546762589928, 'fraction_numerical': 0.0037410071942446045, 'mean_word_length': 3.0046082949308754, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2179981', 'n_tokens_mistral': 989, 'n_tokens_neox': 960, 'n_words': 224}