Add basic lua scripting capabilities (#4341)
The scripting capabilities is locked behind a cmake flag, and is not enabled by default. Co-authored-by: nerix <nerixdev@outlook.de> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "controllers/commands/Command.hpp"
|
||||
#include "controllers/commands/CommandContext.hpp"
|
||||
#include "controllers/commands/CommandModel.hpp"
|
||||
#include "controllers/plugins/PluginController.hpp"
|
||||
#include "controllers/userdata/UserDataController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
@@ -3261,6 +3262,32 @@ QString CommandController::execCommand(const QString &textNoEmoji,
|
||||
return text;
|
||||
}
|
||||
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
bool CommandController::registerPluginCommand(const QString &commandName)
|
||||
{
|
||||
if (this->commands_.contains(commandName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->commands_[commandName] = [commandName](const CommandContext &ctx) {
|
||||
return getApp()->plugins->tryExecPluginCommand(commandName, ctx);
|
||||
};
|
||||
this->pluginCommands_.append(commandName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandController::unregisterPluginCommand(const QString &commandName)
|
||||
{
|
||||
if (!this->pluginCommands_.contains(commandName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this->pluginCommands_.removeAll(commandName);
|
||||
return this->commands_.erase(commandName) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void CommandController::registerCommand(const QString &commandName,
|
||||
CommandFunctionVariants commandFunction)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,15 @@ public:
|
||||
const QStringList &words, const Command &command, bool dryRun,
|
||||
ChannelPtr channel, const Message *message = nullptr,
|
||||
std::unordered_map<QString, QString> context = {});
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
bool registerPluginCommand(const QString &commandName);
|
||||
bool unregisterPluginCommand(const QString &commandName);
|
||||
|
||||
const QStringList &pluginCommands()
|
||||
{
|
||||
return this->pluginCommands_;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void load(Paths &paths);
|
||||
@@ -73,6 +82,9 @@ private:
|
||||
commandsSetting_;
|
||||
|
||||
QStringList defaultChatterinoCommandAutoCompletions_;
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
QStringList pluginCommands_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user