mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Made cleanUpCode() as static TwitchEmotes's method.
This commit is contained in:
parent
23458aa1df
commit
0d48c04d8a
4 changed files with 31 additions and 33 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "util/DebugCount.hpp"
|
||||
|
||||
|
@ -99,7 +100,7 @@ void ImageLayoutElement::addCopyTextToString(QString &str, int from,
|
|||
if (emoteElement)
|
||||
{
|
||||
str += emoteElement->getEmote()->getCopyString();
|
||||
str.replace("<", "<").replace(">", ">");
|
||||
str = TwitchEmotes::cleanUpEmoteCode(EmoteName{str});
|
||||
if (this->hasTrailingSpace())
|
||||
{
|
||||
str += " ";
|
||||
|
|
|
@ -13,37 +13,6 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
|
||||
{
|
||||
auto cleanCode = dirtyEmoteCode.string;
|
||||
cleanCode.detach();
|
||||
|
||||
static QMap<QString, QString> emoteNameReplacements{
|
||||
{"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("},
|
||||
{"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"},
|
||||
{"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"},
|
||||
{"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("},
|
||||
{"\\:-?\\)", ":)"}, {"\\:-?D", ":D"},
|
||||
{"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"},
|
||||
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
|
||||
};
|
||||
|
||||
auto it = emoteNameReplacements.find(dirtyEmoteCode.string);
|
||||
if (it != emoteNameReplacements.end())
|
||||
{
|
||||
cleanCode = it.value();
|
||||
}
|
||||
|
||||
cleanCode.replace("<", "<");
|
||||
cleanCode.replace(">", ">");
|
||||
|
||||
return {cleanCode};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken,
|
||||
const QString &oauthClient, const QString &userID)
|
||||
: Account(ProviderId::Twitch)
|
||||
|
@ -491,7 +460,7 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
|||
auto code = EmoteName{_code};
|
||||
auto id = EmoteId{QString::number(idNumber)};
|
||||
|
||||
auto cleanCode = cleanUpCode(code);
|
||||
auto cleanCode = EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
|
||||
emoteSet->emotes.emplace_back(TwitchEmote{id, cleanCode});
|
||||
emoteData->allEmoteNames.push_back(cleanCode);
|
||||
|
||||
|
|
|
@ -13,6 +13,33 @@ TwitchEmotes::TwitchEmotes()
|
|||
{
|
||||
}
|
||||
|
||||
QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
|
||||
{
|
||||
auto cleanCode = dirtyEmoteCode.string;
|
||||
cleanCode.detach();
|
||||
|
||||
static QMap<QString, QString> emoteNameReplacements{
|
||||
{"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("},
|
||||
{"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"},
|
||||
{"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"},
|
||||
{"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("},
|
||||
{"\\:-?\\)", ":)"}, {"\\:-?D", ":D"},
|
||||
{"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"},
|
||||
{"R-?\\)", "R)"}, {"B-?\\)", "B)"},
|
||||
};
|
||||
|
||||
auto it = emoteNameReplacements.find(dirtyEmoteCode.string);
|
||||
if (it != emoteNameReplacements.end())
|
||||
{
|
||||
cleanCode = it.value();
|
||||
}
|
||||
|
||||
cleanCode.replace("<", "<");
|
||||
cleanCode.replace(">", ">");
|
||||
|
||||
return cleanCode;
|
||||
}
|
||||
|
||||
// id is used for lookup
|
||||
// emoteName is used for giving a name to the emote in case it doesn't exist
|
||||
EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
|
||||
|
|
|
@ -32,6 +32,7 @@ struct CheerEmoteSet {
|
|||
class TwitchEmotes
|
||||
{
|
||||
public:
|
||||
static QString cleanUpEmoteCode(const EmoteName &dirtyEmoteCode);
|
||||
TwitchEmotes();
|
||||
|
||||
EmotePtr getOrCreateEmote(const EmoteId &id, const EmoteName &name);
|
||||
|
|
Loading…
Reference in a new issue