#include "inspircd.h"
+#include "modules/cap.h"
+#include "modules/whois.h"
-/* $ModDesc: Provides user mode +B to mark the user as a bot */
-
-/** Handles user mode +B
- */
-class BotMode : public SimpleUserModeHandler
+enum
{
- public:
- BotMode(Module* Creator) : SimpleUserModeHandler(Creator, "bot", 'B') { }
+ // From UnrealIRCd.
+ RPL_WHOISBOT = 335
};
-class ModuleBotMode : public Module
+class BotTag : public ClientProtocol::MessageTagProvider
{
- BotMode bm;
+ private:
+ SimpleUserModeHandler& botmode;
+ Cap::Reference ctctagcap;
+
public:
- ModuleBotMode()
- : bm(this)
+ BotTag(Module* mod, SimpleUserModeHandler& bm)
+ : ClientProtocol::MessageTagProvider(mod)
+ , botmode(bm)
+ , ctctagcap(mod, "message-tags")
{
}
- void init()
+ void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
{
- if (!ServerInstance->Modes->AddMode(&bm))
- throw ModuleException("Could not add new modes!");
- Implementation eventlist[] = { I_OnWhois };
- ServerInstance->Modules->Attach(eventlist, this, 1);
+ User* const user = msg.GetSourceUser();
+ if (user && user->IsModeSet(botmode))
+ msg.AddTag("inspircd.org/bot", this, "");
}
- virtual ~ModuleBotMode()
+ 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;
- virtual Version GetVersion()
+ public:
+ ModuleBotMode()
+ : Whois::EventListener(this)
+ , bm(this, "bot", 'B')
+ , tag(this, bm)
+ {
+ }
+
+ Version GetVersion() CXX11_OVERRIDE
{
return Version("Provides user mode +B to mark the user as a bot",VF_VENDOR);
}
- virtual void OnWhois(User* src, User* dst)
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- if (dst->IsModeSet('B'))
+ if (whois.GetTarget()->IsModeSet(bm))
{
- ServerInstance->SendWhoisLine(src, dst, 335, src->nick+" "+dst->nick+" :is a bot on "+ServerInstance->Config->Network);
+ whois.SendLine(RPL_WHOISBOT, "is a bot on " + ServerInstance->Config->Network);
}
}
-
};
-
MODULE_INIT(ModuleBotMode)