<commit_before>import time

import os
from slackclient import SlackClient

from parrots import exchange
from models import exchange_model

from util import parse_slack_output, handle_error, parrot_says

# Constant variables
BOT_NAME = "parrot-bot"

sc = SlackClient(os.environ["SLACK_API_TOKEN"])
        
models = [ exchange_model ]
parrots = [exchange.ExchangeParrot()]
parrot_cage = {}
for parrot in parrots:
    parrot_cage[parrot.NAME] = parrot.generate_actor()

if __name__ == "__main__":
    READ_WEBSOCKET_DELAY = 1
    if sc.rtm_connect():
        print("Parrot-Bot connected and running!")
        while True:
            command, channel = parse_slack_output(sc.rtm_read())
            success = 0 # if all model failed, command is not valid
            for model in models:
                if model(command):
                    result = parrot_cage[model(command)](command)
                    parrot_says(result, channel, sc)
                    success += 1
            if command and success == 0: # if command is '', handle_error wouldn't be executed
                handle_error(sc)
            time.sleep(READ_WEBSOCKET_DELAY)
    else:
        print("Connection failed. Invalid Slack token or bot ID")<commit_msg>add response function for testing purpose<commit_after>import time

import os
from slackclient import SlackClient

from parrots import exchange
from models import exchange_model

from util import parse_slack_output, handle_error, parrot_says

# Constant variables
BOT_NAME = "parrot-bot"

sc = SlackClient(os.environ["SLACK_API_TOKEN"])
        
models = [ exchange_model ]
parrots = [exchange.ExchangeParrot()]
parrot_cage = {}
for parrot in parrots:
    parrot_cage[parrot.NAME] = parrot.generate_actor()


def response(command):
    for model in models:
        if model(command):
            return parrot_cage[model(command)](command)
    return None


if __name__ == "__main__":
    READ_WEBSOCKET_DELAY = 1
    if sc.rtm_connect():
        print("Parrot-Bot connected and running!")
        while True:
            command, channel = parse_slack_output(sc.rtm_read())
            success = 0 # if all model failed, command is not valid
            if command:
                result = response(command)
                if result:
                    parrot_says(result, channel, sc)
                else:
                    handle_error(sc)  # if command is '', handle_error wouldn't be executed

            time.sleep(READ_WEBSOCKET_DELAY)
    else:
        print("Connection failed. Invalid Slack token or bot ID")
{'fraction_non_alphanumeric': 0.08014073494917905, 'fraction_numerical': 0.0023455824863174357, 'mean_word_length': 2.6609442060085837, 'pattern_counts': {'":': 2, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3116890', 'n_tokens_mistral': 762, 'n_tokens_neox': 734, 'n_words': 210}