clang-format
This commit is contained in:
parent
6e3b1f8e7b
commit
31a26e99f4
1 changed files with 210 additions and 193 deletions
115
idlerpg.cpp
115
idlerpg.cpp
|
@ -1,5 +1,5 @@
|
|||
#include <znc/IRCNetwork.h>
|
||||
#include <znc/Chan.h>
|
||||
#include <znc/IRCNetwork.h>
|
||||
|
||||
using std::map;
|
||||
|
||||
|
@ -10,23 +10,13 @@ class CIdleRPGMod;
|
|||
class CIdleRPGChannel {
|
||||
public:
|
||||
CIdleRPGChannel() {}
|
||||
CIdleRPGChannel(const CString& sLine) {
|
||||
FromString(sLine);
|
||||
}
|
||||
CIdleRPGChannel(const CString& sLine) { FromString(sLine); }
|
||||
virtual ~CIdleRPGChannel() {}
|
||||
|
||||
const CString& GetChannel() const {
|
||||
return m_Channel;
|
||||
}
|
||||
const CString& GetBotnick() const {
|
||||
return m_Botnick;
|
||||
}
|
||||
const CString& GetUsername() const {
|
||||
return m_Username;
|
||||
}
|
||||
const CString& GetPassword() const {
|
||||
return m_Password;
|
||||
}
|
||||
const CString& GetChannel() const { return m_Channel; }
|
||||
const CString& GetBotnick() const { return m_Botnick; }
|
||||
const CString& GetUsername() const { return m_Username; }
|
||||
const CString& GetPassword() const { return m_Password; }
|
||||
|
||||
bool FromString(const CString& sLine) {
|
||||
m_Channel = sLine.Token(0).AsLower();
|
||||
|
@ -34,11 +24,13 @@ class CIdleRPGChannel {
|
|||
m_Username = sLine.Token(2);
|
||||
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 {
|
||||
return GetChannel() + " " + GetBotnick() + " " + GetUsername() + " " + GetPassword();
|
||||
return GetChannel() + " " + GetBotnick() + " " + GetUsername() + " " +
|
||||
GetPassword();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -51,9 +43,9 @@ class CIdleRPGChannel {
|
|||
|
||||
class CIdleRPGModTimer : public CTimer {
|
||||
public:
|
||||
CIdleRPGModTimer(CModule* pModule, CIdleRPGChannel* sChannel, unsigned int uInterval,
|
||||
unsigned int uCycles, const CString& sLabel,
|
||||
const CString& sDescription)
|
||||
CIdleRPGModTimer(CModule* pModule, CIdleRPGChannel* sChannel,
|
||||
unsigned int uInterval, unsigned int uCycles,
|
||||
const CString& sLabel, const CString& sDescription)
|
||||
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {
|
||||
pChannel = sChannel;
|
||||
}
|
||||
|
@ -72,11 +64,19 @@ class CIdleRPGMod : public CModule {
|
|||
MODCONSTRUCTOR(CIdleRPGMod) {
|
||||
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("Del", t_d("<#channel>"), t_d("Removes a channel"), [=](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); });
|
||||
AddCommand("Add", t_d("<#channel> <botnick> <username> <password>"),
|
||||
t_d("Adds a new channel or updates a channel"),
|
||||
[=](const CString& sLine) { CommandAdd(sLine); });
|
||||
AddCommand("Del", t_d("<#channel>"), t_d("Removes a channel"),
|
||||
[=](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 {}
|
||||
|
@ -87,7 +87,8 @@ class CIdleRPGMod : public CModule {
|
|||
const CString& sLine = it->second;
|
||||
CIdleRPGChannel* pChannel = new CIdleRPGChannel;
|
||||
|
||||
if (!pChannel->FromString(sLine) || FindChannel(pChannel->GetChannel())) {
|
||||
if (!pChannel->FromString(sLine) ||
|
||||
FindChannel(pChannel->GetChannel())) {
|
||||
delete pChannel;
|
||||
} else {
|
||||
m_Channels[pChannel->GetChannel()] = pChannel;
|
||||
|
@ -98,13 +99,12 @@ class CIdleRPGMod : public CModule {
|
|||
}
|
||||
|
||||
CIdleRPGChannel* FindChannel(const CString& sChannel) {
|
||||
map<CString, CIdleRPGChannel*>::iterator it =
|
||||
m_Channels.find(sChannel);
|
||||
map<CString, CIdleRPGChannel*>::iterator it = m_Channels.find(sChannel);
|
||||
|
||||
return (it != m_Channels.end()) ? it->second : nullptr;
|
||||
}
|
||||
|
||||
void CommandList () {
|
||||
void CommandList() {
|
||||
if (m_Channels.empty()) {
|
||||
PutModule(t_s("No channels setup yet. Try: help add"));
|
||||
return;
|
||||
|
@ -127,9 +127,10 @@ class CIdleRPGMod : public CModule {
|
|||
PutModule(Table);
|
||||
}
|
||||
|
||||
void CommandAdd (const CString& sLine) {
|
||||
void CommandAdd(const CString& sLine) {
|
||||
if (sLine.Token(1).empty()) {
|
||||
PutModule(t_s("Usage: Add <#channel> <botnick> <username> <password>"));
|
||||
PutModule(
|
||||
t_s("Usage: Add <#channel> <botnick> <username> <password>"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,22 +157,23 @@ class CIdleRPGMod : public CModule {
|
|||
}
|
||||
|
||||
CIdleRPGChannel* pChannel = new CIdleRPGChannel();
|
||||
pChannel->FromString(sChannel+" "+sBotnick+" "+sUsername+" "+sPassword);
|
||||
pChannel->FromString(sChannel + " " + sBotnick + " " + sUsername + " " +
|
||||
sPassword);
|
||||
m_Channels[pChannel->GetChannel()] = pChannel;
|
||||
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) {
|
||||
if (sLine.Token(1).empty()) {
|
||||
PutModule(t_s("Usage: Del <#channel>"));
|
||||
return;
|
||||
}
|
||||
CString sChannel = sLine.Token(1).AsLower();
|
||||
|
||||
map<CString, CIdleRPGChannel*>::iterator it =
|
||||
m_Channels.find(sChannel);
|
||||
map<CString, CIdleRPGChannel*>::iterator it = m_Channels.find(sChannel);
|
||||
|
||||
if (it == m_Channels.end()) {
|
||||
PutModule(t_f("Channel {1} not found")(sChannel));
|
||||
|
@ -184,7 +186,7 @@ class CIdleRPGMod : public CModule {
|
|||
PutModule(t_f("Channel {1} removed")(sChannel));
|
||||
}
|
||||
|
||||
void CommandLogin (const CString& sLine) {
|
||||
void CommandLogin(const CString& sLine) {
|
||||
CString sChannel = sLine.Token(1).AsLower();
|
||||
if (!sChannel.empty()) {
|
||||
CIdleRPGChannel* fChannel = FindChannel(sChannel);
|
||||
|
@ -203,40 +205,50 @@ class CIdleRPGMod : public CModule {
|
|||
}
|
||||
}
|
||||
|
||||
void CommandClear () {
|
||||
void CommandClear() {
|
||||
ClearNV();
|
||||
m_Channels.clear();
|
||||
PutModule(t_s("All settings cleared!"));
|
||||
}
|
||||
|
||||
void QueueLogin(CIdleRPGChannel* sChan) {
|
||||
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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
void Login(CIdleRPGChannel* sChan) {
|
||||
// Valid channel?
|
||||
CChan* pChan = this->GetNetwork()->FindChan(sChan->GetChannel());
|
||||
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;
|
||||
}
|
||||
|
||||
// Botnick on channel?
|
||||
CNick* pBot = pChan->FindNick(sChan->GetBotnick());
|
||||
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;
|
||||
}
|
||||
|
||||
// Bot has 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;
|
||||
}
|
||||
|
||||
PutIRC("PRIVMSG " + sChan->GetBotnick() + " :login " + sChan->GetUsername() + " " + sChan->GetPassword());
|
||||
PutModule(t_s("Logging you in with "+sChan->GetBotnick()+" on "+sChan->GetChannel()));
|
||||
PutIRC("PRIVMSG " + sChan->GetBotnick() + " :login " +
|
||||
sChan->GetUsername() + " " + sChan->GetPassword());
|
||||
PutModule(t_s("Logging you in with " + sChan->GetBotnick() + " on " +
|
||||
sChan->GetChannel()));
|
||||
}
|
||||
|
||||
void OnJoin(const CNick& Nick, CChan& Channel) override {
|
||||
|
@ -252,7 +264,8 @@ class CIdleRPGMod : public CModule {
|
|||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -263,7 +276,9 @@ class CIdleRPGMod : public CModule {
|
|||
map<CString, CIdleRPGChannel*> m_Channels;
|
||||
};
|
||||
|
||||
void CIdleRPGModTimer::RunJob() { ((CIdleRPGMod*)GetModule())->Login(pChannel); }
|
||||
void CIdleRPGModTimer::RunJob() {
|
||||
((CIdleRPGMod*)GetModule())->Login(pChannel);
|
||||
}
|
||||
|
||||
template <>
|
||||
void TModInfo<CIdleRPGMod>(CModInfo& Info) {
|
||||
|
@ -271,4 +286,6 @@ void TModInfo<CIdleRPGMod>(CModInfo& Info) {
|
|||
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"))
|
Loading…
Add table
Reference in a new issue