2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2017-2023 Sadie Powell <sadie@witchery.services>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012, 2015 Attila Molnar <attilamolnar@hush.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>
|
2022-12-30 11:31:28 +00:00
|
|
|
* Copyright (C) 2004 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"
|
2020-03-11 19:51:26 +00:00
|
|
|
#include "modules/ctctags.h"
|
2020-06-08 18:14:19 +01:00
|
|
|
#include "modules/isupport.h"
|
2020-06-06 17:55:06 +01:00
|
|
|
#include "modules/who.h"
|
2018-04-07 15:48:30 +01:00
|
|
|
#include "modules/whois.h"
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2021-10-01 06:36:26 +01:00
|
|
|
class BotTag final
|
2022-11-29 05:12:42 +00:00
|
|
|
: public CTCTags::TagProvider
|
2019-03-30 11:52:36 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2021-06-01 01:48:14 +01:00
|
|
|
SimpleUserMode& botmode;
|
2019-03-30 11:52:36 +00:00
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2021-06-01 01:48:14 +01:00
|
|
|
BotTag(Module* mod, SimpleUserMode& bm)
|
2022-11-29 05:12:42 +00:00
|
|
|
: CTCTags::TagProvider(mod)
|
2019-03-30 11:52:36 +00:00
|
|
|
, botmode(bm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-30 22:06:19 +00:00
|
|
|
void OnPopulateTags(ClientProtocol::Message& msg) override
|
2019-03-30 11:52:36 +00:00
|
|
|
{
|
|
|
|
User* const user = msg.GetSourceUser();
|
|
|
|
if (user && user->IsModeSet(botmode))
|
2022-04-26 17:05:12 +01:00
|
|
|
msg.AddTag("bot", this, "");
|
2019-03-30 11:52:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-04 17:07:51 +01:00
|
|
|
class ModuleBotMode final
|
2020-06-06 17:55:06 +01:00
|
|
|
: public Module
|
2020-06-08 18:14:19 +01:00
|
|
|
, public ISupport::EventListener
|
2020-06-06 17:55:06 +01:00
|
|
|
, public Who::EventListener
|
|
|
|
, public Whois::EventListener
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2022-01-25 13:59:42 +00:00
|
|
|
private:
|
2021-06-01 01:48:14 +01:00
|
|
|
SimpleUserMode bm;
|
2019-03-30 11:52:36 +00:00
|
|
|
BotTag tag;
|
2020-07-07 01:42:38 +01:00
|
|
|
bool forcenotice;
|
2019-03-30 11:52:36 +00:00
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2009-09-26 14:13:13 +00:00
|
|
|
ModuleBotMode()
|
2020-04-11 14:00:48 +01:00
|
|
|
: Module(VF_VENDOR, "Adds user mode B (bot) which marks users with it set as bots in their /WHOIS response.")
|
2020-06-08 18:14:19 +01:00
|
|
|
, ISupport::EventListener(this)
|
|
|
|
, Who::EventListener(this)
|
2020-04-09 18:57:50 +01: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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:00:24 +01:00
|
|
|
void ReadConfig(ConfigStatus& status) override
|
2020-07-07 01:42:38 +01:00
|
|
|
{
|
|
|
|
forcenotice = ServerInstance->Config->ConfValue("botmode")->getBool("forcenotice");
|
|
|
|
}
|
|
|
|
|
2020-06-08 18:14:19 +01:00
|
|
|
void OnBuildISupport(ISupport::TokenMap& tokens) override
|
2020-06-06 17:55:06 +01:00
|
|
|
{
|
|
|
|
tokens["BOT"] = ConvToStr(bm.GetModeChar());
|
|
|
|
}
|
|
|
|
|
2023-11-15 22:17:18 +00:00
|
|
|
ModResult OnUserPreMessage(User* user, MessageTarget& target, MessageDetails& details) override
|
2020-07-07 01:42:38 +01:00
|
|
|
{
|
|
|
|
// Allow sending if forcenotice is off, the user is not a bot, or if the message is a notice.
|
2023-01-22 21:48:22 +00:00
|
|
|
if (!forcenotice || !user->IsModeSet(bm) || details.type == MessageType::NOTICE)
|
2020-07-07 01:42:38 +01:00
|
|
|
return MOD_RES_PASSTHRU;
|
|
|
|
|
|
|
|
// Allow sending PRIVMSGs to services pseudoclients.
|
2021-01-30 14:19:23 +00:00
|
|
|
if (target.type == MessageTarget::TYPE_USER && target.Get<User>()->server->IsService())
|
2020-07-07 01:42:38 +01:00
|
|
|
return MOD_RES_PASSTHRU;
|
|
|
|
|
|
|
|
// Force the message to be broadcast as a NOTICE.
|
2023-01-22 21:48:22 +00:00
|
|
|
details.type = MessageType::NOTICE;
|
2020-07-07 01:42:38 +01:00
|
|
|
return MOD_RES_PASSTHRU;
|
|
|
|
}
|
|
|
|
|
2020-06-08 18:14:19 +01:00
|
|
|
ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) override
|
2020-06-06 17:55:06 +01:00
|
|
|
{
|
|
|
|
size_t flag_index;
|
|
|
|
if (!request.GetFieldIndex('f', flag_index))
|
|
|
|
return MOD_RES_PASSTHRU;
|
|
|
|
|
|
|
|
if (user->IsModeSet(bm))
|
|
|
|
numeric.GetParams()[flag_index].push_back('B');
|
|
|
|
|
|
|
|
return MOD_RES_PASSTHRU;
|
|
|
|
}
|
|
|
|
|
2019-01-25 02:52:11 +00:00
|
|
|
void OnWhois(Whois::Context& whois) 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
|
|
|
{
|
2024-11-05 20:41:10 +00:00
|
|
|
whois.SendLine(RPL_WHOISBOT, "is a bot");
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_INIT(ModuleBotMode)
|