clang-format

This commit is contained in:
Daniel Schmitz 2021-06-22 17:21:31 +08:00
parent 6e3b1f8e7b
commit 31a26e99f4

View file

@ -1,5 +1,5 @@
#include <znc/IRCNetwork.h>
#include <znc/Chan.h> #include <znc/Chan.h>
#include <znc/IRCNetwork.h>
using std::map; using std::map;
@ -10,23 +10,13 @@ class CIdleRPGMod;
class CIdleRPGChannel { class CIdleRPGChannel {
public: public:
CIdleRPGChannel() {} CIdleRPGChannel() {}
CIdleRPGChannel(const CString& sLine) { CIdleRPGChannel(const CString& sLine) { FromString(sLine); }
FromString(sLine);
}
virtual ~CIdleRPGChannel() {} virtual ~CIdleRPGChannel() {}
const CString& GetChannel() const { const CString& GetChannel() const { return m_Channel; }
return m_Channel; const CString& GetBotnick() const { return m_Botnick; }
} const CString& GetUsername() const { return m_Username; }
const CString& GetBotnick() const { const CString& GetPassword() const { return m_Password; }
return m_Botnick;
}
const CString& GetUsername() const {
return m_Username;
}
const CString& GetPassword() const {
return m_Password;
}
bool FromString(const CString& sLine) { bool FromString(const CString& sLine) {
m_Channel = sLine.Token(0).AsLower(); m_Channel = sLine.Token(0).AsLower();
@ -34,11 +24,13 @@ class CIdleRPGChannel {
m_Username = sLine.Token(2); m_Username = sLine.Token(2);
m_Password = sLine.Token(3); m_Password = sLine.Token(3);
return !m_Channel.empty() && !m_Botnick.empty() && !m_Username.empty() && !m_Password.empty(); return !m_Channel.empty() && !m_Botnick.empty() &&
!m_Username.empty() && !m_Password.empty();
} }
CString ToString() const { CString ToString() const {
return GetChannel() + " " + GetBotnick() + " " + GetUsername() + " " + GetPassword(); return GetChannel() + " " + GetBotnick() + " " + GetUsername() + " " +
GetPassword();
} }
private: private:
@ -51,9 +43,9 @@ class CIdleRPGChannel {
class CIdleRPGModTimer : public CTimer { class CIdleRPGModTimer : public CTimer {
public: public:
CIdleRPGModTimer(CModule* pModule, CIdleRPGChannel* sChannel, unsigned int uInterval, CIdleRPGModTimer(CModule* pModule, CIdleRPGChannel* sChannel,
unsigned int uCycles, const CString& sLabel, unsigned int uInterval, unsigned int uCycles,
const CString& sDescription) const CString& sLabel, const CString& sDescription)
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) { : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {
pChannel = sChannel; pChannel = sChannel;
} }
@ -72,11 +64,19 @@ class CIdleRPGMod : public CModule {
MODCONSTRUCTOR(CIdleRPGMod) { MODCONSTRUCTOR(CIdleRPGMod) {
AddHelpCommand(); AddHelpCommand();
AddCommand("Add", t_d("<#channel> <botnick> <username> <password>"), t_d("Adds a new channel or updates a channel"), [=](const CString& sLine) { CommandAdd(sLine); }); AddCommand("Add", t_d("<#channel> <botnick> <username> <password>"),
AddCommand("Del", t_d("<#channel>"), t_d("Removes a channel"), [=](const CString& sLine) { CommandDel(sLine); }); t_d("Adds a new channel or updates a channel"),
AddCommand("Clear", "", t_d("Clears all current settings"), [=](const CString& sLine) { CommandClear(); }); [=](const CString& sLine) { CommandAdd(sLine); });
AddCommand("List", "", t_d("Displays current settings"), [=](const CString& sLine) { CommandList(); }); AddCommand("Del", t_d("<#channel>"), t_d("Removes a channel"),
AddCommand("Login", t_d("[<#channel>]"), t_d("Manually triggers login now (either for specific channel or all channels)"), [=](const CString& sLine) { CommandLogin(sLine); }); [=](const CString& sLine) { CommandDel(sLine); });
AddCommand("Clear", "", t_d("Clears all current settings"),
[=](const CString& sLine) { CommandClear(); });
AddCommand("List", "", t_d("Displays current settings"),
[=](const CString& sLine) { CommandList(); });
AddCommand("Login", t_d("[<#channel>]"),
t_d("Manually triggers login now (either for specific "
"channel or all channels)"),
[=](const CString& sLine) { CommandLogin(sLine); });
} }
~CIdleRPGMod() override {} ~CIdleRPGMod() override {}
@ -87,7 +87,8 @@ class CIdleRPGMod : public CModule {
const CString& sLine = it->second; const CString& sLine = it->second;
CIdleRPGChannel* pChannel = new CIdleRPGChannel; CIdleRPGChannel* pChannel = new CIdleRPGChannel;
if (!pChannel->FromString(sLine) || FindChannel(pChannel->GetChannel())) { if (!pChannel->FromString(sLine) ||
FindChannel(pChannel->GetChannel())) {
delete pChannel; delete pChannel;
} else { } else {
m_Channels[pChannel->GetChannel()] = pChannel; m_Channels[pChannel->GetChannel()] = pChannel;
@ -98,8 +99,7 @@ class CIdleRPGMod : public CModule {
} }
CIdleRPGChannel* FindChannel(const CString& sChannel) { CIdleRPGChannel* FindChannel(const CString& sChannel) {
map<CString, CIdleRPGChannel*>::iterator it = map<CString, CIdleRPGChannel*>::iterator it = m_Channels.find(sChannel);
m_Channels.find(sChannel);
return (it != m_Channels.end()) ? it->second : nullptr; return (it != m_Channels.end()) ? it->second : nullptr;
} }
@ -129,7 +129,8 @@ class CIdleRPGMod : public CModule {
void CommandAdd(const CString& sLine) { void CommandAdd(const CString& sLine) {
if (sLine.Token(1).empty()) { if (sLine.Token(1).empty()) {
PutModule(t_s("Usage: Add <#channel> <botnick> <username> <password>")); PutModule(
t_s("Usage: Add <#channel> <botnick> <username> <password>"));
return; return;
} }
@ -156,11 +157,13 @@ class CIdleRPGMod : public CModule {
} }
CIdleRPGChannel* pChannel = new CIdleRPGChannel(); CIdleRPGChannel* pChannel = new CIdleRPGChannel();
pChannel->FromString(sChannel+" "+sBotnick+" "+sUsername+" "+sPassword); pChannel->FromString(sChannel + " " + sBotnick + " " + sUsername + " " +
sPassword);
m_Channels[pChannel->GetChannel()] = pChannel; m_Channels[pChannel->GetChannel()] = pChannel;
SetNV(pChannel->GetChannel(), pChannel->ToString()); SetNV(pChannel->GetChannel(), pChannel->ToString());
PutModule(t_f("Saved settings for channel {1}")(pChannel->GetChannel())); PutModule(
t_f("Saved settings for channel {1}")(pChannel->GetChannel()));
} }
void CommandDel(const CString& sLine) { void CommandDel(const CString& sLine) {
@ -170,8 +173,7 @@ class CIdleRPGMod : public CModule {
} }
CString sChannel = sLine.Token(1).AsLower(); CString sChannel = sLine.Token(1).AsLower();
map<CString, CIdleRPGChannel*>::iterator it = map<CString, CIdleRPGChannel*>::iterator it = m_Channels.find(sChannel);
m_Channels.find(sChannel);
if (it == m_Channels.end()) { if (it == m_Channels.end()) {
PutModule(t_f("Channel {1} not found")(sChannel)); PutModule(t_f("Channel {1} not found")(sChannel));
@ -211,32 +213,42 @@ class CIdleRPGMod : public CModule {
void QueueLogin(CIdleRPGChannel* sChan) { void QueueLogin(CIdleRPGChannel* sChan) {
RemTimer("idlerpg_login_timer_" + sChan->GetChannel()); RemTimer("idlerpg_login_timer_" + sChan->GetChannel());
AddTimer(new CIdleRPGModTimer(this, sChan, IDLERPG_JOIN_LOGIN_WAIT_TIME, 1, "idlerpg_login_timer_"+sChan->GetChannel(), "Tries login to IdleRPG bot")); AddTimer(
new CIdleRPGModTimer(this, sChan, IDLERPG_JOIN_LOGIN_WAIT_TIME, 1,
"idlerpg_login_timer_" + sChan->GetChannel(),
"Tries login to IdleRPG bot"));
} }
void Login(CIdleRPGChannel* sChan) { void Login(CIdleRPGChannel* sChan) {
// Valid channel? // Valid channel?
CChan* pChan = this->GetNetwork()->FindChan(sChan->GetChannel()); CChan* pChan = this->GetNetwork()->FindChan(sChan->GetChannel());
if (!pChan) { if (!pChan) {
PutModule(t_f("Error logging in: Invalid channel [{1}]")(sChan->GetChannel())); PutModule(t_f("Error logging in: Invalid channel [{1}]")(
sChan->GetChannel()));
return; return;
} }
// Botnick on channel? // Botnick on channel?
CNick* pBot = pChan->FindNick(sChan->GetBotnick()); CNick* pBot = pChan->FindNick(sChan->GetBotnick());
if (!pBot) { if (!pBot) {
PutModule(t_f("Error logging in: Bot [{1}] not found in channel [{2}]")(sChan->GetBotnick(), sChan->GetChannel())); PutModule(
t_f("Error logging in: Bot [{1}] not found in channel [{2}]")(
sChan->GetBotnick(), sChan->GetChannel()));
return; return;
} }
// Bot has op? // Bot has op?
if (!pBot->HasPerm(CChan::Op)) { if (!pBot->HasPerm(CChan::Op)) {
PutModule(t_f("Error logging in: Bot [{1}] not operator in in channel [{2}]")(sChan->GetBotnick(), sChan->GetChannel())); PutModule(t_f(
"Error logging in: Bot [{1}] not operator in in channel [{2}]")(
sChan->GetBotnick(), sChan->GetChannel()));
return; return;
} }
PutIRC("PRIVMSG " + sChan->GetBotnick() + " :login " + sChan->GetUsername() + " " + sChan->GetPassword()); PutIRC("PRIVMSG " + sChan->GetBotnick() + " :login " +
PutModule(t_s("Logging you in with "+sChan->GetBotnick()+" on "+sChan->GetChannel())); sChan->GetUsername() + " " + sChan->GetPassword());
PutModule(t_s("Logging you in with " + sChan->GetBotnick() + " on " +
sChan->GetChannel()));
} }
void OnJoin(const CNick& Nick, CChan& Channel) override { void OnJoin(const CNick& Nick, CChan& Channel) override {
@ -252,7 +264,8 @@ class CIdleRPGMod : public CModule {
} }
// Either Bot or user joins // Either Bot or user joins
if (Nick.GetNick() != fChannel->GetBotnick() && !GetNetwork()->GetCurNick().Equals(Nick.GetNick())) { if (Nick.GetNick() != fChannel->GetBotnick() &&
!GetNetwork()->GetCurNick().Equals(Nick.GetNick())) {
return; return;
} }
@ -263,7 +276,9 @@ class CIdleRPGMod : public CModule {
map<CString, CIdleRPGChannel*> m_Channels; map<CString, CIdleRPGChannel*> m_Channels;
}; };
void CIdleRPGModTimer::RunJob() { ((CIdleRPGMod*)GetModule())->Login(pChannel); } void CIdleRPGModTimer::RunJob() {
((CIdleRPGMod*)GetModule())->Login(pChannel);
}
template <> template <>
void TModInfo<CIdleRPGMod>(CModInfo& Info) { void TModInfo<CIdleRPGMod>(CModInfo& Info) {
@ -271,4 +286,6 @@ void TModInfo<CIdleRPGMod>(CModInfo& Info) {
Info.SetWikiPage("idlerpg"); Info.SetWikiPage("idlerpg");
} }
NETWORKMODULEDEFS(CIdleRPGMod, t_s("Automatically handles your login to IdleRPG games/channels")) NETWORKMODULEDEFS(
CIdleRPGMod,
t_s("Automatically handles your login to IdleRPG games/channels"))