<commit_before># -*- coding: utf-8 -*-

import random
from slackbot import SlackBot
from data.poketext import pokedex, templates, alternative_desc
from argparse import ArgumentParser
import yaml
from functools import partial
from wolfram import answers
import string
import re

def pikachu(client, event, wolfram_appid=None, bingid=None):
    # Note that all messages get sent here, even if they aren't addressing the bot

    text = event.get('text')
    for pnc in u"“”" + string.punctuation:
        text = text.replace(pnc, ' ')
    words = [word.lower().capitalize() for word in text.split() if len(word) > 1]

    _reactions(client, event, words)

    cmd_response = _commands(client, event, words)

    if cmd_response:
        return cmd_response

    if 'Pikachu' in words and not event.get('speaking_to_me'):
        event['text_query'] = event.get('text_query', '').replace('Pikachu', ' ').replace('pikachu', ' ')
        event['speaking_to_me'] = True

    if event.get('speaking_to_me'):
        # You're talking to me, you want real answers
        return answers(client, event, wolfram_appid, bingid)

    pokemon = list(set(words).intersection(pokedex.keys()))

    if len(pokemon) == 0 and len(set(words).intersection([u'Pokemon'])) == 0:
        # You didn't mention a pokemon or the word "pokemon" and you're not speaking to me
        return None

    return _poke_quote(pokemon)


def _commands(client, event, words):

    text = event.get('text')

    if text.lower() == 'standup!':
        return """Hey, <!channel> , it's time for our :slack: Standup! Respond with:
       I am working on OPTI-XXXX and am {[on track with X days left|facing some issues but am on it|will be delayed]}
Optionally followed by:
       I had to stop working on OPTI-XXXX due to {unforeseen reason here}
       I completed my work on OPTI-XXXX
Who wants to go first?"""

    tickets = re.findall("(OPTI-\d+)", text)
    if tickets:
        links = [" <https://nanigans.atlassian.net/browse/{ticket}|{ticket}> ".format(ticket=ticket) for ticket in tickets]
        message = "Great Job on " + ", ".join(links) + "!" + "\n" + "Who's up next?"
        print "Sending" + message + " to: " + str(event['channel'])
        client.api_call("chat.postMessage", text=message, channel=event['channel'], as_user=True)
        return ""

    # if text.lower().startswith('interns'): # and event.get('channel') == 'C054GJYFE':
    #     responses = ['Pinging', 'Announcement for', 'I think that was meant for']
    #     return random.choice(responses) + " <@bscannell> and <@magic>"

    return None

def _reactions(client, event, words):
    swears = set(words).intersection(['Fuck', 'Fuckity', 'Fucks', 'F***', 'Fucking', 'Fucked', 'Fbomb', 'Fbombs'])
    if len(swears) > 0:
        client.api_call("reactions.add", name='fbomb', channel=event['channel'], timestamp=event['ts'])

    trump = len(set(words).intersection(['Trump', 'Drumpf', 'Democrat'])) > 0
    hillary = len(set(words).intersection(['Hillary', 'Clinton', 'Obama', 'Republican'])) > 0
    generic = len(set(words).intersection(['Election', 'President', 'Presidential', 'Electoral', 'Politics',
                                           'Constitution', 'Vote', 'Voting'])) > 0

    if trump and not hillary:
        client.api_call("reactions.add", name='hillary', channel=event['channel'], timestamp=event['ts'])
    elif hillary and not trump:
        client.api_call("reactions.add", name='trump', channel=event['channel'], timestamp=event['ts'])
    elif generic or hillary or trump:
        client.api_call("reactions.add", name=random.choice(['trump', 'hillary']), channel=event['channel'],
                        timestamp=event['ts'])


def _poke_quote(pokemon):
    if len(pokemon) == 0:
        # Been triggered, but the user didn't specify a specific Pokemon. Draw a random one.
        pokemon = [random.choice(pokedex.keys())]
        odds = {"description": 1, "type": 1, "statement": 2}
    else:
        odds = {"description": 100, "type": 10, "statement": 2}

    if len(pokemon) == 1:<commit_msg>Adding ability to select user order for standup<commit_after># -*- coding: utf-8 -*-

import random
from slackbot import SlackBot
from data.poketext import pokedex, templates, alternative_desc
from argparse import ArgumentParser
import yaml
from functools import partial
from wolfram import answers
import string
import re
import time

def pikachu(client, event, wolfram_appid=None, bingid=None):
    # Note that all messages get sent here, even if they aren't addressing the bot

    text = event.get('text')
    for pnc in u"“”" + string.punctuation:
        text = text.replace(pnc, ' ')
    words = [word.lower().capitalize() for word in text.split() if len(word) > 1]

    _reactions(client, event, words)

    cmd_response = _commands(client, event, words)

    if cmd_response:
        return cmd_response
    elif event.get('channel') == 'G1EEN6V9D':
        # List channels that he won't respond in other than commands
        return None

    if 'Pikachu' in words and not event.get('speaking_to_me'):
        event['text_query'] = event.get('text_query', '').replace('Pikachu', ' ').replace('pikachu', ' ')
        event['speaking_to_me'] = True

    if event.get('speaking_to_me'):
        # You're talking to me, you want real answers
        return answers(client, event, wolfram_appid, bingid)

    pokemon = list(set(words).intersection(pokedex.keys()))

    if len(pokemon) == 0 and len(set(words).intersection([u'Pokemon'])) == 0:
        # You didn't mention a pokemon or the word "pokemon" and you're not speaking to me
        return None

    return _poke_quote(pokemon)


