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
9886021c6a
commit
6e1096710d
7 changed files with 68 additions and 24 deletions
|
@ -176,7 +176,8 @@ SOURCES += \
|
|||
src/providers/irc/ircaccount.cpp \
|
||||
src/providers/irc/ircserver.cpp \
|
||||
src/providers/irc/ircchannel2.cpp \
|
||||
src/util/streamlink.cpp
|
||||
src/util/streamlink.cpp \
|
||||
src/providers/twitch/twitchhelpers.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/precompiled_header.hpp \
|
||||
|
@ -289,7 +290,8 @@ HEADERS += \
|
|||
src/providers/irc/ircaccount.hpp \
|
||||
src/providers/irc/ircserver.hpp \
|
||||
src/providers/irc/ircchannel2.hpp \
|
||||
src/util/streamlink.hpp
|
||||
src/util/streamlink.hpp \
|
||||
src/providers/twitch/twitchhelpers.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "messages/limitedqueue.hpp"
|
||||
#include "messages/message.hpp"
|
||||
#include "providers/twitch/twitchchannel.hpp"
|
||||
#include "providers/twitch/twitchhelpers.hpp"
|
||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||
#include "providers/twitch/twitchserver.hpp"
|
||||
#include "singletons/resourcemanager.hpp"
|
||||
|
@ -59,16 +60,14 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
|||
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
// check parameter count
|
||||
if (message->parameters().length() < 1)
|
||||
if (message->parameters().length() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString chanName = message->parameter(0);
|
||||
|
||||
// check channel name length
|
||||
if (chanName.length() >= 2)
|
||||
QString chanName;
|
||||
if (!TrimChannelName(message->parameter(0), chanName)) {
|
||||
return;
|
||||
|
||||
chanName = chanName.mid(1);
|
||||
}
|
||||
|
||||
// get channel
|
||||
auto chan = TwitchServer::getInstance().getChannel(chanName);
|
||||
|
@ -86,8 +85,6 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
|||
return;
|
||||
}
|
||||
|
||||
assert(message->parameters().length() >= 2);
|
||||
|
||||
// get username, duration and message of the timed out user
|
||||
QString username = message->parameter(1);
|
||||
QString durationInSeconds, reason;
|
||||
|
@ -136,10 +133,12 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
|||
QVariant _mod = message->tag("mod");
|
||||
|
||||
if (_mod.isValid()) {
|
||||
auto rawChannelName = message->parameters().at(0);
|
||||
auto trimmedChannelName = rawChannelName.mid(1);
|
||||
QString channelName;
|
||||
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());
|
||||
if (tc != nullptr) {
|
||||
tc->setMod(_mod == "1");
|
||||
|
@ -192,13 +191,11 @@ void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
|
|||
|
||||
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||
{
|
||||
auto rawChannelName = message->target();
|
||||
|
||||
bool broadcast = rawChannelName.length() < 2;
|
||||
MessagePtr msg = Message::createSystemMessage(message->content());
|
||||
|
||||
if (broadcast) {
|
||||
// fourtf: send to all twitch channels
|
||||
QString channelName;
|
||||
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) {
|
||||
c->addMessage(msg); //
|
||||
});
|
||||
|
@ -206,13 +203,11 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
|||
return;
|
||||
}
|
||||
|
||||
auto trimmedChannelName = rawChannelName.mid(1);
|
||||
|
||||
auto channel = TwitchServer::getInstance().getChannel(trimmedChannelName);
|
||||
auto channel = TwitchServer::getInstance().getChannel(channelName);
|
||||
|
||||
if (!channel) {
|
||||
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
|
||||
trimmedChannelName);
|
||||
channelName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ class ResourceManager;
|
|||
|
||||
namespace providers {
|
||||
namespace twitch {
|
||||
|
||||
class IrcMessageHandler
|
||||
{
|
||||
IrcMessageHandler(singletons::ResourceManager &resourceManager);
|
||||
|
@ -28,6 +29,7 @@ public:
|
|||
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||
};
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // 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/twitchaccount.hpp"
|
||||
#include "providers/twitch/twitchhelpers.hpp"
|
||||
#include "providers/twitch/twitchmessagebuilder.hpp"
|
||||
#include "singletons/accountmanager.hpp"
|
||||
#include "util/posttothread.hpp"
|
||||
|
@ -14,6 +15,7 @@ using namespace chatterino::singletons;
|
|||
namespace chatterino {
|
||||
namespace providers {
|
||||
namespace twitch {
|
||||
|
||||
TwitchServer::TwitchServer()
|
||||
: whispersChannel(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)
|
||||
{
|
||||
QString channelName;
|
||||
if (!TrimChannelName(message->target(), channelName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->onPrivateMessage.invoke(message);
|
||||
auto chan = TwitchServer::getInstance().getChannel(message->target().mid(1));
|
||||
auto chan = TwitchServer::getInstance().getChannel(channelName);
|
||||
|
||||
if (!chan) {
|
||||
return;
|
||||
|
@ -163,6 +170,7 @@ void TwitchServer::forEachChannelAndSpecialChannels(std::function<void(ChannelPt
|
|||
func(this->whispersChannel);
|
||||
func(this->mentionsChannel);
|
||||
}
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
namespace chatterino {
|
||||
namespace providers {
|
||||
namespace twitch {
|
||||
|
||||
class TwitchServer final : public irc::AbstractIrcServer
|
||||
{
|
||||
TwitchServer();
|
||||
|
@ -33,6 +34,7 @@ protected:
|
|||
|
||||
virtual std::shared_ptr<Channel> getCustomChannel(const QString &channelname) override;
|
||||
};
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace providers
|
||||
} // namespace chatterino
|
||||
|
|
Loading…
Reference in a new issue