mirror of https://notabug.org/acetone/ircabot.git
access to ircclient trough config::network
parent
7143458781
commit
ea575a9de9
|
@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
#include "currenttime.h"
|
||||
#include "adminircpanel.h"
|
||||
#include "ircnetworkclient.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <QMutex>
|
||||
|
@ -72,10 +73,9 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
|
|||
channel.remove(rgx_channel);
|
||||
|
||||
auto configs = Config::networksAccess();
|
||||
QListIterator<Config::Network> networksIter(configs);
|
||||
while(networksIter.hasNext())
|
||||
for (auto iter = configs.begin(); iter != configs.end(); ++iter)
|
||||
{
|
||||
auto network = networksIter.next();
|
||||
auto& network = *iter;
|
||||
if (network.networkName != networkName) continue;
|
||||
|
||||
if (add and network.channels.contains(channel))
|
||||
|
@ -86,8 +86,7 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
|
|||
else if (add)
|
||||
{
|
||||
network.channels.push_back(channel);
|
||||
// TODO: update ircnetworkclient instance
|
||||
answer.push_back("Success. Channel " + channel + " added. ");
|
||||
answer.push_back("Success. Channel " + channel + " added.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -99,7 +98,6 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
|
|||
else if (not add)
|
||||
{
|
||||
network.channels.removeOne(channel);
|
||||
// TODO: update ircnetworkclient instance
|
||||
answer.push_back("Success. Channel " + channel + " removed.");
|
||||
return true;
|
||||
}
|
||||
|
@ -109,18 +107,21 @@ bool AdminIRCPanel::parse(const QString& networkName, const QString &input, QStr
|
|||
|
||||
else if (input.contains(rgx_reloadChannels))
|
||||
{
|
||||
// TODO
|
||||
answer.push_back("NOT IMPLEMENTED");
|
||||
auto configs = Config::networksAccess();
|
||||
for (auto iter = configs.begin(); iter != configs.end(); ++iter)
|
||||
{
|
||||
iter->instance->reloadChannelList();
|
||||
}
|
||||
answer.push_back("Success. Reloaded.");
|
||||
}
|
||||
|
||||
else if (input.contains(rgx_voiceGate))
|
||||
{
|
||||
bool enable = input.endsWith("enable", Qt::CaseInsensitive);
|
||||
auto configs = Config::networksAccess();
|
||||
QListIterator<Config::Network> networksIter(configs);
|
||||
while(networksIter.hasNext())
|
||||
for (auto iter = configs.begin(); iter != configs.end(); ++iter)
|
||||
{
|
||||
auto network = networksIter.next();
|
||||
auto& network = *iter;
|
||||
if (network.networkName != networkName) continue;
|
||||
|
||||
if (network.voiceGate == enable)
|
||||
|
|
|
@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class IRCNetworkClient;
|
||||
class QJsonObject;
|
||||
|
||||
class Config
|
||||
|
@ -51,6 +52,8 @@ public:
|
|||
QStringList channels;
|
||||
bool autoReconnect;
|
||||
bool voiceGate;
|
||||
|
||||
IRCNetworkClient* instance = nullptr;
|
||||
};
|
||||
|
||||
static void setConfigurationFilePath(const QString& path) { m_configurationFilePath = path; }
|
||||
|
|
|
@ -26,8 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
#define LOG_WARN qWarning().noquote() << "[" + m_config.networkName + "]"
|
||||
#define LOG_INFO qInfo().noquote() << "[" + m_config.networkName + "]"
|
||||
#define LOG_WARN qWarning().noquote() << "[" + m_config->networkName + "]"
|
||||
#define LOG_INFO qInfo().noquote() << "[" + m_config->networkName + "]"
|
||||
|
||||
IRCNetworkClient::IRCNetworkClient(QObject *parent) : QObject(parent) {}
|
||||
|
||||
|
@ -41,7 +41,7 @@ void IRCNetworkClient::reloadChannelList()
|
|||
while (connectedChannelListIterator.hasNext())
|
||||
{
|
||||
auto connectedChan = connectedChannelListIterator.next();
|
||||
if (not m_config.channels.contains(connectedChan->GetName()))
|
||||
if (not m_config->channels.contains(connectedChan->GetName()))
|
||||
{
|
||||
channelsToPart.push_back(connectedChan->GetName());
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ void IRCNetworkClient::reloadChannelList()
|
|||
|
||||
// JOIN
|
||||
QStringList channelsToJoin;
|
||||
QStringListIterator newChannelListIter (m_config.channels);
|
||||
QStringListIterator newChannelListIter (m_config->channels);
|
||||
while (newChannelListIter.hasNext())
|
||||
{
|
||||
auto newChannel = newChannelListIter.next();
|
||||
|
@ -79,17 +79,17 @@ void IRCNetworkClient::reloadChannelList()
|
|||
|
||||
void IRCNetworkClient::start()
|
||||
{
|
||||
libirc::ServerAddress address(m_config.host);
|
||||
address.SetPort(m_config.port);
|
||||
address.SetSSL(m_config.ssl);
|
||||
address.SetNick(m_config.nickname);
|
||||
address.SetPassword(m_config.password);
|
||||
address.SetIdent(m_config.ident);
|
||||
address.SetRealname(m_config.realName);
|
||||
address.SetSuffix(m_config.channels.join(','));
|
||||
libirc::ServerAddress address(m_config->host);
|
||||
address.SetPort(m_config->port);
|
||||
address.SetSSL(m_config->ssl);
|
||||
address.SetNick(m_config->nickname);
|
||||
address.SetPassword(m_config->password);
|
||||
address.SetIdent(m_config->ident);
|
||||
address.SetRealname(m_config->realName);
|
||||
address.SetSuffix(m_config->channels.join(','));
|
||||
|
||||
m_network = new libircclient::Network(address, m_config.networkName);
|
||||
m_network->SetDefaultIdentifyString(m_config.identifyFormat);
|
||||
m_network = new libircclient::Network(address, m_config->networkName);
|
||||
m_network->SetDefaultIdentifyString(m_config->identifyFormat);
|
||||
m_network->Connect();
|
||||
|
||||
connect(m_network, &libircclient::Network::Event_WhoisRegNick, this, &IRCNetworkClient::Slot_adminIdentified);
|
||||
|
@ -120,21 +120,21 @@ void IRCNetworkClient::Slot_adminIdentified(libircclient::Parser* p)
|
|||
LOG_WARN << "Event_WhoisRegNick failure: params.size() < 2, expected 2";
|
||||
return;
|
||||
}
|
||||
if (p->GetParameters().at(1) != m_config.ircabotAdmin)
|
||||
if (p->GetParameters().at(1) != m_config->ircabotAdmin)
|
||||
{
|
||||
LOG_WARN << "Event_WhoisRegNick failure: requested, but admin changed";
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO << "Admin authorized:" << m_config.ircabotAdmin;
|
||||
LOG_INFO << "Admin authorized:" << m_config->ircabotAdmin;
|
||||
AdminIRCPanel::identifiedTimestampUpdate(m_network->GetNetworkName());
|
||||
m_network->SendMessage(m_config.ircabotAdmin, "You have been identified as an IRCaBot administrator. "
|
||||
m_network->SendMessage(m_config->ircabotAdmin, "You have been identified as an IRCaBot administrator. "
|
||||
"Timeout: " + QString::number(Config::ircAdminAuthorizationTimeout()) + " secs");
|
||||
}
|
||||
|
||||
void IRCNetworkClient::Slot_onDirectMessage(QString sender, QString text)
|
||||
{
|
||||
if (sender != m_config.ircabotAdmin) return;
|
||||
if (sender != m_config->ircabotAdmin) return;
|
||||
|
||||
QStringList answer;
|
||||
if (not AdminIRCPanel::parse(m_network->GetNetworkName(), text, answer))
|
||||
|
|
|
@ -30,7 +30,7 @@ class IRCNetworkClient : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
IRCNetworkClient(QObject* parent = nullptr);
|
||||
void setConfig(const Config::Network& config) { m_config = config; }
|
||||
void setConfig(const Config::Network* config) { m_config = config; }
|
||||
// after config change; voiceGate, ircabotAdmin and autoReconnect have effect in run-time automatically
|
||||
void reloadChannelList();
|
||||
void start();
|
||||
|
@ -47,7 +47,7 @@ private slots:
|
|||
void Slot_onChannelMessage(QString channel, QString sender, QString text);
|
||||
|
||||
private:
|
||||
Config::Network m_config;
|
||||
const Config::Network* m_config;
|
||||
libircclient::Network* m_network = nullptr;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue