<commit_before>#! /usr/bin/env python2.7

import modules.commands.helpers.get_category_string as get_category_string
import modules.commands.helpers.get_category_title as get_category_title
import modules.commands.helpers.time_formatter as time_formatter

def call(salty_inst, c_msg, **kwargs):
    msg_split = c_msg["message"].split(" ", 2)
    infer_category = True
    search_game = True

    try:
        game = msg_split[1].lower()
        search_game = False
    except IndexError:
        game = salty_inst.game
    try:
        category = msg_split[2].lower()
        infer_category = False
    except IndexError:
        category = salty_inst.title

    if search_game:
        success, response = salty_inst.sr_com_api.get_search_games(game)
        if not success:
            return False, \
                "Error retrieving info from speedrun.com ({0}).".format(response.status_code)
    else:
        success, response = salty_inst.sr_com_api.get_game_leaderboards(game, category, )<commit_msg>finish up wr<commit_after>#! /usr/bin/env python2.7

import modules.commands.helpers.get_category_string as get_category_string
import modules.commands.helpers.get_category_title as get_category_title
import modules.commands.helpers.time_formatter as time_formatter

def call(salty_inst, c_msg, **kwargs):
    msg_split = c_msg["message"].split(" ", 2)
    infer_category = True
    search_game = True

    try:
        game = msg_split[1].lower()
        search_game = False
    except IndexError:
        game = salty_inst.game
    try:
        category = msg_split[2].lower()
        infer_category = False
    except IndexError:
        category = salty_inst.title

    if search_game:
        success, response = salty_inst.sr_com_api.get_games_search(game)
        if not success:
            return False, \
                "Error retrieving games from speedrun.com ({0}).".format(response.status_code)
        for i in response["data"]:
            if i["names"]["international"] == game:
                found_categories = [{x["name"] : x["id"]} for x in i["categories"]["data"] if x["type"] == "per-game"]
                game_id = i["id"]
                break
        else:
            return False, "No game found for: {0}.".format(game)

    if infer_category:
        category_finder = get_category_title.find_active_cat
    else:
        category_finder = get_category_string.find_active_cat

    cat_success, cat_response = category_finder(found_categories, category)
    if not cat_success:
        return False, cat_response

    success, response = salty_inst.sr_com_api.get_leaderboards(game_id, found_categories[cat_response], **kwargs)
    if not success:
        return False, \
            "Error retrieving leaderboard from speedrun.com ({0}).".format(response.status_code)

    msg = "The current world record for {0} {1} is {2} by {3}.".format(
        response["data"]["game"]["data"]["names"]["international"],
        cat_response,
        time_formatter.format(response["runs"]["times"]["primary_t"]),
        response["players"]["data"][0]["names"]["international"]
    )
    if response["runs"][0]["run"]["videos"]:
        msg += " Video: {0}".format(response["runs"][0]["run"]["videos"]["links"][0]["uri"])
    if response["runs"][0]["run"]["splits"]:
        msg += " Splits: {0}".format(response["runs"][0]["run"]["splits"]["uri"])

    return True, msg
{'fraction_non_alphanumeric': 0.12941176470588237, 'fraction_numerical': 0.007647058823529412, 'mean_word_length': 3.1274271844660193, 'pattern_counts': {'":': 0, '<': 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': '2605555', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1055, 'n_words': 217}