mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
parent
ef81029374
commit
13475332fb
6 changed files with 98 additions and 20 deletions
|
@ -239,6 +239,11 @@ bool Channel::hasModRights() const
|
|||
return this->isMod() || this->isBroadcaster();
|
||||
}
|
||||
|
||||
bool Channel::hasHighRateLimit() const
|
||||
{
|
||||
return this->isMod() || this->isBroadcaster();
|
||||
}
|
||||
|
||||
bool Channel::isLive() const
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
virtual bool isMod() const;
|
||||
virtual bool isBroadcaster() const;
|
||||
virtual bool hasModRights() const;
|
||||
virtual bool hasHighRateLimit() const;
|
||||
virtual bool isLive() const;
|
||||
virtual bool shouldIgnoreHighlights() const;
|
||||
|
||||
|
|
|
@ -20,6 +20,24 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
static QMap<QString, QString> parseBadges(QString badgesString)
|
||||
{
|
||||
QMap<QString, QString> badges;
|
||||
|
||||
for (auto badgeData : badgesString.split(','))
|
||||
{
|
||||
auto parts = badgeData.split('/');
|
||||
if (parts.length() != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
badges.insert(parts[0], parts[1]);
|
||||
}
|
||||
|
||||
return badges;
|
||||
}
|
||||
|
||||
IrcMessageHandler &IrcMessageHandler::getInstance()
|
||||
{
|
||||
static IrcMessageHandler instance;
|
||||
|
@ -207,24 +225,35 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
|||
|
||||
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
QVariant _mod = message->tag("mod");
|
||||
auto app = getApp();
|
||||
|
||||
QString channelName;
|
||||
if (!trimChannelName(message->parameter(0), channelName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto c = app->twitch.server->getChannelOrEmpty(channelName);
|
||||
if (c->isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
QVariant _mod = message->tag("mod");
|
||||
if (_mod.isValid())
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
QString channelName;
|
||||
if (!trimChannelName(message->parameter(0), channelName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto c = app->twitch.server->getChannelOrEmpty(channelName);
|
||||
if (c->isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TwitchChannel *tc = dynamic_cast<TwitchChannel *>(c.get());
|
||||
if (tc != nullptr)
|
||||
{
|
||||
|
|
|
@ -200,7 +200,7 @@ void TwitchChannel::sendMessage(const QString &message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this->hasModRights())
|
||||
if (!this->hasHighRateLimit())
|
||||
{
|
||||
if (getSettings()->allowDuplicateMessages)
|
||||
{
|
||||
|
@ -226,6 +226,16 @@ bool TwitchChannel::isMod() const
|
|||
return this->mod_;
|
||||
}
|
||||
|
||||
bool TwitchChannel::isVIP() const
|
||||
{
|
||||
return this->vip_;
|
||||
}
|
||||
|
||||
bool TwitchChannel::isStaff() const
|
||||
{
|
||||
return this->staff_;
|
||||
}
|
||||
|
||||
void TwitchChannel::setMod(bool value)
|
||||
{
|
||||
if (this->mod_ != value)
|
||||
|
@ -236,6 +246,26 @@ void TwitchChannel::setMod(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::setVIP(bool value)
|
||||
{
|
||||
if (this->vip_ != value)
|
||||
{
|
||||
this->vip_ = value;
|
||||
|
||||
this->userStateChanged.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::setStaff(bool value)
|
||||
{
|
||||
if (this->staff_ != value)
|
||||
{
|
||||
this->staff_ = value;
|
||||
|
||||
this->userStateChanged.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
bool TwitchChannel::isBroadcaster() const
|
||||
{
|
||||
auto app = getApp();
|
||||
|
@ -243,6 +273,11 @@ bool TwitchChannel::isBroadcaster() const
|
|||
return this->getName() == app->accounts->twitch.getCurrent()->getUserName();
|
||||
}
|
||||
|
||||
bool TwitchChannel::hasHighRateLimit() const
|
||||
{
|
||||
return this->isMod() || this->isBroadcaster() || this->isVIP();
|
||||
}
|
||||
|
||||
void TwitchChannel::addRecentChatter(const MessagePtr &message)
|
||||
{
|
||||
this->chatters_.access()->insert(message->displayName);
|
||||
|
|
|
@ -61,7 +61,10 @@ public:
|
|||
virtual bool canSendMessage() const override;
|
||||
virtual void sendMessage(const QString &message) override;
|
||||
virtual bool isMod() const override;
|
||||
bool isVIP() const;
|
||||
bool isStaff() const;
|
||||
virtual bool isBroadcaster() const override;
|
||||
virtual bool hasHighRateLimit() const override;
|
||||
|
||||
// Data
|
||||
const QString &subscriptionUrl();
|
||||
|
@ -123,6 +126,8 @@ private:
|
|||
void addPartedUser(const QString &user);
|
||||
void setLive(bool newLiveStatus);
|
||||
void setMod(bool value);
|
||||
void setVIP(bool value);
|
||||
void setStaff(bool value);
|
||||
void setRoomId(const QString &id);
|
||||
void setRoomModes(const RoomModes &roomModes_);
|
||||
|
||||
|
@ -151,6 +156,8 @@ private:
|
|||
FfzModBadge ffzCustomModBadge_;
|
||||
|
||||
bool mod_ = false;
|
||||
bool vip_ = false;
|
||||
bool staff_ = false;
|
||||
UniqueAccess<QString> roomID_;
|
||||
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
|
|
|
@ -293,10 +293,11 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel,
|
|||
std::lock_guard<std::mutex> guard(this->lastMessageMutex_);
|
||||
|
||||
// std::queue<std::chrono::steady_clock::time_point>
|
||||
auto &lastMessage = channel->hasModRights() ? this->lastMessageMod_
|
||||
: this->lastMessagePleb_;
|
||||
size_t maxMessageCount = channel->hasModRights() ? 99 : 19;
|
||||
auto minMessageOffset = (channel->hasModRights() ? 100ms : 1100ms);
|
||||
auto &lastMessage = channel->hasHighRateLimit()
|
||||
? this->lastMessageMod_
|
||||
: this->lastMessagePleb_;
|
||||
size_t maxMessageCount = channel->hasHighRateLimit() ? 99 : 19;
|
||||
auto minMessageOffset = (channel->hasHighRateLimit() ? 100ms : 1100ms);
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
|
|
Loading…
Reference in a new issue