mirror of https://notabug.org/acetone/ircabot.git
Triggers updating (syntax and url substitute
parent
72bfbd2e8b
commit
70f46b0f87
|
@ -29,9 +29,10 @@ void ApplicationData::createConfigExample(const QString &pathToConfig)
|
|||
"# If password is empty logging in without password.\n"
|
||||
"password = password_for_NickServ\n\n"
|
||||
"# This triggers available in all chats.\n"
|
||||
"# 'request' and 'answer' must be splitted by ':::'\n"
|
||||
"# triggers splitting by '<!>'\n"
|
||||
"triggers = request = version ::: answer = " + IRCABOT_VERSION + " <!> request=hello:::answer=hi\n\n"
|
||||
"# Request and answer must be splitted by \":::\". Triggers splitting by \"<!>\".\n"
|
||||
"# You can use \"%CHANNEL_FOR_URL%\" to automatically substitute the address for the chat,\n"
|
||||
"# from which the link to the web interface is requested.\n"
|
||||
"triggers = version ::: " + IRCABOT_VERSION + " <!> webui ::: http://example.com/%CHANNEL_FOR_URL%\n\n"
|
||||
|
||||
"# Web interface options\n"
|
||||
"bind_to_address = 127.0.0.1\n"
|
||||
|
@ -44,9 +45,7 @@ void ApplicationData::createConfigExample(const QString &pathToConfig)
|
|||
"# Default channel for the web interface marked with an '@' at the end (globally only one).\n"
|
||||
"channels = #general@,#acetonevideo\n"
|
||||
"# This triggers available in current server only.\n"
|
||||
"# 'request' and 'answer' must be splitted by ':::'\n"
|
||||
"# triggers splitting by '<!>'\n"
|
||||
"triggers = request = hi ::: answer = hello <!> request=developer:::answer=acetone\n\n"
|
||||
"triggers = hi ::: hello <!> developer ::: acetone\n\n"
|
||||
"# Optional parameters if global is defined:\n"
|
||||
"#nick = unique_nickname_for_this_server\n"
|
||||
"#user = unique_ident_for_this_server\n"
|
||||
|
@ -180,11 +179,18 @@ void ApplicationData::readConfig()
|
|||
QString triggersLine = global::getValue(globalSection, "triggers");
|
||||
if (not triggersLine.isEmpty()) {
|
||||
QStringList triggersPair = triggersLine.split("<!>");
|
||||
for (auto &pair: triggersPair) {
|
||||
QString request = global::getValue(pair, "request", global::Type::eForTriggers);
|
||||
if (request.isEmpty()) continue;
|
||||
QString answer = global::getValue(pair, "answer", global::Type::eForTriggers);
|
||||
if (answer.isEmpty()) continue;
|
||||
for (auto &p: triggersPair) {
|
||||
QStringList pair = p.split(":::");
|
||||
if (pair.size() != 2) continue;
|
||||
QString request = pair.first();
|
||||
QString answer = pair.last();
|
||||
|
||||
if (request.startsWith(' ')) request.remove(QRegularExpression("^\\s*"));
|
||||
if (request.endsWith(' ')) request.remove(QRegularExpression("\\s*$"));
|
||||
if (answer.startsWith(' ')) answer.remove(QRegularExpression("^\\s*"));
|
||||
if (answer.endsWith(' ')) answer.remove(QRegularExpression("\\s*$"));
|
||||
if (request.isEmpty() or answer.isEmpty()) continue;
|
||||
|
||||
globalTriggers[request] = answer;
|
||||
qInfo().noquote() << "[GLOBAL] Trigger (" << request << ":::" << answer << ")";
|
||||
}
|
||||
|
@ -295,14 +301,20 @@ void ApplicationData::readConfig()
|
|||
QString triggersLine = global::getValue(currentSection, "triggers");
|
||||
if (not triggersLine.isEmpty()) {
|
||||
QStringList triggersPair = triggersLine.split("<!>");
|
||||
for (auto &pair: triggersPair) {
|
||||
QString request = global::getValue(pair, "request", global::Type::eForTriggers);
|
||||
if (request.isEmpty()) continue;
|
||||
QString answer = global::getValue(pair, "answer", global::Type::eForTriggers);
|
||||
if (answer.isEmpty()) continue;
|
||||
for (auto &p: triggersPair) {
|
||||
QStringList pair = p.split(":::");
|
||||
if (pair.size() != 2) continue;
|
||||
QString request = pair.first();
|
||||
QString answer = pair.last();
|
||||
|
||||
if (request.startsWith(' ')) request.remove(QRegularExpression("^\\s*"));
|
||||
if (request.endsWith(' ')) request.remove(QRegularExpression("\\s*$"));
|
||||
if (answer.startsWith(' ')) answer.remove(QRegularExpression("^\\s*"));
|
||||
if (answer.endsWith(' ')) answer.remove(QRegularExpression("\\s*$"));
|
||||
if (request.isEmpty() or answer.isEmpty()) continue;
|
||||
|
||||
newConnection.triggers[request] = answer;
|
||||
qInfo().noquote() << "[" + newConnection.displayName + "] Trigger (" <<
|
||||
request << ":::" << answer << ")";
|
||||
qInfo().noquote() << "["+newConnection.displayName+"] Trigger (" << request << ":::" << answer << ")";
|
||||
}
|
||||
}
|
||||
for (auto &glob: globalTriggers) {
|
||||
|
|
|
@ -8,12 +8,6 @@
|
|||
#include <QTimer>
|
||||
#include <QFile>
|
||||
|
||||
const int NICK_RECOVER_TIMER = 60000; // 1 minute
|
||||
const int THREAD_SLEEP_ON_RECONNECT = 3; // seconds
|
||||
const int USER_LIST_ACTIALIZE = 5000;// 1800000; // 30 minutes
|
||||
const int WRITING_STOP_TIMER = 1100; // 1.1 second
|
||||
const int PING_TIMEOUT = 361000; // 361 seconds
|
||||
|
||||
IrcClient::IrcClient(const ConnectionData& config, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_socket(nullptr),
|
||||
|
@ -193,7 +187,10 @@ void IrcClient::toTrigger(const QString& channel, const QString &nickname, const
|
|||
|
||||
for (auto trigger: m_connectionData.triggers) {
|
||||
if (message.contains(m_connectionData.triggers.key(trigger), Qt::CaseInsensitive)) {
|
||||
write("PRIVMSG " + channel + " " + nickname + ", " + trigger);
|
||||
QString response {trigger};
|
||||
response.replace(TRIGGER_CHANNEL_FOR_URL_PATTERN,
|
||||
global::toLowerAndNoSpaces(m_connectionData.displayName) + "/" + channel.mid(1, channel.size()-1));
|
||||
write("PRIVMSG " + channel + " " + nickname + ", " + response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
#include <QTimer>
|
||||
#include <map>
|
||||
|
||||
constexpr int NICK_RECOVER_TIMER = 60000; // 1 minute
|
||||
constexpr int THREAD_SLEEP_ON_RECONNECT = 3; // seconds
|
||||
constexpr int USER_LIST_ACTIALIZE = 1800000; // 30 minutes
|
||||
constexpr int WRITING_STOP_TIMER = 1100; // 1.1 second
|
||||
constexpr int PING_TIMEOUT = 361000; // 361 seconds
|
||||
|
||||
const QString TRIGGER_CHANNEL_FOR_URL_PATTERN = "%CHANNEL_FOR_URL%";
|
||||
|
||||
class IrcClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in New Issue