]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_botmode.cpp
Allow enabling the message-tags cap without client-only tags.
[user/henk/code/inspircd.git] / src / modules / m_botmode.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012, 2015 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012 Shawn Smith <ShawnSmith0828@gmail.com>
7  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2004, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "modules/ctctags.h"
28 #include "modules/whois.h"
29
30 enum
31 {
32         // From UnrealIRCd.
33         RPL_WHOISBOT = 335
34 };
35
36 class BotTag : public ClientProtocol::MessageTagProvider
37 {
38  private:
39         SimpleUserModeHandler& botmode;
40         CTCTags::CapReference ctctagcap;
41
42  public:
43         BotTag(Module* mod, SimpleUserModeHandler& bm)
44                 : ClientProtocol::MessageTagProvider(mod)
45                 , botmode(bm)
46                 , ctctagcap(mod)
47         {
48         }
49
50         void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
51         {
52                 User* const user = msg.GetSourceUser();
53                 if (user && user->IsModeSet(botmode))
54                         msg.AddTag("inspircd.org/bot", this, "");
55         }
56
57         bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE
58         {
59                 return ctctagcap.get(user);
60         }
61 };
62
63 class ModuleBotMode : public Module, public Whois::EventListener
64 {
65  private:
66         SimpleUserModeHandler bm;
67         BotTag tag;
68
69  public:
70         ModuleBotMode()
71                 : Whois::EventListener(this)
72                 , bm(this, "bot", 'B')
73                 , tag(this, bm)
74         {
75         }
76
77         Version GetVersion() CXX11_OVERRIDE
78         {
79                 return Version("Adds user mode B (bot) which marks users with it set as bots in their /WHOIS response.",VF_VENDOR);
80         }
81
82         void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
83         {
84                 if (whois.GetTarget()->IsModeSet(bm))
85                 {
86                         whois.SendLine(RPL_WHOISBOT, "is a bot on " + ServerInstance->Config->Network);
87                 }
88         }
89 };
90
91 MODULE_INIT(ModuleBotMode)