2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
|
|
|
|
* Copyright (C) 2012, 2015 Attila Molnar <attilamolnar@hush.com>
|
|
|
|
* Copyright (C) 2012 Shawn Smith <ShawnSmith0828@gmail.com>
|
|
|
|
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2004, 2010 Craig Edwards <brain@inspircd.org>
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
#include "inspircd.h"
|
2019-03-30 11:52:36 +00:00
|
|
|
#include "modules/cap.h"
|
2018-04-07 15:48:30 +01:00
|
|
|
#include "modules/whois.h"
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2017-12-09 13:43:44 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// From UnrealIRCd.
|
2017-12-09 16:12:00 +00:00
|
|
|
RPL_WHOISBOT = 335
|
2017-12-09 13:43:44 +00:00
|
|
|
};
|
|
|
|
|
2019-03-30 11:52:36 +00:00
|
|
|
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")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-30 11:53:51 +00:00
|
|
|
void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
|
2019-03-30 11:52:36 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-28 15:16:22 +02:00
|
|
|
class ModuleBotMode : public Module, public Whois::EventListener
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2019-03-30 11:52:36 +00:00
|
|
|
private:
|
2017-11-12 20:53:24 +00:00
|
|
|
SimpleUserModeHandler bm;
|
2019-03-30 11:52:36 +00:00
|
|
|
BotTag tag;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
public:
|
2009-09-26 14:13:13 +00:00
|
|
|
ModuleBotMode()
|
2015-04-28 15:16:22 +02:00
|
|
|
: Whois::EventListener(this)
|
2017-11-12 20:53:24 +00:00
|
|
|
, bm(this, "bot", 'B')
|
2019-03-30 11:52:36 +00:00
|
|
|
, tag(this, bm)
|
2012-10-13 03:12:29 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-30 08:38:33 +01:00
|
|
|
Version GetVersion() CXX11_OVERRIDE
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2012-07-06 14:23:04 -04:00
|
|
|
return Version("Provides user mode +B to mark the user as a bot",VF_VENDOR);
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 15:16:22 +02:00
|
|
|
void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2015-04-28 15:16:22 +02:00
|
|
|
if (whois.GetTarget()->IsModeSet(bm))
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2017-12-09 13:43:44 +00:00
|
|
|
whois.SendLine(RPL_WHOISBOT, "is a bot on " + ServerInstance->Config->Network);
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_INIT(ModuleBotMode)
|