From 180b8b6ab194fd74cb5c64fc3ec0775eb542451a Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 30 Mar 2019 11:52:36 +0000 Subject: Mark messages with inspircd.org/bot if the user has +B set. --- src/modules/m_botmode.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/modules/m_botmode.cpp') diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp index 1931666d1..1007f7ca1 100644 --- a/src/modules/m_botmode.cpp +++ b/src/modules/m_botmode.cpp @@ -20,6 +20,7 @@ #include "inspircd.h" +#include "modules/cap.h" #include "modules/whois.h" enum @@ -28,13 +29,44 @@ enum RPL_WHOISBOT = 335 }; +class BotTag : public ClientProtocol::MessageTagProvider +{ + private: + SimpleUserModeHandler& botmode; + Cap::Reference ctctagcap; + + public: + BotTag(Module* mod, SimpleUserModeHandler& bm) + : ClientProtocol::MessageTagProvider(mod) + , botmode(bm) + , ctctagcap(mod, "message-tags") + { + } + + void OnClientProtocolPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE + { + User* const user = msg.GetSourceUser(); + if (user && user->IsModeSet(botmode)) + msg.AddTag("inspircd.org/bot", this, ""); + } + + bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE + { + return ctctagcap.get(user); + } +}; + class ModuleBotMode : public Module, public Whois::EventListener { + private: SimpleUserModeHandler bm; + BotTag tag; + public: ModuleBotMode() : Whois::EventListener(this) , bm(this, "bot", 'B') + , tag(this, bm) { } -- cgit v1.3.1-10-gc9f91 From bdded70ac222c997aea8e8fefb029571398c611e Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 30 Mar 2019 11:53:51 +0000 Subject: Rename OnClientProtocolPopulateTags to OnPopulateTags. --- include/clientprotocol.h | 2 +- include/modules/ircv3.h | 2 +- src/clientprotocol.cpp | 2 +- src/modules/m_botmode.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/modules/m_botmode.cpp') diff --git a/include/clientprotocol.h b/include/clientprotocol.h index ec033e166..44896a3a3 100644 --- a/include/clientprotocol.h +++ b/include/clientprotocol.h @@ -537,7 +537,7 @@ class ClientProtocol::MessageTagProvider : public Events::ModuleEventListener * The default implementation does nothing. * @param msg Message to be populated with tags. */ - virtual void OnClientProtocolPopulateTags(ClientProtocol::Message& msg) + virtual void OnPopulateTags(ClientProtocol::Message& msg) { } diff --git a/include/modules/ircv3.h b/include/modules/ircv3.h index 9729e8ed5..ce2b70da7 100644 --- a/include/modules/ircv3.h +++ b/include/modules/ircv3.h @@ -75,7 +75,7 @@ class IRCv3::CapTag : public ClientProtocol::MessageTagProvider return cap.get(user); } - void OnClientProtocolPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE + void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE { T& tag = static_cast(*this); const std::string* const val = tag.GetValue(msg); diff --git a/src/clientprotocol.cpp b/src/clientprotocol.cpp index 212d65d6b..ee3909fbf 100644 --- a/src/clientprotocol.cpp +++ b/src/clientprotocol.cpp @@ -63,7 +63,7 @@ const ClientProtocol::SerializedMessage& ClientProtocol::Serializer::SerializeFo if (!msg.msginit_done) { msg.msginit_done = true; - FOREACH_MOD_CUSTOM(evprov, MessageTagProvider, OnClientProtocolPopulateTags, (msg)); + FOREACH_MOD_CUSTOM(evprov, MessageTagProvider, OnPopulateTags, (msg)); } return msg.GetSerialized(Message::SerializedInfo(this, MakeTagWhitelist(user, msg.GetTags()))); } diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp index 1007f7ca1..44241e82c 100644 --- a/src/modules/m_botmode.cpp +++ b/src/modules/m_botmode.cpp @@ -43,7 +43,7 @@ class BotTag : public ClientProtocol::MessageTagProvider { } - void OnClientProtocolPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE + void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE { User* const user = msg.GetSourceUser(); if (user && user->IsModeSet(botmode)) -- cgit v1.3.1-10-gc9f91