// SPDX-FileCopyrightText: 2018 Contributors to Chatterino // // SPDX-License-Identifier: MIT #pragma once #include "common/SignalVector.hpp" #include "util/QStringHash.hpp" #include #include #include #include #include #include namespace chatterino { class Settings; class Paths; class Channel; using ChannelPtr = std::shared_ptr; struct Message; struct Command; class CommandModel; struct CommandContext; class CommandController final { public: SignalVector items; QString execCommand(const QString &text, std::shared_ptr channel, bool dryRun); QStringList getDefaultChatterinoCommandList(); CommandController(const Paths &paths); void save(); CommandModel *createModel(QObject *parent); QString execCustomCommand( const QStringList &words, const Command &command, bool dryRun, ChannelPtr channel, const Message *message = nullptr, std::unordered_map context = {}); #ifdef CHATTERINO_HAVE_PLUGINS bool registerPluginCommand(const QString &commandName); bool unregisterPluginCommand(const QString &commandName); const QStringList &pluginCommands() { return this->pluginCommands_; } #endif /// Returns the length of the command trigger in `text`, including leading /// spaces. If `text` does not start with a command trigger, 0 is returned. /// Examples: /// - " /ban forsen" returns 5 /// - "/non-existing-command" returns 0 qsizetype commandTriggerLen(QStringView text); private: void load(Paths &paths); using CommandFunction = std::function; using CommandFunctionWithContext = std::function; using CommandFunctionVariants = std::variant; void registerCommand(const QString &commandName, CommandFunctionVariants commandFunction); // Chatterino commands std::unordered_map commands_; // User-created commands QMap userCommands_; qsizetype maxSpaces_ = 0; std::shared_ptr sm_; // Because the setting manager is not initialized until the initialize // function is called (and not in the constructor), we have to // late-initialize the setting, which is why we're storing it as a // unique_ptr std::unique_ptr>> commandsSetting_; QStringList defaultChatterinoCommandAutoCompletions_; #ifdef CHATTERINO_HAVE_PLUGINS QStringList pluginCommands_; #endif }; } // namespace chatterino