Migrate /color command to Helix API (#3988)
This commit is contained in:
@@ -1,16 +1,37 @@
|
||||
#include "util/Twitch.hpp"
|
||||
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)";
|
||||
|
||||
// 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"},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// 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",
|
||||
};
|
||||
|
||||
void openTwitchUsercard(QString channel, QString username)
|
||||
{
|
||||
QDesktopServices::openUrl("https://www.twitch.tv/popout/" + channel +
|
||||
@@ -57,4 +78,17 @@ QRegularExpression twitchUserLoginRegexp()
|
||||
return re;
|
||||
}
|
||||
|
||||
void cleanHelixColorName(QString &color)
|
||||
{
|
||||
color = color.toLower();
|
||||
auto it = HELIX_COLOR_REPLACEMENTS.find(color);
|
||||
|
||||
if (it == HELIX_COLOR_REPLACEMENTS.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = it->second;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user