2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
27 #include "modules/ctctags.h"
28 #include "modules/who.h"
29 #include "modules/whois.h"
37 class BotTag : public ClientProtocol::MessageTagProvider
40 SimpleUserModeHandler& botmode;
41 CTCTags::CapReference ctctagcap;
44 BotTag(Module* mod, SimpleUserModeHandler& bm)
45 : ClientProtocol::MessageTagProvider(mod)
51 void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
53 User* const user = msg.GetSourceUser();
54 if (user && user->IsModeSet(botmode))
55 msg.AddTag("inspircd.org/bot", this, "");
58 bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE
60 return ctctagcap.get(user);
66 , public Who::EventListener
67 , public Whois::EventListener
70 SimpleUserModeHandler bm;
76 : Who::EventListener(this)
77 , Whois::EventListener(this)
78 , bm(this, "bot", 'B')
83 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
85 forcenotice = ServerInstance->Config->ConfValue("botmode")->getBool("forcenotice");
88 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
90 tokens["BOT"] = ConvToStr(bm.GetModeChar());
93 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
95 // Allow sending if forcenotice is off, the user is not a bot, or if the message is a notice.
96 if (!forcenotice || !user->IsModeSet(bm) || details.type == MSG_NOTICE)
97 return MOD_RES_PASSTHRU;
99 // Allow sending PRIVMSGs to services pseudoclients.
100 if (target.type == MessageTarget::TYPE_USER && target.Get<User>()->server->IsULine())
101 return MOD_RES_PASSTHRU;
103 // Force the message to be broadcast as a NOTICE.
104 details.type = MSG_NOTICE;
105 return MOD_RES_PASSTHRU;
108 ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE
111 if (!request.GetFieldIndex('f', flag_index))
112 return MOD_RES_PASSTHRU;
114 if (user->IsModeSet(bm))
115 numeric.GetParams()[flag_index].push_back('B');
117 return MOD_RES_PASSTHRU;
120 Version GetVersion() CXX11_OVERRIDE
122 return Version("Adds user mode B (bot) which marks users with it set as bots in their /WHOIS response.",VF_VENDOR);
125 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
127 if (whois.GetTarget()->IsModeSet(bm))
129 whois.SendLine(RPL_WHOISBOT, "is a bot on " + ServerInstance->Config->Network);
134 MODULE_INIT(ModuleBotMode)