2020-05-10 12:45:19 +02:00
|
|
|
#include "util/Twitch.hpp"
|
|
|
|
|
2022-09-16 23:15:28 +02:00
|
|
|
#include "util/QStringHash.hpp"
|
|
|
|
|
2020-05-10 12:45:19 +02:00
|
|
|
#include <QDesktopServices>
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <QUrl>
|
2020-05-10 12:45:19 +02:00
|
|
|
|
2022-09-16 23:15:28 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2020-05-10 12:45:19 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2022-05-08 12:27:25 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)";
|
|
|
|
|
2022-09-16 23:15:28 +02:00
|
|
|
// Remember to keep VALID_HELIX_COLORS up-to-date if a new color is implemented to keep naming for users consistent
|
|
|
|
const std::unordered_map<QString, QString> HELIX_COLOR_REPLACEMENTS{
|
|
|
|
{"blueviolet", "blue_violet"}, {"cadetblue", "cadet_blue"},
|
|
|
|
{"dodgerblue", "dodger_blue"}, {"goldenrod", "golden_rod"},
|
|
|
|
{"hotpink", "hot_pink"}, {"orangered", "orange_red"},
|
|
|
|
{"seagreen", "sea_green"}, {"springgreen", "spring_green"},
|
|
|
|
{"yellowgreen", "yellow_green"},
|
|
|
|
};
|
|
|
|
|
2022-05-08 12:27:25 +02:00
|
|
|
} // namespace
|
|
|
|
|
2022-09-16 23:15:28 +02:00
|
|
|
// Colors retreived from https://dev.twitch.tv/docs/api/reference#update-user-chat-color 2022-09-11
|
|
|
|
// Remember to keep HELIX_COLOR_REPLACEMENTS up-to-date if a new color is implemented to keep naming for users consistent
|
|
|
|
extern const QStringList VALID_HELIX_COLORS{
|
|
|
|
"blue", "blue_violet", "cadet_blue", "chocolate", "coral",
|
|
|
|
"dodger_blue", "firebrick", "golden_rod", "green", "hot_pink",
|
|
|
|
"orange_red", "red", "sea_green", "spring_green", "yellow_green",
|
|
|
|
};
|
|
|
|
|
2020-05-10 12:45:19 +02:00
|
|
|
void openTwitchUsercard(QString channel, QString username)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl("https://www.twitch.tv/popout/" + channel +
|
|
|
|
"/viewercard/" + username);
|
|
|
|
}
|
2022-02-12 15:06:47 +01:00
|
|
|
|
|
|
|
void stripUserName(QString &userName)
|
|
|
|
{
|
|
|
|
if (userName.startsWith('@'))
|
|
|
|
{
|
|
|
|
userName.remove(0, 1);
|
|
|
|
}
|
|
|
|
if (userName.endsWith(','))
|
|
|
|
{
|
|
|
|
userName.chop(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stripChannelName(QString &channelName)
|
|
|
|
{
|
|
|
|
if (channelName.startsWith('@') || channelName.startsWith('#'))
|
|
|
|
{
|
|
|
|
channelName.remove(0, 1);
|
|
|
|
}
|
|
|
|
if (channelName.endsWith(','))
|
|
|
|
{
|
|
|
|
channelName.chop(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-08 12:27:25 +02:00
|
|
|
QRegularExpression twitchUserNameRegexp()
|
|
|
|
{
|
|
|
|
static QRegularExpression re(
|
|
|
|
TWITCH_USER_LOGIN_PATTERN,
|
|
|
|
QRegularExpression::PatternOption::CaseInsensitiveOption);
|
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegularExpression twitchUserLoginRegexp()
|
|
|
|
{
|
|
|
|
static QRegularExpression re(TWITCH_USER_LOGIN_PATTERN);
|
|
|
|
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
2022-09-16 23:15:28 +02:00
|
|
|
void cleanHelixColorName(QString &color)
|
|
|
|
{
|
|
|
|
color = color.toLower();
|
|
|
|
auto it = HELIX_COLOR_REPLACEMENTS.find(color);
|
|
|
|
|
|
|
|
if (it == HELIX_COLOR_REPLACEMENTS.end())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
color = it->second;
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:45:19 +02:00
|
|
|
} // namespace chatterino
|