mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
make helper function for trimming a twitch channel name from irc
This commit is contained in:
parent
dc578a5f29
commit
4790f68557
7 changed files with 68 additions and 24 deletions
|
@ -176,7 +176,8 @@ SOURCES += \
|
||||||
src/providers/irc/ircaccount.cpp \
|
src/providers/irc/ircaccount.cpp \
|
||||||
src/providers/irc/ircserver.cpp \
|
src/providers/irc/ircserver.cpp \
|
||||||
src/providers/irc/ircchannel2.cpp \
|
src/providers/irc/ircchannel2.cpp \
|
||||||
src/util/streamlink.cpp
|
src/util/streamlink.cpp \
|
||||||
|
src/providers/twitch/twitchhelpers.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/precompiled_header.hpp \
|
src/precompiled_header.hpp \
|
||||||
|
@ -289,7 +290,8 @@ HEADERS += \
|
||||||
src/providers/irc/ircaccount.hpp \
|
src/providers/irc/ircaccount.hpp \
|
||||||
src/providers/irc/ircserver.hpp \
|
src/providers/irc/ircserver.hpp \
|
||||||
src/providers/irc/ircchannel2.hpp \
|
src/providers/irc/ircchannel2.hpp \
|
||||||
src/util/streamlink.hpp
|
src/util/streamlink.hpp \
|
||||||
|
src/providers/twitch/twitchhelpers.hpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources/resources.qrc
|
resources/resources.qrc
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "messages/limitedqueue.hpp"
|
#include "messages/limitedqueue.hpp"
|
||||||
#include "messages/message.hpp"
|
#include "messages/message.hpp"
|
||||||
#include "providers/twitch/twitchchannel.hpp"
|
#include "providers/twitch/twitchchannel.hpp"
|
||||||
|
#include "providers/twitch/twitchhelpers.hpp"
|
||||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||||
#include "providers/twitch/twitchserver.hpp"
|
#include "providers/twitch/twitchserver.hpp"
|
||||||
#include "singletons/resourcemanager.hpp"
|
#include "singletons/resourcemanager.hpp"
|
||||||
|
@ -59,16 +60,14 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
||||||
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
{
|
{
|
||||||
// check parameter count
|
// check parameter count
|
||||||
if (message->parameters().length() < 1)
|
if (message->parameters().length() < 1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString chanName = message->parameter(0);
|
QString chanName;
|
||||||
|
if (!TrimChannelName(message->parameter(0), chanName)) {
|
||||||
// check channel name length
|
|
||||||
if (chanName.length() >= 2)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
chanName = chanName.mid(1);
|
|
||||||
|
|
||||||
// get channel
|
// get channel
|
||||||
auto chan = TwitchServer::getInstance().getChannel(chanName);
|
auto chan = TwitchServer::getInstance().getChannel(chanName);
|
||||||
|
@ -86,8 +85,6 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(message->parameters().length() >= 2);
|
|
||||||
|
|
||||||
// get username, duration and message of the timed out user
|
// get username, duration and message of the timed out user
|
||||||
QString username = message->parameter(1);
|
QString username = message->parameter(1);
|
||||||
QString durationInSeconds, reason;
|
QString durationInSeconds, reason;
|
||||||
|
@ -136,10 +133,12 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
||||||
QVariant _mod = message->tag("mod");
|
QVariant _mod = message->tag("mod");
|
||||||
|
|
||||||
if (_mod.isValid()) {
|
if (_mod.isValid()) {
|
||||||
auto rawChannelName = message->parameters().at(0);
|
QString channelName;
|
||||||
auto trimmedChannelName = rawChannelName.mid(1);
|
if (!TrimChannelName(message->parameter(0), channelName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto c = TwitchServer::getInstance().getChannel(trimmedChannelName);
|
auto c = TwitchServer::getInstance().getChannel(channelName);
|
||||||
twitch::TwitchChannel *tc = dynamic_cast<twitch::TwitchChannel *>(c.get());
|
twitch::TwitchChannel *tc = dynamic_cast<twitch::TwitchChannel *>(c.get());
|
||||||
if (tc != nullptr) {
|
if (tc != nullptr) {
|
||||||
tc->setMod(_mod == "1");
|
tc->setMod(_mod == "1");
|
||||||
|
@ -192,13 +191,11 @@ void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
|
||||||
|
|
||||||
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
{
|
{
|
||||||
auto rawChannelName = message->target();
|
|
||||||
|
|
||||||
bool broadcast = rawChannelName.length() < 2;
|
|
||||||
MessagePtr msg = Message::createSystemMessage(message->content());
|
MessagePtr msg = Message::createSystemMessage(message->content());
|
||||||
|
|
||||||
if (broadcast) {
|
QString channelName;
|
||||||
// fourtf: send to all twitch channels
|
if (!TrimChannelName(message->target(), channelName)) {
|
||||||
|
// Notice wasn't targeted at a single channel, send to all twitch channels
|
||||||
TwitchServer::getInstance().forEachChannelAndSpecialChannels([msg](const auto &c) {
|
TwitchServer::getInstance().forEachChannelAndSpecialChannels([msg](const auto &c) {
|
||||||
c->addMessage(msg); //
|
c->addMessage(msg); //
|
||||||
});
|
});
|
||||||
|
@ -206,13 +203,11 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto trimmedChannelName = rawChannelName.mid(1);
|
auto channel = TwitchServer::getInstance().getChannel(channelName);
|
||||||
|
|
||||||
auto channel = TwitchServer::getInstance().getChannel(trimmedChannelName);
|
|
||||||
|
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
|
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
|
||||||
trimmedChannelName);
|
channelName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class ResourceManager;
|
||||||
|
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
|
||||||
class IrcMessageHandler
|
class IrcMessageHandler
|
||||||
{
|
{
|
||||||
IrcMessageHandler(singletons::ResourceManager &resourceManager);
|
IrcMessageHandler(singletons::ResourceManager &resourceManager);
|
||||||
|
@ -28,6 +29,7 @@ public:
|
||||||
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||||
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
|
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace twitch
|
} // namespace twitch
|
||||||
} // namespace providers
|
} // namespace providers
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
22
src/providers/twitch/twitchhelpers.cpp
Normal file
22
src/providers/twitch/twitchhelpers.cpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include "providers/twitch/twitchhelpers.hpp"
|
||||||
|
#include "debug/log.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace providers {
|
||||||
|
namespace twitch {
|
||||||
|
|
||||||
|
bool TrimChannelName(const QString &channelName, QString &outChannelName)
|
||||||
|
{
|
||||||
|
if (channelName.length() < 3) {
|
||||||
|
debug::Log("channel name length below 2");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outChannelName = channelName.mid(1);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace twitch
|
||||||
|
} // namespace providers
|
||||||
|
} // namespace chatterino
|
13
src/providers/twitch/twitchhelpers.hpp
Normal file
13
src/providers/twitch/twitchhelpers.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace providers {
|
||||||
|
namespace twitch {
|
||||||
|
|
||||||
|
bool TrimChannelName(const QString &channelName, QString &outChannelName);
|
||||||
|
|
||||||
|
} // namespace twitch
|
||||||
|
} // namespace providers
|
||||||
|
} // namespace chatterino
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "providers/twitch/ircmessagehandler.hpp"
|
#include "providers/twitch/ircmessagehandler.hpp"
|
||||||
#include "providers/twitch/twitchaccount.hpp"
|
#include "providers/twitch/twitchaccount.hpp"
|
||||||
|
#include "providers/twitch/twitchhelpers.hpp"
|
||||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||||
#include "singletons/accountmanager.hpp"
|
#include "singletons/accountmanager.hpp"
|
||||||
#include "util/posttothread.hpp"
|
#include "util/posttothread.hpp"
|
||||||
|
@ -14,6 +15,7 @@ using namespace chatterino::singletons;
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
|
||||||
TwitchServer::TwitchServer()
|
TwitchServer::TwitchServer()
|
||||||
: whispersChannel(new Channel("/mentions"))
|
: whispersChannel(new Channel("/mentions"))
|
||||||
, mentionsChannel(new Channel("/mentions"))
|
, mentionsChannel(new Channel("/mentions"))
|
||||||
|
@ -72,8 +74,13 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||||
|
|
||||||
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
|
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
|
||||||
{
|
{
|
||||||
|
QString channelName;
|
||||||
|
if (!TrimChannelName(message->target(), channelName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->onPrivateMessage.invoke(message);
|
this->onPrivateMessage.invoke(message);
|
||||||
auto chan = TwitchServer::getInstance().getChannel(message->target().mid(1));
|
auto chan = TwitchServer::getInstance().getChannel(channelName);
|
||||||
|
|
||||||
if (!chan) {
|
if (!chan) {
|
||||||
return;
|
return;
|
||||||
|
@ -163,6 +170,7 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
|
||||||
func(this->whispersChannel);
|
func(this->whispersChannel);
|
||||||
func(this->mentionsChannel);
|
func(this->mentionsChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace twitch
|
} // namespace twitch
|
||||||
} // namespace providers
|
} // namespace providers
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace providers {
|
namespace providers {
|
||||||
namespace twitch {
|
namespace twitch {
|
||||||
|
|
||||||
class TwitchServer final : public irc::AbstractIrcServer
|
class TwitchServer final : public irc::AbstractIrcServer
|
||||||
{
|
{
|
||||||
TwitchServer();
|
TwitchServer();
|
||||||
|
@ -33,6 +34,7 @@ protected:
|
||||||
|
|
||||||
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
|
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace twitch
|
} // namespace twitch
|
||||||
} // namespace providers
|
} // namespace providers
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
Loading…
Reference in a new issue