def _commands(client, event, words):

    text = event.get('text')

    if text.lower() == 'standup!':
        members = _get_quasirandom_userlist(client, event)
        response_message = """Hey, <!channel> , it's time for our :slack: Standup! Respond with:
       I am working on OPTI-XXXX and (more details here)
Optionally followed by:
       I had to stop working on OPTI-XXXX due to (unforeseen reason here)
       I completed my work on OPTI-XXXX
Today's standup order will be {order}
<@{user}>, you're first!""".format(order=", ".join(members), user=members[0])
        return response_message

    tickets = re.findall("((?i)OPTI-\d+)", text)
    if tickets:
        links = [" <https://nanigans.atlassian.net/browse/{ticket}|{ticket}> ".format(ticket=ticket) for ticket in tickets]
        members = _get_quasirandom_userlist(client, event)
        username = event.get('username')

        compliments = ['Great Job {user} on {links}!', '{user}, nice work on {links}!', "{user}'s tickets: {links}.",
                       "Oh yeah, {links}. Challenging stuff.", "Crushing it on {links}.",
                       ":hand: High five {user} on {links}.", ":thumbsup: {user} on {links}."]

        prompts = ["<@{user}>, you're up.", "<@{user}> is next.", "Next up is <@{user}>.", "Ok, <@{user}>'s turn."]
        after = ["({user} is after)", "({user} is on deck)", '({user} can start thinking)']
        final = ["I think that's everybody", "Did I miss anyone?", "Anyone else?"]

        message = random.choice(compliments).format(user=username, links=", ".join(links))

        idx = members.index(username)
        if idx < len(members) - 1:
            next_up = members[idx + 1]
            message += " " + random.choice(prompts).format(user=next_up)

            if idx < len(members) - 2:
                on_deck = members[idx + 2]
                message += " " + random.choice(after).format(user=on_deck)
        else:
            message += " " + random.choice(final)

        # message = "Great Job on " + ", ".join(links) + "!" + "\n" + "Who's up next?"
        print "Sending" + message + " to: " + str(event['channel'])
        client.api_call("chat.postMessage", text=message, channel=event['channel'], as_user=True)
        return ""

    # if text.lower().startswith('interns'): # and event.get('channel') == 'C054GJYFE':
    #     responses = ['Pinging', 'Announcement for', 'I think that was meant for']
    #     return random.choice(responses) + " <@bscannell> and <@magic>"

    return None


def _get_quasirandom_userlist(client, event, excluded_users=['opt-bot', 'internpikachu', 'quip']):
    # Returns a "randomly" sorted list of users in channel that will keep the same order throughout the day

    channel_obj = client.server.channels.find(str(event['channel']))
    members = [client.server.users.find(member).name for member in channel_obj.members]
    members = [x for x in members if x not in excluded_users]

    # Get temporary random number generator based on todays date
    myrandom = random.Random(int(time.strftime("%Y%m%d")))
    myrandom.shuffle(members)

    return members


def _reactions(client, event, words):
    swears = set(words).intersection(['Fuck', 'Fuckity', 'Fucks', 'F***', 'Fucking', 'Fucked', 'Fbomb', 'Fbombs'])
    if len(swears) > 0:
        client.api_call("reactions.add", name='fbomb', channel=event['channel'], timestamp=event['ts'])

    trump = len(set(words).intersection(['Trump', 'Drumpf', 'Democrat'])) > 0
    hillary = len(set(words).intersection(['Hillary', 'Clinton', 'Obama', 'Republican'])) > 0
    generic = len(set(words).intersection(['Election', 'President', 'Presidential', 'Electoral', 'Politics',
                                           'Constitution', 'Vote', 'Voting'])) > 0

    if trump and not hillary:
        client.api_call("reactions.add", name='hillary', channel=event['channel'], timestamp=event['ts'])
    elif hillary and not trump:
        client.api_call("reactions.add", name='trump', channel=event['channel'], timestamp=event['ts'])
    elif generic or hillary or trump:
        client.api_call("reactions.add", name=random.choice(['trump', 'hillary']), channel=event['channel'],
                        timestamp=event['ts'])


def _poke_quote(pokemon):
    if len(pokemon) == 0:
        # Been triggered, but the user didn't specify a specific Pokemon. Draw a random one.
        pokemon = [random.choice(pokedex.keys())]
        odds = {"description": 1, "type": 1, "statement": 2}
    else:
        odds = {"description": 100, "type": 10, "statement": 2}

    if len(pokemon) == 1:
{'fraction_non_alphanumeric': 0.15298471126691984, 'fraction_numerical': 0.005063784204888499, 'mean_word_length': 3.3535396354387452, 'pattern_counts': {'":': 14, '<': 18, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4455406', 'n_tokens_mistral': 3326, 'n_tokens_neox': 3158, 'n_words': 911}