mirror-chatterino2/src/singletons/commandmanager.hpp

48 lines
889 B
C++
Raw Normal View History

2017-11-12 17:21:50 +01:00
#pragma once
2018-01-04 02:50:36 +01:00
#include <QMap>
2017-11-12 17:21:50 +01:00
#include <QString>
2018-01-04 02:50:36 +01:00
#include <mutex>
2017-11-12 17:21:50 +01:00
namespace chatterino {
2018-01-05 02:05:59 +01:00
class Channel;
2017-12-31 22:58:35 +01:00
namespace singletons {
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
//
// this class managed the custom /commands
//
2017-11-12 17:21:50 +01:00
class CommandManager
{
2017-12-31 00:50:07 +01:00
CommandManager() = default;
public:
static CommandManager &getInstance();
2018-01-05 02:05:59 +01:00
QString execCommand(const QString &text, std::shared_ptr<Channel> channel, bool dryRun);
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
void loadCommands();
void saveCommands();
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
void setCommands(const QStringList &commands);
QStringList getCommands();
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
private:
struct Command {
QString name;
QString text;
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
Command() = default;
Command(QString text);
};
2017-12-27 19:50:05 +01:00
2018-01-04 02:50:36 +01:00
QMap<QString, Command> commands;
std::mutex mutex;
QStringList commandsStringList;
2018-01-05 02:05:59 +01:00
QString execCustomCommand(const QStringList &words, const Command &command);
2017-11-12 17:21:50 +01:00
};
}
2017-12-31 22:58:35 +01:00
}