2018-01-01 23:54:54 +01:00
|
|
|
#include "ircmessagehandler.hpp"
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include "application.hpp"
|
2018-01-01 23:54:54 +01:00
|
|
|
#include "debug/log.hpp"
|
|
|
|
#include "messages/limitedqueue.hpp"
|
|
|
|
#include "messages/message.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchchannel.hpp"
|
2018-03-25 11:37:57 +02:00
|
|
|
#include "providers/twitch/twitchhelpers.hpp"
|
2018-02-05 21:20:38 +01:00
|
|
|
#include "providers/twitch/twitchmessagebuilder.hpp"
|
|
|
|
#include "providers/twitch/twitchserver.hpp"
|
2018-01-01 23:54:54 +01:00
|
|
|
#include "singletons/resourcemanager.hpp"
|
|
|
|
#include "singletons/windowmanager.hpp"
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
using namespace chatterino::singletons;
|
2018-01-01 23:54:54 +01:00
|
|
|
using namespace chatterino::messages;
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-02-05 15:11:50 +01:00
|
|
|
namespace providers {
|
|
|
|
namespace twitch {
|
2018-01-01 23:54:54 +01:00
|
|
|
|
|
|
|
IrcMessageHandler &IrcMessageHandler::getInstance()
|
|
|
|
{
|
2018-04-14 21:59:51 +02:00
|
|
|
static IrcMessageHandler instance;
|
2018-01-01 23:54:54 +01:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
const auto &tags = message->tags();
|
2018-05-24 08:58:34 +02:00
|
|
|
auto app = getApp();
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
// get twitch channel
|
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
|
|
|
|
TwitchChannel *twitchChannel = dynamic_cast<twitch::TwitchChannel *>(chan.get());
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
if (twitchChannel) {
|
|
|
|
// room-id
|
|
|
|
decltype(tags.find("xD")) it;
|
2018-02-05 15:11:50 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
if ((it = tags.find("room-id")) != tags.end()) {
|
|
|
|
auto roomID = it.value().toString();
|
2018-04-28 15:20:18 +02:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
twitchChannel->setRoomID(roomID);
|
2018-02-05 15:11:50 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
app->resources->loadChannelData(roomID);
|
|
|
|
}
|
2018-02-05 15:11:50 +01:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
// Room modes
|
|
|
|
TwitchChannel::RoomModes roomModes = twitchChannel->getRoomModes();
|
2018-04-21 00:40:17 +02:00
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
if ((it = tags.find("emote-only")) != tags.end()) {
|
|
|
|
roomModes.emoteOnly = it.value() == "1";
|
2018-04-21 00:40:17 +02:00
|
|
|
}
|
2018-05-24 08:58:34 +02:00
|
|
|
if ((it = tags.find("subs-only")) != tags.end()) {
|
|
|
|
roomModes.submode = it.value() == "1";
|
|
|
|
}
|
|
|
|
if ((it = tags.find("slow")) != tags.end()) {
|
|
|
|
roomModes.slowMode = it.value().toInt();
|
|
|
|
}
|
|
|
|
if ((it = tags.find("r9k")) != tags.end()) {
|
|
|
|
roomModes.r9k = it.value() == "1";
|
|
|
|
}
|
|
|
|
if ((it = tags.find("broadcaster-lang")) != tags.end()) {
|
|
|
|
roomModes.broadcasterLang = it.value().toString();
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
2018-05-24 08:58:34 +02:00
|
|
|
twitchChannel->setRoomModes(roomModes);
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2018-05-17 13:43:01 +02:00
|
|
|
// check parameter count
|
|
|
|
if (message->parameters().length() < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString chanName;
|
2018-05-24 08:58:34 +02:00
|
|
|
if (!trimChannelName(message->parameter(0), chanName)) {
|
2018-05-17 13:43:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
// get channel
|
|
|
|
auto chan = app->twitch.server->getChannelOrEmpty(chanName);
|
|
|
|
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
debug::Log("[IrcMessageHandler:handleClearChatMessage] Twitch channel {} not found",
|
|
|
|
chanName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the chat has been cleared by a moderator
|
|
|
|
if (message->parameters().length() == 1) {
|
|
|
|
chan->addMessage(Message::createSystemMessage("Chat has been cleared by a moderator."));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get username, duration and message of the timed out user
|
|
|
|
QString username = message->parameter(1);
|
|
|
|
QString durationInSeconds, reason;
|
|
|
|
QVariant v = message->tag("ban-duration");
|
|
|
|
if (v.isValid()) {
|
|
|
|
durationInSeconds = v.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
v = message->tag("ban-reason");
|
|
|
|
if (v.isValid()) {
|
|
|
|
reason = v.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto timeoutMsg = Message::createTimeoutMessage(username, durationInSeconds, reason, false);
|
|
|
|
chan->addOrReplaceTimeout(timeoutMsg);
|
|
|
|
|
|
|
|
// refresh all
|
|
|
|
app->windows->repaintVisibleChatWidgets(chan.get());
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2018-01-17 18:36:12 +01:00
|
|
|
QVariant _mod = message->tag("mod");
|
|
|
|
|
|
|
|
if (_mod.isValid()) {
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
2018-03-25 11:37:57 +02:00
|
|
|
QString channelName;
|
2018-05-24 08:58:34 +02:00
|
|
|
if (!trimChannelName(message->parameter(0), channelName)) {
|
2018-03-25 11:37:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-01-17 18:36:12 +01:00
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
auto c = app->twitch.server->getChannelOrEmpty(channelName);
|
2018-04-21 00:40:17 +02:00
|
|
|
if (c->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-17 18:36:12 +01:00
|
|
|
twitch::TwitchChannel *tc = dynamic_cast<twitch::TwitchChannel *>(c.get());
|
|
|
|
if (tc != nullptr) {
|
|
|
|
tc->setMod(_mod == "1");
|
|
|
|
}
|
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-02-04 16:33:46 +01:00
|
|
|
debug::Log("Received whisper!");
|
|
|
|
messages::MessageParseArgs args;
|
|
|
|
|
|
|
|
args.isReceivedWhisper = true;
|
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
auto c = app->twitch.server->whispersChannel.get();
|
2018-02-04 16:33:46 +01:00
|
|
|
|
|
|
|
twitch::TwitchMessageBuilder builder(c, message, message->parameter(1), args);
|
|
|
|
|
|
|
|
if (!builder.isIgnored()) {
|
|
|
|
messages::MessagePtr _message = builder.build();
|
2018-04-18 20:38:08 +02:00
|
|
|
_message->flags |= messages::Message::DoNotTriggerNotification;
|
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
if (_message->flags & messages::Message::Highlighted) {
|
2018-04-28 15:20:18 +02:00
|
|
|
app->twitch.server->mentionsChannel->addMessage(_message);
|
2018-02-04 16:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
c->addMessage(_message);
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
if (app->settings->inlineWhispers) {
|
2018-04-28 15:20:18 +02:00
|
|
|
app->twitch.server->forEachChannel([_message](ChannelPtr channel) {
|
2018-02-04 16:33:46 +01:00
|
|
|
channel->addMessage(_message); //
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2018-04-28 15:20:18 +02:00
|
|
|
auto app = getApp();
|
|
|
|
|
|
|
|
auto channel = app->twitch.server->getChannelOrEmpty(message->parameter(0).remove(0, 1));
|
2018-04-21 00:40:17 +02:00
|
|
|
|
|
|
|
if (channel->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-05 15:11:50 +01:00
|
|
|
|
2018-01-01 23:54:54 +01:00
|
|
|
if (message->parameter(1) == "+o") {
|
|
|
|
channel->modList.append(message->parameter(2));
|
|
|
|
} else if (message->parameter(1) == "-o") {
|
|
|
|
channel->modList.append(message->parameter(2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
2018-04-29 13:24:37 +02:00
|
|
|
return;
|
2018-05-06 12:52:47 +02:00
|
|
|
// auto app = getApp();
|
|
|
|
// MessagePtr msg = Message::createSystemMessage(message->content());
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
// QString channelName;
|
|
|
|
// if (!TrimChannelName(message->target(), channelName)) {
|
|
|
|
// // Notice wasn't targeted at a single channel, send to all twitch channels
|
|
|
|
// app->twitch.server->forEachChannelAndSpecialChannels([msg](const auto &c) {
|
|
|
|
// c->addMessage(msg); //
|
|
|
|
// });
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
// return;
|
|
|
|
// }
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
// auto channel = app->twitch.server->getChannelOrEmpty(channelName);
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
// if (channel->isEmpty()) {
|
2018-05-24 08:58:34 +02:00
|
|
|
// debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel
|
|
|
|
// manager",
|
2018-05-06 12:52:47 +02:00
|
|
|
// channelName);
|
|
|
|
// return;
|
|
|
|
// }
|
2018-01-01 23:54:54 +01:00
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
// channel->addMessage(msg);
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
|
|
|
QVariant v = message->tag("msg-id");
|
|
|
|
if (!v.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString msg_id = v.toString();
|
|
|
|
|
|
|
|
static QList<QString> idsToSkip = {"timeout_success", "ban_success"};
|
|
|
|
|
|
|
|
if (idsToSkip.contains(msg_id)) {
|
|
|
|
// Already handled in the read-connection
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->handleNoticeMessage(message);
|
|
|
|
}
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace twitch
|
|
|
|
} // namespace providers
|
2018-01-17 02:22:57 +01:00
|
|
|
} // namespace chatterino
|