added brace wrapping after if and for
This commit is contained in:
@@ -37,8 +37,10 @@ CommandController::CommandController()
|
||||
auto addFirstMatchToMap = [this](auto args) {
|
||||
this->commandsMap_.remove(args.item.name);
|
||||
|
||||
for (const Command &cmd : this->items.getVector()) {
|
||||
if (cmd.name == args.item.name) {
|
||||
for (const Command &cmd : this->items.getVector())
|
||||
{
|
||||
if (cmd.name == args.item.name)
|
||||
{
|
||||
this->commandsMap_[cmd.name] = cmd;
|
||||
break;
|
||||
}
|
||||
@@ -59,15 +61,18 @@ void CommandController::load(Paths &paths)
|
||||
this->filePath_ = combinePath(paths.settingsDirectory, "commands.txt");
|
||||
|
||||
QFile textFile(this->filePath_);
|
||||
if (!textFile.open(QIODevice::ReadOnly)) {
|
||||
if (!textFile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
// No commands file created yet
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QByteArray> test = textFile.readAll().split('\n');
|
||||
|
||||
for (const auto &command : test) {
|
||||
if (command.isEmpty()) {
|
||||
for (const auto &command : test)
|
||||
{
|
||||
if (command.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -80,13 +85,15 @@ void CommandController::load(Paths &paths)
|
||||
void CommandController::save()
|
||||
{
|
||||
QFile textFile(this->filePath_);
|
||||
if (!textFile.open(QIODevice::WriteOnly)) {
|
||||
if (!textFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
log("[CommandController::saveCommands] Unable to open {} for writing",
|
||||
this->filePath_);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const Command &cmd : this->items.getVector()) {
|
||||
for (const Command &cmd : this->items.getVector())
|
||||
{
|
||||
textFile.write((cmd.toString() + "\n").toUtf8());
|
||||
}
|
||||
|
||||
@@ -110,16 +117,20 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
if (words.length() == 0) {
|
||||
if (words.length() == 0)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
QString commandName = words[0];
|
||||
|
||||
// works in a valid twitch channel and /whispers, etc...
|
||||
if (!dryRun && channel->isTwitchChannel()) {
|
||||
if (commandName == "/w") {
|
||||
if (words.length() <= 2) {
|
||||
if (!dryRun && channel->isTwitchChannel())
|
||||
{
|
||||
if (commandName == "/w")
|
||||
{
|
||||
if (words.length() <= 2)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -139,7 +150,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
|
||||
QString rest = "";
|
||||
|
||||
for (int i = 2; i < words.length(); i++) {
|
||||
for (int i = 2; i < words.length(); i++)
|
||||
{
|
||||
rest += words[i] + " ";
|
||||
}
|
||||
|
||||
@@ -151,7 +163,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
|
||||
app->twitch.server->sendMessage("jtv", text);
|
||||
|
||||
if (getSettings()->inlineWhispers) {
|
||||
if (getSettings()->inlineWhispers)
|
||||
{
|
||||
app->twitch.server->forEachChannel(
|
||||
[&messagexD](ChannelPtr _channel) {
|
||||
_channel->addMessage(messagexD);
|
||||
@@ -166,14 +179,18 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
||||
|
||||
// works only in a valid twitch channel
|
||||
if (!dryRun && twitchChannel != nullptr) {
|
||||
if (commandName == "/debug-args") {
|
||||
if (!dryRun && twitchChannel != nullptr)
|
||||
{
|
||||
if (commandName == "/debug-args")
|
||||
{
|
||||
QString msg = QApplication::instance()->arguments().join(' ');
|
||||
|
||||
channel->addMessage(makeSystemMessage(msg));
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/uptime") {
|
||||
}
|
||||
else if (commandName == "/uptime")
|
||||
{
|
||||
const auto &streamStatus = twitchChannel->accessStreamStatus();
|
||||
|
||||
QString messageText = streamStatus->live
|
||||
@@ -183,8 +200,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
channel->addMessage(makeSystemMessage(messageText));
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/ignore") {
|
||||
if (words.size() < 2) {
|
||||
}
|
||||
else if (commandName == "/ignore")
|
||||
{
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("Usage: /ignore [user]"));
|
||||
return "";
|
||||
@@ -194,7 +214,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto user = app->accounts->twitch.getCurrent();
|
||||
auto target = words.at(1);
|
||||
|
||||
if (user->isAnon()) {
|
||||
if (user->isAnon())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"You must be logged in to ignore someone"));
|
||||
return "";
|
||||
@@ -206,8 +227,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
});
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/unignore") {
|
||||
if (words.size() < 2) {
|
||||
}
|
||||
else if (commandName == "/unignore")
|
||||
{
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("Usage: /unignore [user]"));
|
||||
return "";
|
||||
@@ -217,7 +241,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto user = app->accounts->twitch.getCurrent();
|
||||
auto target = words.at(1);
|
||||
|
||||
if (user->isAnon()) {
|
||||
if (user->isAnon())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"You must be logged in to ignore someone"));
|
||||
return "";
|
||||
@@ -229,8 +254,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
});
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/follow") {
|
||||
if (words.size() < 2) {
|
||||
}
|
||||
else if (commandName == "/follow")
|
||||
{
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("Usage: /follow [user]"));
|
||||
return "";
|
||||
@@ -240,7 +268,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto user = app->accounts->twitch.getCurrent();
|
||||
auto target = words.at(1);
|
||||
|
||||
if (user->isAnon()) {
|
||||
if (user->isAnon())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"You must be logged in to follow someone"));
|
||||
return "";
|
||||
@@ -248,7 +277,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
|
||||
TwitchApi::findUserId(
|
||||
target, [user, channel, target](QString userId) {
|
||||
if (userId.isEmpty()) {
|
||||
if (userId.isEmpty())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"User " + target + " could not be followed!"));
|
||||
return;
|
||||
@@ -260,8 +290,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
});
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/unfollow") {
|
||||
if (words.size() < 2) {
|
||||
}
|
||||
else if (commandName == "/unfollow")
|
||||
{
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("Usage: /unfollow [user]"));
|
||||
return "";
|
||||
@@ -271,7 +304,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto user = app->accounts->twitch.getCurrent();
|
||||
auto target = words.at(1);
|
||||
|
||||
if (user->isAnon()) {
|
||||
if (user->isAnon())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"You must be logged in to follow someone"));
|
||||
return "";
|
||||
@@ -279,7 +313,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
|
||||
TwitchApi::findUserId(
|
||||
target, [user, channel, target](QString userId) {
|
||||
if (userId.isEmpty()) {
|
||||
if (userId.isEmpty())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
"User " + target + " could not be followed!"));
|
||||
return;
|
||||
@@ -291,8 +326,11 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
});
|
||||
|
||||
return "";
|
||||
} else if (commandName == "/logs") {
|
||||
if (words.size() < 2) {
|
||||
}
|
||||
else if (commandName == "/logs")
|
||||
{
|
||||
if (words.size() < 2)
|
||||
{
|
||||
channel->addMessage(
|
||||
makeSystemMessage("Usage: /logs [user] (channel)"));
|
||||
return "";
|
||||
@@ -302,24 +340,34 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
auto logs = new LogsPopup();
|
||||
QString target;
|
||||
|
||||
if (words.at(1).at(0) == "@") {
|
||||
if (words.at(1).at(0) == "@")
|
||||
{
|
||||
target = words.at(1).mid(1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
target = words.at(1);
|
||||
}
|
||||
|
||||
if (words.size() == 3) {
|
||||
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);
|
||||
}
|
||||
auto logsChannel =
|
||||
app->twitch.server->getChannelOrEmpty(channelName);
|
||||
if (logsChannel == nullptr) {
|
||||
} else {
|
||||
if (logsChannel == nullptr)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
logs->setInfo(logsChannel, target);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
logs->setInfo(channel, target);
|
||||
}
|
||||
logs->setAttribute(Qt::WA_DeleteOnClose);
|
||||
@@ -330,7 +378,8 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel,
|
||||
|
||||
// check if custom command exists
|
||||
auto it = this->commandsMap_.find(commandName);
|
||||
if (it == this->commandsMap_.end()) {
|
||||
if (it == this->commandsMap_.end())
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -352,11 +401,13 @@ QString CommandController::execCustomCommand(const QStringList &words,
|
||||
auto globalMatch = parseCommand.globalMatch(command.func);
|
||||
int matchOffset = 0;
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
QRegularExpressionMatch match =
|
||||
parseCommand.match(command.func, matchOffset);
|
||||
|
||||
if (!match.hasMatch()) {
|
||||
if (!match.hasMatch())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -373,32 +424,40 @@ QString CommandController::execCustomCommand(const QStringList &words,
|
||||
|
||||
bool ok;
|
||||
int wordIndex = wordIndexMatch.replace("=", "").toInt(&ok);
|
||||
if (!ok || wordIndex == 0) {
|
||||
if (!ok || wordIndex == 0)
|
||||
{
|
||||
result += "{" + match.captured(3) + "}";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (words.length() <= wordIndex) {
|
||||
if (words.length() <= wordIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (plus) {
|
||||
if (plus)
|
||||
{
|
||||
bool first = true;
|
||||
for (int i = wordIndex; i < words.length(); i++) {
|
||||
if (!first) {
|
||||
for (int i = wordIndex; i < words.length(); i++)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
result += " ";
|
||||
}
|
||||
result += words[i];
|
||||
first = false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
result += words[wordIndex];
|
||||
}
|
||||
}
|
||||
|
||||
result += command.func.mid(lastCaptureEnd);
|
||||
|
||||
if (result.size() > 0 && result.at(0) == '{') {
|
||||
if (result.size() > 0 && result.at(0) == '{')
|
||||
{
|
||||
result = result.mid(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user