2020-10-18 15:54:48 +02:00
|
|
|
#include "IrcMessageHandler.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
#include "Application.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
#include "messages/LimitedQueue.hpp"
|
|
|
|
#include "messages/Message.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "providers/twitch/TwitchAccountManager.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "providers/twitch/TwitchHelpers.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
2021-01-31 13:55:44 +01:00
|
|
|
#include "util/FormatTime.hpp"
|
2021-04-11 14:17:21 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
#include "util/IrcHelpers.hpp"
|
|
|
|
|
|
|
|
#include <IrcMessage>
|
|
|
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
2020-12-12 14:19:51 +01:00
|
|
|
namespace {
|
|
|
|
using namespace chatterino;
|
2021-05-01 17:42:51 +02:00
|
|
|
|
|
|
|
// Message types below are the ones that might contain special user's message on USERNOTICE
|
|
|
|
static const QSet<QString> specialMessageTypes{
|
|
|
|
"sub", //
|
|
|
|
"subgift", //
|
|
|
|
"resub", // resub messages
|
|
|
|
"bitsbadgetier", // bits badge upgrade
|
|
|
|
"ritual", // new viewer ritual
|
|
|
|
};
|
|
|
|
|
2020-12-12 14:19:51 +01:00
|
|
|
MessagePtr generateBannedMessage(bool confirmedBan)
|
|
|
|
{
|
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::Reconnect, QString());
|
|
|
|
const auto bannedText =
|
|
|
|
confirmedBan
|
|
|
|
? QString("You were banned from this channel!")
|
|
|
|
: QString(
|
|
|
|
"Your connection to this channel was unexpectedly dropped.");
|
|
|
|
|
|
|
|
const auto reconnectPromptText =
|
|
|
|
confirmedBan
|
|
|
|
? QString(
|
|
|
|
"If you believe you have been unbanned, try reconnecting.")
|
|
|
|
: QString("Try reconnecting.");
|
|
|
|
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
auto text = QString("%1 %2").arg(bannedText, reconnectPromptText);
|
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2020-12-12 14:19:51 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(bannedText, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(reconnectPromptText, MessageElementFlag::Text,
|
|
|
|
linkColor)
|
|
|
|
->setLink(accountsLink);
|
|
|
|
|
|
|
|
return builder.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2019-09-08 22:27:57 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2020-02-02 14:31:37 +01:00
|
|
|
static float relativeSimilarity(const QString &str1, const QString &str2)
|
|
|
|
{
|
|
|
|
// Longest Common Substring Problem
|
|
|
|
std::vector<std::vector<int>> tree(str1.size(),
|
|
|
|
std::vector<int>(str2.size(), 0));
|
|
|
|
int z = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < str1.size(); ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < str2.size(); ++j)
|
|
|
|
{
|
|
|
|
if (str1[i] == str2[j])
|
|
|
|
{
|
|
|
|
if (i == 0 || j == 0)
|
|
|
|
{
|
|
|
|
tree[i][j] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tree[i][j] = tree[i - 1][j - 1] + 1;
|
|
|
|
}
|
|
|
|
if (tree[i][j] > z)
|
|
|
|
{
|
|
|
|
z = tree[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tree[i][j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 21:05:40 +02:00
|
|
|
// ensure that no div by 0
|
|
|
|
return z == 0 ? 0.f
|
|
|
|
: float(z) /
|
|
|
|
std::max<int>(1, std::max(str1.size(), str2.size()));
|
2020-02-02 14:31:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
float IrcMessageHandler::similarity(
|
|
|
|
MessagePtr msg, const LimitedQueueSnapshot<MessagePtr> &messages)
|
|
|
|
{
|
|
|
|
float similarityPercent = 0.0f;
|
2021-08-14 14:28:08 +02:00
|
|
|
int checked = 0;
|
|
|
|
for (int i = 1; i <= messages.size(); ++i)
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
2021-08-14 14:28:08 +02:00
|
|
|
if (checked >= getSettings()->hideSimilarMaxMessagesToCheck)
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const auto &prevMsg = messages[messages.size() - i];
|
|
|
|
if (prevMsg->parseTime.secsTo(QTime::currentTime()) >=
|
|
|
|
getSettings()->hideSimilarMaxDelay)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-08-14 14:28:08 +02:00
|
|
|
if (getSettings()->hideSimilarBySameUser &&
|
|
|
|
msg->loginName != prevMsg->loginName)
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-14 14:28:08 +02:00
|
|
|
++checked;
|
2020-02-02 14:31:37 +01:00
|
|
|
similarityPercent = std::max(
|
|
|
|
similarityPercent,
|
|
|
|
relativeSimilarity(msg->messageText, prevMsg->messageText));
|
|
|
|
}
|
|
|
|
return similarityPercent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::setSimilarityFlags(MessagePtr msg, ChannelPtr chan)
|
|
|
|
{
|
|
|
|
if (getSettings()->similarityEnabled)
|
|
|
|
{
|
|
|
|
bool isMyself = msg->loginName ==
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName();
|
|
|
|
bool hideMyself = getSettings()->hideSimilarMyself;
|
|
|
|
|
|
|
|
if (isMyself && !hideMyself)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IrcMessageHandler::similarity(msg, chan->getMessageSnapshot()) >
|
|
|
|
getSettings()->similarityPercentage)
|
|
|
|
{
|
|
|
|
msg->flags.set(MessageFlag::Similar, true);
|
|
|
|
if (getSettings()->colorSimilarDisabled)
|
|
|
|
{
|
|
|
|
msg->flags.set(MessageFlag::Disabled, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
static QMap<QString, QString> parseBadges(QString badgesString)
|
|
|
|
{
|
|
|
|
QMap<QString, QString> badges;
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
for (const auto &badgeData : badgesString.split(','))
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
auto parts = badgeData.split('/');
|
|
|
|
if (parts.length() != 2)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
badges.insert(parts[0], parts[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return badges;
|
|
|
|
}
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
IrcMessageHandler &IrcMessageHandler::instance()
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
static IrcMessageHandler instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MessagePtr> IrcMessageHandler::parseMessage(
|
|
|
|
Channel *channel, Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
|
|
|
|
auto command = message->command();
|
|
|
|
|
|
|
|
if (command == "PRIVMSG")
|
|
|
|
{
|
|
|
|
return this->parsePrivMessage(
|
|
|
|
channel, static_cast<Communi::IrcPrivateMessage *>(message));
|
|
|
|
}
|
|
|
|
else if (command == "USERNOTICE")
|
|
|
|
{
|
|
|
|
return this->parseUserNoticeMessage(channel, message);
|
|
|
|
}
|
|
|
|
else if (command == "NOTICE")
|
|
|
|
{
|
|
|
|
return this->parseNoticeMessage(
|
|
|
|
static_cast<Communi::IrcNoticeMessage *>(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MessagePtr> IrcMessageHandler::parsePrivMessage(
|
|
|
|
Channel *channel, Communi::IrcPrivateMessage *message)
|
|
|
|
{
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
MessageParseArgs args;
|
|
|
|
TwitchMessageBuilder builder(channel, message, args, message->content(),
|
|
|
|
message->isAction());
|
|
|
|
if (!builder.isIgnored())
|
|
|
|
{
|
|
|
|
builtMessages.emplace_back(builder.build());
|
|
|
|
builder.triggerHighlights();
|
|
|
|
}
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
2019-09-18 13:03:16 +02:00
|
|
|
TwitchIrcServer &server)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2022-01-11 01:18:02 +01:00
|
|
|
// This is to make sure that combined emoji go through properly, see
|
|
|
|
// https://github.com/Chatterino/chatterino2/issues/3384 and
|
|
|
|
// https://mm2pl.github.io/emoji_rfc.pdf for more details
|
|
|
|
// Constants used here are defined in TwitchChannel.hpp
|
|
|
|
|
|
|
|
this->addMessage(
|
|
|
|
message, message->target(),
|
|
|
|
message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server,
|
|
|
|
false, message->isAction());
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
|
|
|
|
const QString &target,
|
2019-09-18 13:03:16 +02:00
|
|
|
const QString &content,
|
|
|
|
TwitchIrcServer &server, bool isSub,
|
|
|
|
bool isAction)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
QString channelName;
|
|
|
|
if (!trimChannelName(target, channelName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto chan = server.getChannelOrEmpty(channelName);
|
|
|
|
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageParseArgs args;
|
|
|
|
if (isSub)
|
|
|
|
{
|
|
|
|
args.trimSubscriberUsername = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan->isBroadcaster())
|
|
|
|
{
|
|
|
|
args.isStaffOrBroadcaster = true;
|
|
|
|
}
|
|
|
|
|
2020-08-08 15:37:22 +02:00
|
|
|
auto channel = dynamic_cast<TwitchChannel *>(chan.get());
|
|
|
|
|
|
|
|
const auto &tags = _message->tags();
|
|
|
|
if (const auto &it = tags.find("custom-reward-id"); it != tags.end())
|
|
|
|
{
|
|
|
|
const auto rewardId = it.value().toString();
|
|
|
|
if (!channel->isChannelPointRewardKnown(rewardId))
|
|
|
|
{
|
|
|
|
// Need to wait for pubsub reward notification
|
|
|
|
auto clone = _message->clone();
|
|
|
|
channel->channelPointRewardAdded.connect(
|
|
|
|
[=, &server](ChannelPointReward reward) {
|
|
|
|
if (reward.id == rewardId)
|
|
|
|
{
|
|
|
|
this->addMessage(clone, target, content, server, isSub,
|
|
|
|
isAction);
|
|
|
|
clone->deleteLater();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
args.channelPointRewardId = rewardId;
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
TwitchMessageBuilder builder(chan.get(), _message, args, content, isAction);
|
|
|
|
|
|
|
|
if (isSub || !builder.isIgnored())
|
|
|
|
{
|
|
|
|
if (isSub)
|
|
|
|
{
|
|
|
|
builder->flags.set(MessageFlag::Subscription);
|
|
|
|
builder->flags.unset(MessageFlag::Highlighted);
|
|
|
|
}
|
|
|
|
auto msg = builder.build();
|
2020-02-02 14:31:37 +01:00
|
|
|
|
|
|
|
IrcMessageHandler::setSimilarityFlags(msg, chan);
|
|
|
|
|
|
|
|
if (!msg->flags.has(MessageFlag::Similar) ||
|
|
|
|
(!getSettings()->hideSimilar &&
|
|
|
|
getSettings()->shownSimilarTriggerHighlights))
|
|
|
|
{
|
|
|
|
builder.triggerHighlights();
|
|
|
|
}
|
|
|
|
|
2020-10-24 14:33:15 +02:00
|
|
|
const auto highlighted = msg->flags.has(MessageFlag::Highlighted);
|
|
|
|
const auto showInMentions = msg->flags.has(MessageFlag::ShowInMentions);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-08-15 12:39:58 +02:00
|
|
|
if (highlighted && showInMentions)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-08-15 12:39:58 +02:00
|
|
|
server.mentionsChannel->addMessage(msg);
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chan->addMessage(msg);
|
2019-09-18 13:03:16 +02:00
|
|
|
if (auto chatters = dynamic_cast<ChannelChatters *>(chan.get()))
|
|
|
|
{
|
|
|
|
chatters->addRecentChatter(msg->displayName);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
const auto &tags = message->tags();
|
|
|
|
|
2021-10-17 15:06:58 +02:00
|
|
|
// get Twitch channel
|
2019-09-08 22:27:57 +02:00
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
auto chan = getApp()->twitch.server->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
|
|
|
|
if (!twitchChannel)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
// room-id
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("room-id"); it != tags.end())
|
|
|
|
{
|
|
|
|
auto roomId = it.value().toString();
|
|
|
|
twitchChannel->setRoomId(roomId);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
// Room modes
|
|
|
|
{
|
|
|
|
auto roomModes = *twitchChannel->accessRoomModes();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("emote-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.emoteOnly = it.value() == "1";
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("subs-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.submode = it.value() == "1";
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("slow"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.slowMode = it.value().toInt();
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("r9k"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.r9k = it.value() == "1";
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("followers-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.followerOnly = it.value().toInt();
|
|
|
|
}
|
|
|
|
twitchChannel->setRoomModes(roomModes);
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
|
|
|
|
twitchChannel->roomModesChanged.invoke();
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// check parameter count
|
|
|
|
if (message->parameters().length() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get channel
|
2021-07-17 15:09:21 +02:00
|
|
|
auto chan = getApp()->twitch.server->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[IrcMessageHandler:handleClearChatMessage] Twitch channel"
|
|
|
|
<< chanName << "not found";
|
2019-09-08 22:27:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the chat has been cleared by a moderator
|
|
|
|
if (message->parameters().length() == 1)
|
|
|
|
{
|
|
|
|
chan->disableAllMessages();
|
|
|
|
chan->addMessage(
|
2020-10-03 13:37:07 +02:00
|
|
|
makeSystemMessage("Chat has been cleared by a moderator.",
|
|
|
|
calculateMessageTimestamp(message)));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get username, duration and message of the timed out user
|
|
|
|
QString username = message->parameter(1);
|
2021-04-25 15:44:12 +02:00
|
|
|
QString durationInSeconds;
|
2019-09-08 22:27:57 +02:00
|
|
|
QVariant v = message->tag("ban-duration");
|
|
|
|
if (v.isValid())
|
|
|
|
{
|
|
|
|
durationInSeconds = v.toString();
|
|
|
|
}
|
|
|
|
|
2020-10-03 13:37:07 +02:00
|
|
|
auto timeoutMsg =
|
2021-04-25 15:44:12 +02:00
|
|
|
MessageBuilder(timeoutMessage, username, durationInSeconds, false,
|
|
|
|
calculateMessageTimestamp(message))
|
2020-10-03 13:37:07 +02:00
|
|
|
.release();
|
2019-09-08 22:27:57 +02:00
|
|
|
chan->addOrReplaceTimeout(timeoutMsg);
|
|
|
|
|
|
|
|
// refresh all
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->windows->repaintVisibleChatWidgets(chan.get());
|
2019-09-08 22:27:57 +02:00
|
|
|
if (getSettings()->hideModerated)
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->windows->forceLayoutChannelViews();
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// check parameter count
|
|
|
|
if (message->parameters().length() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get channel
|
2021-07-17 15:09:21 +02:00
|
|
|
auto chan = getApp()->twitch.server->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[IrcMessageHandler:handleClearMessageMessage] Twitch "
|
|
|
|
"channel"
|
|
|
|
<< chanName << "not found";
|
2019-09-08 22:27:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto tags = message->tags();
|
|
|
|
|
|
|
|
QString targetID = tags.value("target-msg-id").toString();
|
|
|
|
|
2021-06-06 17:51:57 +02:00
|
|
|
auto msg = chan->findMessage(targetID);
|
2021-07-17 15:09:21 +02:00
|
|
|
if (msg == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msg->flags.set(MessageFlag::Disabled);
|
|
|
|
if (!getSettings()->hideDeletionActions)
|
2021-06-06 17:51:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::deletionMessage(msg, &builder);
|
|
|
|
chan->addMessage(builder.release());
|
2021-06-06 17:51:57 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2021-06-20 00:11:06 +02:00
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
// set received emote-sets, used in TwitchAccount::loadUserstateEmotes
|
|
|
|
bool emoteSetsChanged = currentUser->setUserstateEmoteSets(
|
|
|
|
message->tag("emote-sets").toString().split(","));
|
|
|
|
|
|
|
|
if (emoteSetsChanged)
|
|
|
|
{
|
2021-07-17 17:18:17 +02:00
|
|
|
currentUser->loadUserstateEmotes([] {});
|
2021-06-20 00:11:06 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
QString channelName;
|
|
|
|
if (!trimChannelName(message->parameter(0), channelName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-20 00:11:06 +02:00
|
|
|
auto c = getApp()->twitch.server->getChannelOrEmpty(channelName);
|
2019-09-08 22:27:57 +02:00
|
|
|
if (c->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// Checking if currentUser is a VIP or staff member
|
2019-09-08 22:27:57 +02:00
|
|
|
QVariant _badges = message->tag("badges");
|
|
|
|
if (_badges.isValid())
|
|
|
|
{
|
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(c.get());
|
|
|
|
if (tc != nullptr)
|
|
|
|
{
|
|
|
|
auto parsedBadges = parseBadges(_badges.toString());
|
|
|
|
tc->setVIP(parsedBadges.contains("vip"));
|
|
|
|
tc->setStaff(parsedBadges.contains("staff"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// Checking if currentUser is a moderator
|
2019-09-08 22:27:57 +02:00
|
|
|
QVariant _mod = message->tag("mod");
|
|
|
|
if (_mod.isValid())
|
|
|
|
{
|
|
|
|
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(c.get());
|
|
|
|
if (tc != nullptr)
|
|
|
|
{
|
|
|
|
tc->setMod(_mod == "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// This will emit only once and right after user logs in to IRC - reset emote data and reload emotes
|
|
|
|
void IrcMessageHandler::handleGlobalUserStateMessage(
|
|
|
|
Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
// set received emote-sets, this time used to initially load emotes
|
|
|
|
// NOTE: this should always return true unless we reconnect
|
|
|
|
auto emoteSetsChanged = currentUser->setUserstateEmoteSets(
|
|
|
|
message->tag("emote-sets").toString().split(","));
|
|
|
|
|
|
|
|
// We should always attempt to reload emotes even on reconnections where
|
|
|
|
// emoteSetsChanged, since we want to trigger emote reloads when
|
|
|
|
// "currentUserChanged" signal is emitted
|
|
|
|
qCDebug(chatterinoTwitch) << emoteSetsChanged << message->toData();
|
|
|
|
currentUser->loadEmotes();
|
|
|
|
}
|
|
|
|
|
2019-09-08 22:27:57 +02:00
|
|
|
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
MessageParseArgs args;
|
|
|
|
|
|
|
|
args.isReceivedWhisper = true;
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto c = getApp()->twitch.server->whispersChannel.get();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-01-11 01:18:02 +01:00
|
|
|
TwitchMessageBuilder builder(
|
|
|
|
c, message, args,
|
|
|
|
message->parameter(1).replace(COMBINED_FIXER, ZERO_WIDTH_JOINER),
|
|
|
|
false);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (builder.isIgnored())
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
builder->flags.set(MessageFlag::Whisper);
|
|
|
|
MessagePtr _message = builder.build();
|
|
|
|
builder.triggerHighlights();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->twitch.server->lastUserThatWhisperedMe.set(builder.userName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (_message->flags.has(MessageFlag::Highlighted))
|
|
|
|
{
|
|
|
|
getApp()->twitch.server->mentionsChannel->addMessage(_message);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
c->addMessage(_message);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto overrideFlags = boost::optional<MessageFlags>(_message->flags);
|
|
|
|
overrideFlags->set(MessageFlag::DoNotTriggerNotification);
|
|
|
|
overrideFlags->set(MessageFlag::DoNotLog);
|
|
|
|
|
|
|
|
if (getSettings()->inlineWhispers)
|
|
|
|
{
|
|
|
|
getApp()->twitch.server->forEachChannel(
|
|
|
|
[&_message, overrideFlags](ChannelPtr channel) {
|
|
|
|
channel->addMessage(_message, overrideFlags);
|
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
|
|
|
|
Channel *channel, Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
|
|
|
|
auto tags = message->tags();
|
|
|
|
auto parameters = message->parameters();
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
QString msgType = tags.value("msg-id").toString();
|
2019-09-08 22:27:57 +02:00
|
|
|
QString content;
|
|
|
|
if (parameters.size() >= 2)
|
|
|
|
{
|
|
|
|
content = parameters[1];
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:42:51 +02:00
|
|
|
if (specialMessageTypes.contains(msgType))
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// Messages are not required, so they might be empty
|
2019-09-08 22:27:57 +02:00
|
|
|
if (!content.isEmpty())
|
|
|
|
{
|
|
|
|
MessageParseArgs args;
|
|
|
|
args.trimSubscriberUsername = true;
|
|
|
|
|
|
|
|
TwitchMessageBuilder builder(channel, message, args, content,
|
|
|
|
false);
|
|
|
|
builder->flags.set(MessageFlag::Subscription);
|
|
|
|
builder->flags.unset(MessageFlag::Highlighted);
|
|
|
|
builtMessages.emplace_back(builder.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = tags.find("system-msg");
|
|
|
|
|
|
|
|
if (it != tags.end())
|
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// By default, we return value of system-msg tag
|
2021-04-11 14:17:21 +02:00
|
|
|
QString messageText = it.value().toString();
|
|
|
|
|
|
|
|
if (msgType == "bitsbadgetier")
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
messageText =
|
|
|
|
QString("%1 just earned a new %2 Bits badge!")
|
|
|
|
.arg(tags.value("display-name").toString(),
|
|
|
|
kFormatNumbers(
|
|
|
|
tags.value("msg-param-threshold").toInt()));
|
2021-04-11 14:17:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
|
|
|
|
calculateMessageTimestamp(message));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
b->flags.set(MessageFlag::Subscription);
|
|
|
|
auto newMessage = b.release();
|
|
|
|
builtMessages.emplace_back(newMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
2019-09-18 13:03:16 +02:00
|
|
|
TwitchIrcServer &server)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
auto tags = message->tags();
|
|
|
|
auto parameters = message->parameters();
|
|
|
|
|
|
|
|
auto target = parameters[0];
|
2021-07-17 15:09:21 +02:00
|
|
|
QString msgType = tags.value("msg-id").toString();
|
2019-09-08 22:27:57 +02:00
|
|
|
QString content;
|
|
|
|
if (parameters.size() >= 2)
|
|
|
|
{
|
|
|
|
content = parameters[1];
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:42:51 +02:00
|
|
|
if (specialMessageTypes.contains(msgType))
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// Messages are not required, so they might be empty
|
2019-09-08 22:27:57 +02:00
|
|
|
if (!content.isEmpty())
|
|
|
|
{
|
|
|
|
this->addMessage(message, target, content, server, true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = tags.find("system-msg");
|
|
|
|
|
|
|
|
if (it != tags.end())
|
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// By default, we return value of system-msg tag
|
2021-04-11 14:17:21 +02:00
|
|
|
QString messageText = it.value().toString();
|
|
|
|
|
|
|
|
if (msgType == "bitsbadgetier")
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
messageText =
|
|
|
|
QString("%1 just earned a new %2 Bits badge!")
|
|
|
|
.arg(tags.value("display-name").toString(),
|
|
|
|
kFormatNumbers(
|
|
|
|
tags.value("msg-param-threshold").toInt()));
|
2021-04-11 14:17:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
|
|
|
|
calculateMessageTimestamp(message));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
b->flags.set(MessageFlag::Subscription);
|
|
|
|
auto newMessage = b.release();
|
|
|
|
|
|
|
|
QString channelName;
|
|
|
|
|
|
|
|
if (message->parameters().size() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!trimChannelName(message->parameter(0), channelName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto chan = server.getChannelOrEmpty(channelName);
|
|
|
|
|
|
|
|
if (!chan->isEmpty())
|
|
|
|
{
|
|
|
|
chan->addMessage(newMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MessagePtr> IrcMessageHandler::parseNoticeMessage(
|
|
|
|
Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
|
|
|
if (message->content().startsWith("Login auth", Qt::CaseInsensitive))
|
|
|
|
{
|
2020-10-04 17:36:38 +02:00
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
|
|
|
|
const auto curUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
const auto expirationText = QString("Login expired for user \"%1\"!")
|
|
|
|
.arg(curUser->getUserName());
|
2021-07-11 12:19:35 +02:00
|
|
|
const auto loginPromptText = QString("Try adding your account again.");
|
2020-10-04 17:36:38 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
auto text = QString("%1 %2").arg(expirationText, loginPromptText);
|
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2020-10-04 17:36:38 +02:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
2021-05-08 13:34:32 +02:00
|
|
|
builder.message().flags.set(MessageFlag::DoNotTriggerNotification);
|
2020-10-04 17:36:38 +02:00
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
|
|
|
|
linkColor)
|
|
|
|
->setLink(accountsLink);
|
|
|
|
|
|
|
|
return {builder.release()};
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
2020-12-12 14:19:51 +01:00
|
|
|
else if (message->content().startsWith("You are permanently banned "))
|
|
|
|
{
|
|
|
|
return {generateBannedMessage(true)};
|
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
else if (message->tags().value("msg-id") == "msg_timedout")
|
2021-01-31 13:55:44 +01:00
|
|
|
{
|
2021-03-07 18:03:53 +01:00
|
|
|
std::vector<MessagePtr> builtMessage;
|
2021-01-31 13:55:44 +01:00
|
|
|
|
2021-03-07 18:03:53 +01:00
|
|
|
QString remainingTime =
|
|
|
|
formatTime(message->content().split(" ").value(5));
|
|
|
|
QString formattedMessage =
|
|
|
|
QString("You are timed out for %1.")
|
|
|
|
.arg(remainingTime.isEmpty() ? "0s" : remainingTime);
|
2021-01-31 13:55:44 +01:00
|
|
|
|
2021-03-07 18:03:53 +01:00
|
|
|
builtMessage.emplace_back(makeSystemMessage(
|
|
|
|
formattedMessage, calculateMessageTimestamp(message)));
|
2021-01-31 13:55:44 +01:00
|
|
|
|
2021-03-07 18:03:53 +01:00
|
|
|
return builtMessage;
|
2021-01-31 13:55:44 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
// default case
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
builtMessages.emplace_back(makeSystemMessage(
|
|
|
|
message->content(), calculateMessageTimestamp(message)));
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
|
|
|
auto builtMessages = this->parseNoticeMessage(message);
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
for (const auto &msg : builtMessages)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
QString channelName;
|
|
|
|
if (!trimChannelName(message->target(), channelName) ||
|
|
|
|
channelName == "jtv")
|
|
|
|
{
|
|
|
|
// Notice wasn't targeted at a single channel, send to all twitch
|
|
|
|
// channels
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->twitch.server->forEachChannelAndSpecialChannels(
|
2019-09-08 22:27:57 +02:00
|
|
|
[msg](const auto &c) {
|
2020-11-08 12:02:19 +01:00
|
|
|
c->addMessage(msg);
|
2019-09-08 22:27:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto channel = getApp()->twitch.server->getChannelOrEmpty(channelName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
|
|
|
if (channel->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[IrcManager:handleNoticeMessage] Channel" << channelName
|
|
|
|
<< "not found in channel manager";
|
2019-09-08 22:27:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
QString tags = message->tags().value("msg-id").toString();
|
2021-11-13 13:34:04 +01:00
|
|
|
if (tags == "usage_delete")
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
|
|
|
channel->addMessage(makeSystemMessage(
|
2021-11-13 13:34:04 +01:00
|
|
|
"Usage: /delete <msg-id> - Deletes the specified message. "
|
|
|
|
"Can't take more than one argument."));
|
|
|
|
}
|
|
|
|
else if (tags == "bad_delete_message_error")
|
|
|
|
{
|
|
|
|
channel->addMessage(makeSystemMessage(
|
|
|
|
"There was a problem deleting the message. "
|
|
|
|
"It might be from another channel or too old to delete."));
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
2021-06-27 15:50:12 +02:00
|
|
|
else if (tags == "host_on" || tags == "host_target_went_offline")
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
2021-06-27 15:50:12 +02:00
|
|
|
bool hostOn = (tags == "host_on");
|
2021-05-08 16:46:41 +02:00
|
|
|
QStringList parts = msg->messageText.split(QLatin1Char(' '));
|
2021-06-27 15:50:12 +02:00
|
|
|
if ((hostOn && parts.size() != 3) || (!hostOn && parts.size() != 7))
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-11-27 14:51:37 +01:00
|
|
|
auto &hostedChannelName = hostOn ? parts[2] : parts[0];
|
|
|
|
if (hostedChannelName.size() < 2)
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-06-27 15:50:12 +02:00
|
|
|
if (hostOn)
|
|
|
|
{
|
2021-11-27 14:51:37 +01:00
|
|
|
hostedChannelName.chop(1);
|
2021-06-27 15:50:12 +02:00
|
|
|
}
|
2021-05-08 16:46:41 +02:00
|
|
|
MessageBuilder builder;
|
2021-11-27 14:51:37 +01:00
|
|
|
TwitchMessageBuilder::hostingSystemMessage(hostedChannelName,
|
|
|
|
&builder, hostOn);
|
2021-05-08 16:46:41 +02:00
|
|
|
channel->addMessage(builder.release());
|
|
|
|
}
|
2021-10-24 15:28:43 +02:00
|
|
|
else if (tags == "room_mods" || tags == "vips_success")
|
|
|
|
{
|
|
|
|
// /mods and /vips
|
|
|
|
// room_mods: The moderators of this channel are: ampzyh, antichriststollen, apa420, ...
|
|
|
|
// vips_success: The VIPs of this channel are: 8008, aiden, botfactory, ...
|
|
|
|
|
|
|
|
QString noticeText = msg->messageText;
|
|
|
|
if (tags == "vips_success")
|
|
|
|
{
|
|
|
|
// this one has a trailing period, need to get rid of it.
|
|
|
|
noticeText.chop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList msgParts = noticeText.split(':');
|
|
|
|
MessageBuilder builder;
|
|
|
|
|
|
|
|
auto tc = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
assert(tc != nullptr &&
|
|
|
|
"IrcMessageHandler::handleNoticeMessage. Twitch specific "
|
|
|
|
"functionality called in non twitch channel");
|
|
|
|
|
2021-11-13 12:11:18 +01:00
|
|
|
auto users = msgParts.at(1)
|
|
|
|
.mid(1) // there is a space before the first user
|
|
|
|
.split(", ");
|
2021-11-20 14:53:05 +01:00
|
|
|
TwitchMessageBuilder::listOfUsersSystemMessage(msgParts.at(0),
|
|
|
|
users, tc, &builder);
|
2021-10-24 15:28:43 +02:00
|
|
|
channel->addMessage(builder.release());
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
channel->addMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
auto channel = getApp()->twitch.server->getChannelOrEmpty(
|
2019-09-08 22:27:57 +02:00
|
|
|
message->parameter(0).remove(0, 1));
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
if (!twitchChannel)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->nick() !=
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName() &&
|
|
|
|
getSettings()->showJoins.getValue())
|
|
|
|
{
|
|
|
|
twitchChannel->addJoinedUser(message->nick());
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
auto channel = getApp()->twitch.server->getChannelOrEmpty(
|
2019-09-08 22:27:57 +02:00
|
|
|
message->parameter(0).remove(0, 1));
|
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
if (!twitchChannel)
|
2019-09-08 22:27:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-12-12 14:19:51 +01:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
const auto selfAccountName =
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName();
|
|
|
|
if (message->nick() != selfAccountName &&
|
|
|
|
getSettings()->showParts.getValue())
|
|
|
|
{
|
|
|
|
twitchChannel->addPartedUser(message->nick());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->nick() == selfAccountName)
|
|
|
|
{
|
|
|
|
channel->addMessage(generateBannedMessage(false));
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace chatterino
|