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, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "modules/ctctags.h"
26 class DelayMsgMode : public ParamMode<DelayMsgMode, LocalIntExt>
30 DelayMsgMode(Module* Parent)
31 : ParamMode<DelayMsgMode, LocalIntExt>(Parent, "delaymsg", 'd')
32 , jointime("delaymsg", ExtensionItem::EXT_MEMBERSHIP, Parent)
34 ranktoset = ranktounset = OP_VALUE;
38 bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE
40 return ConvToNum<intptr_t>(their_param) < ConvToNum<intptr_t>(our_param);
43 ModeAction OnSet(User* source, Channel* chan, std::string& parameter) CXX11_OVERRIDE;
44 void OnUnset(User* source, Channel* chan) CXX11_OVERRIDE;
46 void SerializeParam(Channel* chan, intptr_t n, std::string& out)
54 , public CTCTags::EventListener
59 ModResult HandleMessage(User* user, const MessageTarget& target, bool notice);
63 : CTCTags::EventListener(this)
68 Version GetVersion() CXX11_OVERRIDE;
69 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
70 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE;
71 ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
72 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
75 ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter)
77 // Setting a new limit, sanity check
78 intptr_t limit = ConvToNum<intptr_t>(parameter);
83 return MODEACTION_ALLOW;
86 void DelayMsgMode::OnUnset(User* source, Channel* chan)
91 const Channel::MemberMap& users = chan->GetUsers();
92 for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n)
93 jointime.set(n->second, 0);
96 Version ModuleDelayMsg::GetVersion()
98 return Version("Adds channel mode d (delaymsg) which prevents newly joined users from speaking until the specified number of seconds have passed.", VF_VENDOR);
101 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
103 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
105 djm.jointime.set(memb, ServerInstance->Time());
109 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details)
111 return HandleMessage(user, target, details.type == MSG_NOTICE);
114 ModResult ModuleDelayMsg::OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details)
116 return HandleMessage(user, target, false);
119 ModResult ModuleDelayMsg::HandleMessage(User* user, const MessageTarget& target, bool notice)
122 return MOD_RES_PASSTHRU;
124 if ((target.type != MessageTarget::TYPE_CHANNEL) || ((!allownotice) && (notice)))
125 return MOD_RES_PASSTHRU;
127 Channel* channel = target.Get<Channel>();
128 Membership* memb = channel->GetUser(user);
131 return MOD_RES_PASSTHRU;
133 time_t ts = djm.jointime.get(memb);
136 return MOD_RES_PASSTHRU;
138 int len = djm.ext.get(channel);
140 if ((ts + len) > ServerInstance->Time())
142 if (channel->GetPrefixValue(user) < VOICE_VALUE)
144 const std::string message = InspIRCd::Format("You cannot send messages to this channel until you have been a member for %d seconds.", len);
145 user->WriteNumeric(Numerics::CannotSendTo(channel, message));
151 /* Timer has expired, we can stop checking now */
152 djm.jointime.set(memb, 0);
154 return MOD_RES_PASSTHRU;
157 void ModuleDelayMsg::ReadConfig(ConfigStatus& status)
159 ConfigTag* tag = ServerInstance->Config->ConfValue("delaymsg");
160 allownotice = tag->getBool("allownotice", true);
163 MODULE_INIT(ModuleDelayMsg)