mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Implement emoji sending using shortcodes 😎 🅱️
This commit is contained in:
parent
65e18d4833
commit
b5407c94aa
3 changed files with 41 additions and 1 deletions
|
@ -118,7 +118,11 @@ void Channel::reloadChannelEmotes()
|
|||
void Channel::sendMessage(const QString &message)
|
||||
{
|
||||
qDebug() << "Channel send message: " << message;
|
||||
this->ircManager.sendMessage(name, message);
|
||||
|
||||
// Do last message processing
|
||||
QString parsedMessage = this->emoteManager.replaceShortCodes(message);
|
||||
|
||||
this->ircManager.sendMessage(name, parsedMessage);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace chatterino {
|
|||
EmoteManager::EmoteManager(WindowManager &_windowManager, Resources &_resources)
|
||||
: windowManager(_windowManager)
|
||||
, resources(_resources)
|
||||
, findShortCodesRegex(":([-+\\w]+):")
|
||||
{
|
||||
// Note: Do not use this->resources in ctor
|
||||
pajlada::Settings::Setting<std::string> roomID(
|
||||
|
@ -294,6 +295,36 @@ void EmoteManager::parseEmojis(std::vector<std::tuple<EmoteData, QString>> &pars
|
|||
}
|
||||
}
|
||||
|
||||
QString EmoteManager::replaceShortCodes(const QString &text)
|
||||
{
|
||||
QString ret(text);
|
||||
auto it = this->findShortCodesRegex.globalMatch(text);
|
||||
|
||||
int32_t offset = 0;
|
||||
|
||||
while (it.hasNext()) {
|
||||
auto match = it.next();
|
||||
|
||||
auto capturedString = match.captured();
|
||||
|
||||
QString matchString = capturedString.toLower().mid(1, capturedString.size() - 2);
|
||||
|
||||
auto emojiIt = this->emojiShortCodeToEmoji.constFind(matchString);
|
||||
|
||||
if (emojiIt == this->emojiShortCodeToEmoji.constEnd()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto emojiData = emojiIt.value();
|
||||
|
||||
ret.replace(offset + match.capturedStart(), match.capturedLength(), emojiData.value);
|
||||
|
||||
offset += emojiData.value.size() - match.capturedLength();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EmoteManager::refreshTwitchEmotes(const std::string &roomID)
|
||||
{
|
||||
std::string oauthClient =
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <boost/signals2.hpp>
|
||||
|
@ -75,6 +76,8 @@ private:
|
|||
Resources &resources;
|
||||
|
||||
/// Emojis
|
||||
QRegularExpression findShortCodesRegex;
|
||||
|
||||
// shortCodeToEmoji maps strings like "sunglasses" to its emoji
|
||||
QMap<QString, EmojiData> emojiShortCodeToEmoji;
|
||||
|
||||
|
@ -89,6 +92,8 @@ private:
|
|||
public:
|
||||
void parseEmojis(std::vector<std::tuple<EmoteData, QString>> &parsedWords, const QString &text);
|
||||
|
||||
QString replaceShortCodes(const QString &text);
|
||||
|
||||
/// Twitch emotes
|
||||
void refreshTwitchEmotes(const std::string &roomID);
|
||||
|
||||
|
|
Loading…
Reference in a new issue