Add a switch for follower only mode (#1241)

* Add a switch follower only mode

* Format the code
This commit is contained in:
Mm2PL 2019-08-25 19:08:04 +02:00 committed by fourtf
parent def839bef9
commit 1a25c5afe8
3 changed files with 46 additions and 2 deletions

View file

@ -196,6 +196,10 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
{
roomModes.broadcasterLang = it.value().toString();
}
if ((it = tags.find("followers-only")) != tags.end())
{
roomModes.followerOnly = it.value().toInt();
}
twitchChannel->setRoomModes(roomModes);
}

View file

@ -49,7 +49,7 @@ public:
bool submode = false;
bool r9k = false;
bool emoteOnly = false;
// int folowerOnly = 0;
int followerOnly = -1;
int slowMode = 0;
QString broadcasterLang;
};

View file

@ -54,6 +54,18 @@ namespace {
text += "emote, ";
if (modes->submode)
text += "sub, ";
if (modes->followerOnly != -1)
{
if (modes->followerOnly != 0)
{
text += QString("follower(%1 minutes), ")
.arg(QString::number(modes->followerOnly));
}
else
{
text += QString("follower, ");
}
}
}
if (text.length() > 2)
@ -344,7 +356,9 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
auto setEmote = new QAction("Emote only", this);
auto setSlow = new QAction("Slow", this);
auto setR9k = new QAction("R9K", this);
auto setFollowers = new QAction("Followers only", this);
setFollowers->setCheckable(true);
setSub->setCheckable(true);
setEmote->setCheckable(true);
setSlow->setCheckable(true);
@ -354,9 +368,10 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
menu->addAction(setSub);
menu->addAction(setSlow);
menu->addAction(setR9k);
menu->addAction(setFollowers);
this->managedConnections_.push_back(this->modeUpdateRequested_.connect( //
[this, setSub, setEmote, setSlow, setR9k]() {
[this, setSub, setEmote, setSlow, setR9k, setFollowers]() {
auto twitchChannel =
dynamic_cast<TwitchChannel *>(this->split_->getChannel().get());
if (twitchChannel == nullptr)
@ -371,6 +386,7 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
setSlow->setChecked(roomModes->slowMode);
setEmote->setChecked(roomModes->emoteOnly);
setSub->setChecked(roomModes->submode);
setFollowers->setChecked(roomModes->followerOnly != -1);
}));
auto toggle = [this](const QString &command, QAction *action) mutable {
@ -408,6 +424,30 @@ std::unique_ptr<QMenu> SplitHeader::createChatModeMenu()
}
});
QObject::connect(
setFollowers, &QAction::triggered, this, [setFollowers, this]() {
if (!setFollowers->isChecked())
{
this->split_->getChannel().get()->sendMessage("/followersoff");
setFollowers->setChecked(false);
return;
};
auto ok = bool();
auto time = QInputDialog::getText(
this, "", "Time:", QLineEdit::Normal, "15m", &ok,
Qt::FramelessWindowHint,
Qt::ImhLowercaseOnly | Qt::ImhPreferNumbers);
if (ok)
{
this->split_->getChannel().get()->sendMessage(
QString("/followers %1").arg(time));
}
else
{
setFollowers->setChecked(false);
}
});
QObject::connect(
setR9k, &QAction::triggered, this,
[setR9k, toggle]() mutable { toggle("/r9kbeta", setR9k); });