mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Start parsing unknown badges (i.e. game badges)
Prepare channel-specific data to be loaded (i.e. subscription badges)
This commit is contained in:
parent
8715cf14ac
commit
56e521bc24
|
@ -233,29 +233,6 @@ void IrcManager::partChannel(const QString &channelName)
|
|||
this->connectionMutex.unlock();
|
||||
}
|
||||
|
||||
void IrcManager::messageReceived(Communi::IrcMessage *message)
|
||||
{
|
||||
/*
|
||||
qDebug() << "Message received: " << message->command();
|
||||
// qInfo(message->command().toStdString().c_str());
|
||||
//
|
||||
for (const auto ¶m : message->parameters()) {
|
||||
qDebug() << "Param: " << param;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
const QString &command = message->command();
|
||||
|
||||
if (command == "CLEARCHAT") {
|
||||
} else if (command == "ROOMSTATE") {
|
||||
} else if (command == "USERSTATE") {
|
||||
} else if (command == "WHISPER") {
|
||||
} else if (command == "USERNOTICE") {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
||||
{
|
||||
auto c = this->channelManager.getChannel(message->target().mid(1));
|
||||
|
@ -268,6 +245,60 @@ void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message)
|
|||
}
|
||||
}
|
||||
|
||||
void IrcManager::messageReceived(Communi::IrcMessage *message)
|
||||
{
|
||||
if (message->type() == Communi::IrcMessage::Type::Private) {
|
||||
// We already have a handler for private messages
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &command = message->command();
|
||||
|
||||
if (command == "ROOMSTATE") {
|
||||
this->handleRoomStateMessage(message);
|
||||
} else if (command == "CLEARCHAT") {
|
||||
this->handleClearChatMessage(message);
|
||||
} else if (command == "USERSTATE") {
|
||||
this->handleUserStateMessage(message);
|
||||
} else if (command == "WHISPER") {
|
||||
this->handleWhisperMessage(message);
|
||||
} else if (command == "USERNOTICE") {
|
||||
this->handleUserNoticeMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void IrcManager::handleRoomStateMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
const auto &tags = message->tags();
|
||||
|
||||
auto iterator = tags.find("room-id");
|
||||
|
||||
if (iterator != tags.end()) {
|
||||
std::string roomID = iterator.value().toString().toStdString();
|
||||
this->resources.loadChannelData(roomID);
|
||||
}
|
||||
}
|
||||
|
||||
void IrcManager::handleClearChatMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void IrcManager::handleUserStateMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void IrcManager::handleWhisperMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void IrcManager::handleUserNoticeMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
bool IrcManager::isTwitchBlockedUser(QString const &username)
|
||||
{
|
||||
QMutexLocker locker(&_twitchBlockedUsersMutex);
|
||||
|
|
|
@ -80,8 +80,14 @@ private:
|
|||
|
||||
void beginConnecting();
|
||||
|
||||
void messageReceived(Communi::IrcMessage *message);
|
||||
void privateMessageReceived(Communi::IrcPrivateMessage *message);
|
||||
void messageReceived(Communi::IrcMessage *message);
|
||||
|
||||
void handleRoomStateMessage(Communi::IrcMessage *message);
|
||||
void handleClearChatMessage(Communi::IrcMessage *message);
|
||||
void handleUserStateMessage(Communi::IrcMessage *message);
|
||||
void handleWhisperMessage(Communi::IrcMessage *message);
|
||||
void handleUserNoticeMessage(Communi::IrcMessage *message);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -41,12 +41,11 @@ Resources::Resources(EmoteManager &emoteManager, WindowManager &windowManager)
|
|||
util::urlJsonFetch(badgesUrl, [this, &emoteManager, &windowManager](QJsonObject &root) {
|
||||
QJsonObject sets = root.value("badge_sets").toObject();
|
||||
|
||||
for (auto it = std::begin(sets); it != std::end(sets); ++it) {
|
||||
for (QJsonObject::iterator it = sets.begin(); it != sets.end(); ++it) {
|
||||
QJsonObject versions = it.value().toObject().value("versions").toObject();
|
||||
|
||||
auto &badgeSet = this->badgeSets[it.key().toStdString()];
|
||||
|
||||
std::map<std::string, BadgeVersion> &versionsMap = badgeSet.versions;
|
||||
|
||||
QJsonObject versions = it.value().value("versions").toObject();
|
||||
auto &versionsMap = badgeSet.versions;
|
||||
|
||||
for (auto versionIt = std::begin(versions); versionIt != std::end(versions);
|
||||
++versionIt) {
|
||||
|
@ -91,4 +90,9 @@ void Resources::Channel::loadData()
|
|||
*/
|
||||
}
|
||||
|
||||
void Resources::loadChannelData(const std::string &roomID, bool bypassCache)
|
||||
{
|
||||
qDebug() << "Load channel data for" << QString::fromStdString(roomID);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -71,6 +71,8 @@ public:
|
|||
|
||||
// channelId
|
||||
std::map<std::string, Channel> channels;
|
||||
|
||||
void loadChannelData(const std::string &roomID, bool bypassCache = false);
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -364,26 +364,25 @@ void TwitchMessageBuilder::appendTwitchBadges(const QStringList &badges, Resourc
|
|||
}
|
||||
|
||||
QString cheerAmountQS = badge.mid(5);
|
||||
std::string cheerAmountString = cheerAmountQS.toStdString();
|
||||
std::string versionKey = cheerAmountQS.toStdString();
|
||||
|
||||
try {
|
||||
auto &badgeSet = resources.badgeSets.at("bits");
|
||||
|
||||
try {
|
||||
auto &badgeVersion = badgeSet.versions.at(cheerAmountString);
|
||||
auto &badgeVersion = badgeSet.versions.at(versionKey);
|
||||
|
||||
appendWord(
|
||||
Word(badgeVersion.badgeImage1x, Word::BadgeCheer, QString(),
|
||||
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
|
||||
} catch (const std::exception &e) {
|
||||
printf("Exception caught: %s\n", e.what());
|
||||
printf("When trying to fetch the badge version: %s\n",
|
||||
cheerAmountString.c_str());
|
||||
// XXX: Version not found
|
||||
qDebug() << "Exception caught:" << e.what()
|
||||
<< "when trying to fetch badge version " << versionKey.c_str();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
printf("Exception caught: %s\n", e.what());
|
||||
// XXX
|
||||
qDebug() << "No badge set with key"
|
||||
<< "bits"
|
||||
<< ". Exception: " << e.what();
|
||||
}
|
||||
|
||||
} else if (badge == "staff/1") {
|
||||
|
@ -421,6 +420,7 @@ void TwitchMessageBuilder::appendTwitchBadges(const QStringList &badges, Resourc
|
|||
} break;
|
||||
}
|
||||
} else if (badge.startsWith("subscriber/")) {
|
||||
qDebug() << "Subscriber badge:" << badge;
|
||||
int index = badge.midRef(11).toInt();
|
||||
// TODO: Implement subscriber badges here
|
||||
switch (index) {
|
||||
|
@ -430,7 +430,40 @@ void TwitchMessageBuilder::appendTwitchBadges(const QStringList &badges, Resourc
|
|||
} break;
|
||||
}
|
||||
} else {
|
||||
printf("[TwitchMessageBuilder] Unhandled badge: %s\n", qPrintable(badge));
|
||||
if (!resources.dynamicBadgesLoaded) {
|
||||
// Do nothing
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList parts = badge.split('/');
|
||||
|
||||
if (parts.length() != 2) {
|
||||
qDebug() << "Bad number of parts: " << parts.length() << " in " << parts;
|
||||
continue;
|
||||
}
|
||||
|
||||
Word::Type badgeType = Word::Type::BadgeMiscellaneous;
|
||||
|
||||
std::string badgeSetKey = parts[0].toStdString();
|
||||
std::string versionKey = parts[1].toStdString();
|
||||
|
||||
try {
|
||||
auto &badgeSet = resources.badgeSets.at(badgeSetKey);
|
||||
|
||||
try {
|
||||
auto &badgeVersion = badgeSet.versions.at(versionKey);
|
||||
|
||||
appendWord(
|
||||
Word(badgeVersion.badgeImage1x, badgeType, QString(),
|
||||
QString("Twitch " + QString::fromStdString(badgeVersion.title))));
|
||||
} catch (const std::exception &e) {
|
||||
qDebug() << "Exception caught:" << e.what()
|
||||
<< "when trying to fetch badge version " << versionKey.c_str();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
qDebug() << "No badge set with key" << badgeSetKey.c_str()
|
||||
<< ". Exception: " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue