<commit_before>"""
Based on guide posted at:
https://www.fullstackpython.com/blog/build-first-slack-bot-python.html
"""
from __future__ import division # force decimal divison by default

import os
import sys
import time

try:
    from slackclient import SlackClient
except ImportError as err:
    print("")
    print(err)
    print("")
    print("Did you forget to `$ pip install slackclient`? Quitting.")
    print("")
    sys.exit(1)

# Assign the token via environment variable
try:
    SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
except KeyError:
    print("")
    print("Is SLACK_BOT_TOKEN configured in Heroku app Settings w/ a valid Slack token?")
    print("")

# Use the BOT_ID gathered from get_pybot_id.py
BOT_ID = "U1J60L0F2"

AT_BOT = "<@" + BOT_ID + ">:"

EXAMPLE_COMMAND = "do"
VIDCARD_COMMAND = "vidcard"

slack_client = SlackClient(SLACK_BOT_TOKEN)


def vidcard_calc(dollar_amount):
    num_vid_cards = dollar_amount / 300
    return num_vid_cards


def handle_command(command, channel):
    """
    Receives commands directed at bot & determines if valid.

    :param command:
    :param channel:
    :return:
    """
    response = "Not sure what you mean. Use the *" + EXAMPLE_COMMAND + \
        "* command with numbers, delimited by spaces."
    if command.startswith(EXAMPLE_COMMAND):
        response = "Sure .. write some code and I can do that."
    if command.startswith(VIDCARD_COMMAND):
        print(command) # only shows up in logging, $ heroku log -n 50
        command_dollar_amount = command.split(" ")[1]
        # Get rid of preceding dollar signs if present
        if command_dollar_amount.startswith("$"):
            command_dollar_amount = command_dollar_amount.lstrip("$")
        # Get rid of commas if present
        if "," in command_dollar_amount:
            command_dollar_amount = command_dollar_amount.replace(",", "")
        try:
            command_dollar_amount = int(command_dollar_amount)
            vidcard_number = vidcard_calc(command_dollar_amount)
            if vidcard_number < 1:
                response = "That's not even one video card ;("
            else:
                response = "That's {0} video cards!".format(vidcard_number)
        except ValueError:
            response = "You need to give me a number!"

    # if command.startswith("leave"):
    #     #response = "Channel is {0}. Your command was: {1}".format(channel, command)
    #     channel_to_leave = command.split(" ")[1]
    #     data_about_channel = slack_client.api_call("channels.info", channel=channel_to_leave)
    #     response = "Command: {0}. Channel: {1}. Data about channel: {2}".format(command, channel_to_leave, data_about_channel)
    #     #slack_client.api_call("channels.leave", channel=channel)<commit_msg>strip decimal on even results in vidcard func<commit_after>"""
Based on guide posted at:
https://www.fullstackpython.com/blog/build-first-slack-bot-python.html
"""
from __future__ import division # force decimal divison by default

import os
import sys
import time

try:
    from slackclient import SlackClient
except ImportError as err:
    print("")
    print(err)
    print("")
    print("Did you forget to `$ pip install slackclient`? Quitting.")
    print("")
    sys.exit(1)

# Assign the token via environment variable
try:
    SLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]
except KeyError:
    print("")
    print("Is SLACK_BOT_TOKEN configured in Heroku app Settings w/ a valid Slack token?")
    print("")

# Use the BOT_ID gathered from get_pybot_id.py
BOT_ID = "U1J60L0F2"

AT_BOT = "<@" + BOT_ID + ">:"

EXAMPLE_COMMAND = "do"
VIDCARD_COMMAND = "vidcard"

slack_client = SlackClient(SLACK_BOT_TOKEN)


def vidcard_calc(dollar_amount):
    num_vid_cards = dollar_amount / 300
    return num_vid_cards


def handle_command(command, channel):
    """
    Receives commands directed at bot & determines if valid.

    :param command:
    :param channel:
    :return:
    """
    response = "Not sure what you mean. Use the *" + EXAMPLE_COMMAND + \
        "* command with numbers, delimited by spaces."
    if command.startswith(EXAMPLE_COMMAND):
        response = "Sure .. write some code and I can do that."
    if command.startswith(VIDCARD_COMMAND):
        print(command) # only shows up in logging, $ heroku log -n 50
        command_dollar_amount = command.split(" ")[1]
        # Get rid of preceding dollar signs if present
        if command_dollar_amount.startswith("$"):
            command_dollar_amount = command_dollar_amount.lstrip("$")
        # Get rid of commas if present
        if "," in command_dollar_amount:
            command_dollar_amount = command_dollar_amount.replace(",", "")
        try:
            command_dollar_amount = int(command_dollar_amount)
            vidcard_number = vidcard_calc(command_dollar_amount)
            # if it's an even number, example 20.0, strip off the decimal
            if vidcard_number % 2 == 0:
                vidcard_number = int(vidcard_number)
            if vidcard_number < 1:
                response = "That's not even one video card ;("
            else:
                response = "That's {0} video cards!".format(vidcard_number)
        except ValueError:
            response = "You need to give me a number!"

    # if command.startswith("leave"):
    #     #response = "Channel is {0}. Your command was: {1}".format(channel, command)
    #     channel_to_leave = command.split(" ")[1]
    #     data_about_channel = slack_client.api_call("channels.info", channel=channel_to_leave)
    #     response = "Command: {0}. Channel: {1}. Data about channel: {2}".format(command, channel_to_leave, data_about_channel)
    #     #slack_client.api_call("channels.leave", channel=channel)
{'fraction_non_alphanumeric': 0.10482326310290789, 'fraction_numerical': 0.007835625979453248, 'mean_word_length': 3.0679886685552407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '270024', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1762, 'n_words': 491}