Change in which "message received" handler IRC commands are handled after the change in CAP REQs.

Fixes #1252
This commit is contained in:
Rasmus Karlsson 2019-08-31 17:41:49 +02:00
parent 671c9ed654
commit 829c63be51
3 changed files with 38 additions and 85 deletions

View file

@ -582,49 +582,6 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
} }
} }
void IrcMessageHandler::handleWriteConnectionNoticeMessage(
Communi::IrcNoticeMessage *message)
{
static std::unordered_set<std::string> readConnectionOnlyIDs{
"host_on",
"host_off",
"host_target_went_offline",
"emote_only_on",
"emote_only_off",
"slow_on",
"slow_off",
"subs_on",
"subs_off",
"r9k_on",
"r9k_off",
// Display for user who times someone out. This implies you're a
// moderator, at which point you will be connected to PubSub and receive
// a better message from there
"timeout_success",
"ban_success",
// Channel suspended notices
"msg_channel_suspended",
};
QVariant v = message->tag("msg-id");
if (v.isValid())
{
std::string msgID = v.toString().toStdString();
if (readConnectionOnlyIDs.find(msgID) != readConnectionOnlyIDs.end())
{
return;
}
log("Showing notice message from write connection with message id '{}'",
msgID);
}
this->handleNoticeMessage(message);
}
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
{ {
auto app = getApp(); auto app = getApp();

View file

@ -46,8 +46,6 @@ public:
Communi::IrcNoticeMessage *message); Communi::IrcNoticeMessage *message);
void handleNoticeMessage(Communi::IrcNoticeMessage *message); void handleNoticeMessage(Communi::IrcNoticeMessage *message);
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
void handleJoinMessage(Communi::IrcMessage *message); void handleJoinMessage(Communi::IrcMessage *message);
void handlePartMessage(Communi::IrcMessage *message); void handlePartMessage(Communi::IrcMessage *message);

View file

@ -130,7 +130,6 @@ void TwitchServer::privateMessageReceived(Communi::IrcPrivateMessage *message)
void TwitchServer::messageReceived(Communi::IrcMessage *message) void TwitchServer::messageReceived(Communi::IrcMessage *message)
{ {
// this->readConnection
if (message->type() == Communi::IrcMessage::Type::Private) if (message->type() == Communi::IrcMessage::Type::Private)
{ {
// We already have a handler for private messages // We already have a handler for private messages
@ -141,39 +140,11 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message)
auto &handler = IrcMessageHandler::getInstance(); auto &handler = IrcMessageHandler::getInstance();
if (command == "ROOMSTATE") // Below commands enabled through the twitch.tv/membership CAP REQ
{ if (command == "MODE")
handler.handleRoomStateMessage(message);
}
else if (command == "CLEARCHAT")
{
handler.handleClearChatMessage(message);
}
else if (command == "CLEARMSG")
{
handler.handleClearMessageMessage(message);
}
else if (command == "USERSTATE")
{
handler.handleUserStateMessage(message);
}
else if (command == "WHISPER")
{
handler.handleWhisperMessage(message);
}
else if (command == "USERNOTICE")
{
handler.handleUserNoticeMessage(message, *this);
}
else if (command == "MODE")
{ {
handler.handleModeMessage(message); handler.handleModeMessage(message);
} }
else if (command == "NOTICE")
{
handler.handleNoticeMessage(
static_cast<Communi::IrcNoticeMessage *>(message));
}
else if (command == "JOIN") else if (command == "JOIN")
{ {
handler.handleJoinMessage(message); handler.handleJoinMessage(message);
@ -186,16 +157,39 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message)
void TwitchServer::writeConnectionMessageReceived(Communi::IrcMessage *message) void TwitchServer::writeConnectionMessageReceived(Communi::IrcMessage *message)
{ {
switch (message->type()) const QString &command = message->command();
{
case Communi::IrcMessage::Type::Notice:
{
IrcMessageHandler::getInstance().handleWriteConnectionNoticeMessage(
static_cast<Communi::IrcNoticeMessage *>(message));
}
break;
default:; auto &handler = IrcMessageHandler::getInstance();
// Below commands enabled through the twitch.tv/commands CAP REQ
if (command == "USERSTATE")
{
handler.handleUserStateMessage(message);
}
else if (command == "WHISPER")
{
handler.handleWhisperMessage(message);
}
else if (command == "USERNOTICE")
{
handler.handleUserNoticeMessage(message, *this);
}
else if (command == "ROOMSTATE")
{
handler.handleRoomStateMessage(message);
}
else if (command == "CLEARCHAT")
{
handler.handleClearChatMessage(message);
}
else if (command == "CLEARMSG")
{
handler.handleClearMessageMessage(message);
}
else if (command == "NOTICE")
{
handler.handleNoticeMessage(
static_cast<Communi::IrcNoticeMessage *>(message));
} }
} }
@ -203,6 +197,8 @@ void TwitchServer::onReadConnected(IrcConnection *connection)
{ {
AbstractIrcServer::onReadConnected(connection); AbstractIrcServer::onReadConnected(connection);
// twitch.tv/tags enables IRCv3 tags on messages. See https://dev.twitch.tv/docs/irc/tags/
// twitch.tv/membership enables the JOIN/PART/MODE/NAMES commands. See https://dev.twitch.tv/docs/irc/membership/
connection->sendRaw("CAP REQ :twitch.tv/tags twitch.tv/membership"); connection->sendRaw("CAP REQ :twitch.tv/tags twitch.tv/membership");
} }
@ -210,6 +206,8 @@ void TwitchServer::onWriteConnected(IrcConnection *connection)
{ {
AbstractIrcServer::onWriteConnected(connection); AbstractIrcServer::onWriteConnected(connection);
// twitch.tv/tags enables IRCv3 tags on messages. See https://dev.twitch.tv/docs/irc/tags/
// twitch.tv/commands enables a bunch of miscellaneous command capabilities. See https://dev.twitch.tv/docs/irc/commands/
connection->sendRaw("CAP REQ :twitch.tv/tags twitch.tv/commands"); connection->sendRaw("CAP REQ :twitch.tv/tags twitch.tv/commands");
} }