Add specialized types and hooks for the most common msgs

PRIVMSG, NOTICE, JOIN, PART, QUIT, NICK, KICK, TOPIC
This commit is contained in:
J-P Nurmi
2015-07-13 20:33:48 +02:00
parent 50ab019901
commit ff181a4a85
6 changed files with 431 additions and 65 deletions
+8 -7
View File
@@ -28,6 +28,7 @@ class CChan;
class CUser;
class CIRCNetwork;
class CClient;
class CMessage;
// !Forward Declarations
// TODO: This class needs new name
@@ -49,13 +50,13 @@ public:
// Message Handlers
bool OnCTCPReply(CNick& Nick, CString& sMessage);
bool OnPrivCTCP(CNick& Nick, CString& sMessage);
bool OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage);
bool OnGeneralCTCP(CNick& Nick, CString& sMessage);
bool OnPrivMsg(CNick& Nick, CString& sMessage);
bool OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage);
bool OnPrivNotice(CNick& Nick, CString& sMessage);
bool OnChanNotice(CNick& Nick, const CString& sChan, CString& sMessage);
bool OnPrivCTCP(CMessage& Message);
bool OnChanCTCP(CMessage& Message);
bool OnGeneralCTCP(CMessage& Message);
bool OnPrivMsg(CMessage& Message);
bool OnChanMsg(CMessage& Message);
bool OnPrivNotice(CMessage& Message);
bool OnChanNotice(CMessage& Message);
bool OnServerCapAvailable(const CString& sCap);
// !Message Handlers
+103
View File
@@ -87,4 +87,107 @@ private:
CChan* m_pChan = nullptr;
};
class CChanAction : public CMessage {
public:
CString GetText() const { return GetParam(1).TrimLeft_n("\001ACTION ").TrimRight_n("\001"); }
void SetText(const CString& sText) { SetParam(1, "\001ACTION " + sText + "\001"); }
};
class CChanCTCP : public CMessage {
public:
CString GetText() const { return GetParam(1).TrimLeft_n("\001").TrimRight_n("\001"); }
void SetText(const CString& sText) { SetParam(1, "\001" + sText + "\001"); }
};
class CChanMessage : public CMessage {
public:
CString GetText() const { return GetParam(1); }
void SetText(const CString& sText) { SetParam(1, sText); }
};
class CChanNotice : public CMessage {
public:
CString GetText() const { return GetParam(1); }
void SetText(const CString& sText) { SetParam(1, sText); }
};
class CJoinMessage : public CMessage {
public:
};
class CNickMessage : public CMessage {
public:
CString GetOldNick() const { return GetNick().GetNick(); }
CString GetNewNick() const { return GetParam(0); }
void SetNewNick(const CString& sNick) { SetParam(0, sNick); }
};
class CKickMessage : public CMessage {
public:
CString GetKickedNick() const { return GetParam(1); }
void SetKickedNick(const CString& sNick) { SetParam(1, sNick); }
CString GetReason() const { return GetParam(2); }
void SetReason(const CString& sReason) { SetParam(2, sReason); }
};
class CPartMessage : public CMessage {
public:
CString GetReason() const { return GetParam(1); }
void SetReason(const CString& sReason) { SetParam(1, sReason); }
};
class CPrivAction : public CMessage {
public:
CString GetText() const { return GetParam(1).TrimLeft_n("\001ACTION ").TrimRight_n("\001"); }
void SetText(const CString& sText) { SetParam(1, "\001ACTION " + sText + "\001"); }
};
class CPrivCTCP : public CMessage {
public:
CString GetText() const { return GetParam(1).TrimLeft_n("\001").TrimRight_n("\001"); }
void SetText(const CString& sText) { SetParam(1, "\001" + sText + "\001"); }
};
class CPrivMessage : public CMessage {
public:
CString GetText() const { return GetParam(1); }
void SetText(const CString& sText) { SetParam(1, sText); }
};
class CPrivNotice : public CMessage {
public:
CString GetText() const { return GetParam(1); }
void SetText(const CString& sText) { SetParam(1, sText); }
};
class CQuitMessage : public CMessage {
public:
CString GetReason() const { return GetParam(0); }
void SetReason(const CString& sReason) { SetParam(0, sReason); }
};
class CTopicMessage : public CMessage {
public:
CString GetTopic() const { return GetParam(1); }
void SetTopic(const CString& sTopic) { SetParam(1, sTopic); }
};
// The various CMessage subclasses are "mutable views" to the data held by CMessage.
// They provide convenient access to message type speficic attributes, but are not
// allowed to hold extra data of their own.
static_assert(sizeof(CChanAction) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CChanCTCP) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CChanMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CChanNotice) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CJoinMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CPartMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CPrivAction) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CPrivCTCP) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CPrivMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CPrivNotice) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CNickMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CKickMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CQuitMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
static_assert(sizeof(CTopicMessage) == sizeof(CMessage), "No data members allowed in CMessage subclasses.");
#endif // !_MESSAGE_H
+29
View File
@@ -21,6 +21,7 @@
#include <znc/WebModules.h>
#include <znc/Utils.h>
#include <znc/Threads.h>
#include <znc/Message.h>
#include <znc/main.h>
#include <functional>
#include <set>
@@ -593,6 +594,7 @@ public:
* @param vChans List of channels which you and nick share.
*/
virtual void OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
virtual void OnQuitMessage(CQuitMessage& Message, const std::vector<CChan*>& vChans);
/** Called when a nickname change occurs. If we are changing our nick,
* sNewNick will equal m_pIRCSock->GetNick().
* @param Nick The nick which changed its nickname
@@ -600,6 +602,7 @@ public:
* @param vChans Channels which we and nick share.
*/
virtual void OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
virtual void OnNickMessage(CNickMessage& Message, const std::vector<CChan*>& vChans);
/** Called when a nick is kicked from a channel.
* @param OpNick The nick which generated the kick.
* @param sKickedNick The nick which was kicked.
@@ -607,6 +610,7 @@ public:
* @param sMessage The kick message.
*/
virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
virtual void OnKickMessage(CKickMessage& Message);
/** This module hook is called just before ZNC tries to join an IRC channel.
* @param Chan The channel which is about to get joined.
* @return See CModule::EModRet.
@@ -617,12 +621,14 @@ public:
* @param Channel The channel which was joined.
*/
virtual void OnJoin(const CNick& Nick, CChan& Channel);
virtual void OnJoinMessage(CJoinMessage& Message);
/** Called when a nick parts a channel.
* @param Nick The nick who parted.
* @param Channel The channel which was parted.
* @param sMessage The part message.
*/
virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
virtual void OnPartMessage(CPartMessage& Message);
/** Called when user is invited into a channel
* @param Nick The nick who invited you.
* @param sChan The channel the user got invited into
@@ -749,6 +755,7 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage);
virtual EModRet OnPrivCTCPMessage(CPrivCTCP& Message);
/** Called when we receive a channel CTCP request <em>from IRC</em>.
* @param Nick The nick the CTCP request is from.
* @param Channel The channel to which the request was sent.
@@ -756,6 +763,7 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage);
virtual EModRet OnChanCTCPMessage(CChanCTCP& Message);
/** Called when we receive a private CTCP ACTION ("/me" in query) <em>from IRC</em>.
* This is called after CModule::OnPrivCTCP().
* @param Nick The nick the action came from.
@@ -763,6 +771,7 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivAction(CNick& Nick, CString& sMessage);
virtual EModRet OnPrivActionMessage(CPrivAction& Message);
/** Called when we receive a channel CTCP ACTION ("/me" in a channel) <em>from IRC</em>.
* This is called after CModule::OnChanCTCP().
* @param Nick The nick the action came from.
@@ -771,12 +780,14 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage);
virtual EModRet OnChanActionMessage(CChanAction& Message);
/** Called when we receive a private message <em>from IRC</em>.
* @param Nick The nick which sent the message.
* @param sMessage The message.
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage);
virtual EModRet OnPrivMessage(CPrivMessage& Message);
/** Called when we receive a channel message <em>from IRC</em>.
* @param Nick The nick which sent the message.
* @param Channel The channel to which the message was sent.
@@ -784,12 +795,14 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage);
virtual EModRet OnChanMessage(CChanMessage& Message);
/** Called when we receive a private notice.
* @param Nick The nick which sent the notice.
* @param sMessage The notice message.
* @return See CModule::EModRet.
*/
virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage);
virtual EModRet OnPrivNoticeMessage(CPrivNotice& Message);
/** Called when we receive a channel notice.
* @param Nick The nick which sent the notice.
* @param Channel The channel to which the notice was sent.
@@ -797,6 +810,7 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage);
virtual EModRet OnChanNoticeMessage(CChanNotice& Message);
/** Called when we receive a channel topic change <em>from IRC</em>.
* @param Nick The nick which changed the topic.
* @param Channel The channel whose topic was changed.
@@ -804,6 +818,7 @@ public:
* @return See CModule::EModRet.
*/
virtual EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic);
virtual EModRet OnTopicMessage(CTopicMessage& Message);
/** Called for every CAP received via CAP LS from server.
* @param sCap capability supported by server.
@@ -1186,11 +1201,16 @@ public:
bool OnModCTCP(const CString& sMessage);
bool OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
bool OnQuitMessage(CQuitMessage& Message, const std::vector<CChan*>& vChans);
bool OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
bool OnNickMessage(CNickMessage& Message, const std::vector<CChan*>& vChans);
bool OnKick(const CNick& Nick, const CString& sOpNick, CChan& Channel, const CString& sMessage);
bool OnKickMessage(CKickMessage& Message);
bool OnJoining(CChan& Channel);
bool OnJoin(const CNick& Nick, CChan& Channel);
bool OnJoinMessage(CJoinMessage& Message);
bool OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
bool OnPartMessage(CPartMessage& Message);
bool OnInvite(const CNick& Nick, const CString& sChan);
bool OnChanBufferStarting(CChan& Chan, CClient& Client);
@@ -1216,14 +1236,23 @@ public:
bool OnCTCPReply(CNick& Nick, CString& sMessage);
bool OnPrivCTCP(CNick& Nick, CString& sMessage);
bool OnPrivCTCPMessage(CPrivCTCP& Message);
bool OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage);
bool OnChanCTCPMessage(CChanCTCP& Message);
bool OnPrivAction(CNick& Nick, CString& sMessage);
bool OnPrivActionMessage(CPrivAction& Message);
bool OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage);
bool OnChanActionMessage(CChanAction& Message);
bool OnPrivMsg(CNick& Nick, CString& sMessage);
bool OnPrivMessage(CPrivMessage& Message);
bool OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage);
bool OnChanMessage(CChanMessage& Message);
bool OnPrivNotice(CNick& Nick, CString& sMessage);
bool OnPrivNoticeMessage(CPrivNotice& Message);
bool OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage);
bool OnChanNoticeMessage(CChanNotice& Message);
bool OnTopic(CNick& Nick, CChan& Channel, CString& sTopic);
bool OnTopicMessage(CTopicMessage& Message);
bool OnTimerAutoJoin(CChan& Channel);
bool OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet);