<commit_before>#include "providers/twitch/twitchapi.hpp"

#include "common/NetworkRequest.hpp"
#include "debug/Log.hpp"
#include "providers/twitch/TwitchCommon.hpp"

#include <QString>

namespace chatterino {

void TwitchApi::findUserId(const QString user, std::function<void(QString)> successCallback)
{
    QString requestUrl("https://api.twitch.tv/kraken/users?login=" + user);

    NetworkRequest request(requestUrl);
    request.setCaller(QThread::currentThread());
    request.makeAuthorizedV5(getDefaultClientID());
    request.setTimeout(30000);
    request.onSuccess([successCallback](auto result) mutable {
        auto root = result.parseJson();
        if (!root.value("users").isArray()) {
            Log("API Error while getting user id, users is not an array");
            successCallback("");
            return true;
        }
        auto users = root.value("users").toArray();
        if (users.size() != 1) {
            Log("API Error while getting user id, users array size is not 1");
            successCallback("");
            return true;
        }
        if (!users[0].isObject()) {
            Log("API Error while getting user id, first user is not an object");
            successCallback("");
            return true;
        }
        auto firstUser = users[0].toObject();
        auto id = firstUser.value("_id");
        if (!id.isString()) {
            Log("API Error: while getting user id, first user object `_id` key is not a "
                "string");
            successCallback("");
            return true;
        }
        successCallback(id.toString());<commit_msg>changed return-value of errors to false<commit_after>#include "providers/twitch/twitchapi.hpp"

#include "common/NetworkRequest.hpp"
#include "debug/Log.hpp"
#include "providers/twitch/TwitchCommon.hpp"

#include <QString>

namespace chatterino {

void TwitchApi::findUserId(const QString user, std::function<void(QString)> successCallback)
{
    QString requestUrl("https://api.twitch.tv/kraken/users?login=" + user);

    NetworkRequest request(requestUrl);
    request.setCaller(QThread::currentThread());
    request.makeAuthorizedV5(getDefaultClientID());
    request.setTimeout(30000);
    request.onSuccess([successCallback](auto result) mutable {
        auto root = result.parseJson();
        if (!root.value("users").isArray()) {
            Log("API Error while getting user id, users is not an array");
            successCallback("");
            return false;
        }
        auto users = root.value("users").toArray();
        if (users.size() != 1) {
            Log("API Error while getting user id, users array size is not 1");
            successCallback("");
            return false;
        }
        if (!users[0].isObject()) {
            Log("API Error while getting user id, first user is not an object");
            successCallback("");
            return false;
        }
        auto firstUser = users[0].toObject();
        auto id = firstUser.value("_id");
        if (!id.isString()) {
            Log("API Error: while getting user id, first user object `_id` key is not a "
                "string");
            successCallback("");
            return false;
        }
        successCallback(id.toString());
{'fraction_non_alphanumeric': 0.13020833333333334, 'fraction_numerical': 0.006127450980392157, 'mean_word_length': 2.568306010928962, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '346395', 'n_tokens_mistral': 886, 'n_tokens_neox': 887, 'n_words': 230}