Added /chatters command (#2344)

This commit is contained in:
Paweł
2021-01-16 13:58:11 +01:00
committed by GitHub
parent a6e23e2468
commit b587173e18
4 changed files with 33 additions and 2 deletions
+19 -1
View File
@@ -434,6 +434,24 @@ void CommandController::initialize(Settings &, Paths &paths)
userPopup->show();
return "";
});
this->registerCommand(
"/chatters", [](const auto & /*words*/, auto channel) {
auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel == nullptr)
{
channel->addMessage(makeSystemMessage(
"The /chatters command only works in Twitch Channels"));
return "";
}
channel->addMessage(makeSystemMessage(
QString("Chatter count: %1")
.arg(QString::number(twitchChannel->chatterCount()))));
return "";
});
}
void CommandController::save()
@@ -517,7 +535,7 @@ QString CommandController::execCommand(const QString &textNoEmoji,
void CommandController::registerCommand(QString commandName,
CommandFunction commandFunction)
{
assert(this->commands_.contains(commandName) == false);
assert(!this->commands_.contains(commandName));
this->commands_[commandName] = commandFunction;
+11 -1
View File
@@ -528,6 +528,11 @@ const QString &TwitchChannel::popoutPlayerUrl()
return this->popoutPlayerUrl_;
}
int TwitchChannel::chatterCount()
{
return this->chatterCount_;
}
void TwitchChannel::setLive(bool newLiveStatus)
{
bool gotNewLiveStatus = false;
@@ -770,9 +775,14 @@ void TwitchChannel::refreshChatters()
// channel still exists?
auto shared = weak.lock();
if (!shared)
{
return Failure;
}
auto pair = parseChatters(result.parseJson());
auto data = result.parseJson();
this->chatterCount_ = data.value("chatter_count").toInt();
auto pair = parseChatters(std::move(data));
if (pair.first)
{
this->setChatters(std::move(pair.second));
+2
View File
@@ -78,6 +78,7 @@ public:
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
int chatterCount();
virtual bool isLive() const override;
QString roomId() const;
AccessGuard<const RoomModes> accessRoomModes() const;
@@ -155,6 +156,7 @@ private:
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
int chatterCount_;
UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<RoomModes> roomModes_;