make /logs command better

previously you had to have a split open with the channel, that's not
required anymore.
This commit is contained in:
Rasmus Karlsson 2018-11-03 15:37:56 +01:00
parent b469c24154
commit bcebfca477
4 changed files with 60 additions and 38 deletions

View file

@ -378,35 +378,34 @@ QString CommandController::execCommand(const QString &textNoEmoji,
auto app = getApp();
auto logs = new LogsPopup();
QString target;
QString target = words.at(1);
if (words.at(1).at(0) == "@")
if (target.at(0) == '@')
{
target = words.at(1).mid(1);
}
else
{
target = words.at(1);
target = target.mid(1);
}
logs->setTargetUserName(target);
std::shared_ptr<Channel> logsChannel = channel;
if (words.size() == 3)
{
QString channelName = words.at(2);
if (words.at(2).at(0) == "#")
if (words.at(2).at(0) == '#')
{
channelName = words.at(2).mid(1);
channelName = channelName.mid(1);
}
auto logsChannel =
logs->setChannelName(channelName);
logsChannel =
app->twitch.server->getChannelOrEmpty(channelName);
if (logsChannel != nullptr)
{
logs->setInfo(logsChannel, target);
}
}
else
{
logs->setInfo(channel, target);
}
logs->setChannel(logsChannel);
logs->getLogs();
logs->setAttribute(Qt::WA_DeleteOnClose);
logs->show();
return "";

View file

@ -3,6 +3,7 @@
#include "IrcMessage"
#include "common/Channel.hpp"
#include "common/NetworkRequest.hpp"
#include "debug/Log.hpp"
#include "providers/twitch/PartialTwitchUser.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
@ -33,29 +34,47 @@ void LogsPopup::initLayout()
this->setLayout(layout);
}
void LogsPopup::setInfo(ChannelPtr channel, QString userName)
void LogsPopup::setChannelName(QString channelName)
{
this->channelName_ = channelName;
}
void LogsPopup::setChannel(std::shared_ptr<Channel> channel)
{
this->channel_ = channel;
}
void LogsPopup::setTargetUserName(QString userName)
{
this->userName_ = userName;
}
if (auto twitchChannel =
dynamic_cast<TwitchChannel *>(this->channel_.get()))
void LogsPopup::getLogs()
{
if (this->channel_ && !this->channel_->isEmpty())
{
this->channelName_ = twitchChannel->getName();
if (auto twitchChannel =
dynamic_cast<TwitchChannel *>(this->channel_.get()))
{
this->channelName_ = twitchChannel->getName();
this->getLogviewerLogs(twitchChannel->roomId());
this->setWindowTitle(this->userName_ + "'s logs in #" +
this->channelName_);
return;
}
}
else
if (!this->channelName_.isEmpty())
{
PartialTwitchUser::byName(this->channelName_)
.getId(
[=](const QString &roomID) { this->getLogviewerLogs(roomID); },
this);
return;
}
}
// Get channel ID.
PartialTwitchUser::byName(this->channelName_)
.getId([=](const QString &roomID) {
this->getLogviewerLogs(roomID);
}, this);
this->setWindowTitle(this->userName_ + "'s logs in #" +
this->channelName_);
log("Unable to get logs, no channel name or something specified");
}
void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
@ -68,7 +87,6 @@ void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
void LogsPopup::getLogviewerLogs(const QString &roomID)
{
auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500")
.arg(this->channelName_, this->userName_);
@ -115,7 +133,6 @@ void LogsPopup::getLogviewerLogs(const QString &roomID)
void LogsPopup::getOverrustleLogs()
{
QString url =
QString("https://overrustlelogs.net/api/v1/stalk/%1/%2.json?limit=500")
.arg(this->channelName_, this->userName_);
@ -130,11 +147,11 @@ void LogsPopup::getOverrustleLogs()
box->show();
box->raise();
static QSet<int> closeButtons {
static QSet<int> closeButtons{
QMessageBox::Ok,
QMessageBox::Close,
};
if (closeButtons.contains(box->exec()))
if (closeButtons.contains(box->exec()))
{
this->close();
}

View file

@ -18,7 +18,11 @@ class LogsPopup : public BaseWindow
public:
LogsPopup();
void setInfo(std::shared_ptr<Channel> channel, QString userName);
void setChannelName(QString channelName);
void setChannel(std::shared_ptr<Channel> channel);
void setTargetUserName(QString userName);
void getLogs();
private:
ChannelView *channelView_ = nullptr;

View file

@ -96,7 +96,9 @@ UserInfoPopup::UserInfoPopup()
QObject::connect(viewLogs.getElement(), &Button::leftClicked, [this] {
auto logs = new LogsPopup();
logs->setInfo(this->channel_, this->userName_);
logs->setChannel(this->channel_);
logs->setTargetUserName(this->userName_);
logs->getLogs();
logs->setAttribute(Qt::WA_DeleteOnClose);
logs->show();
});