2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
7 * Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "core_channel.h"
31 CommandTopic::CommandTopic(Module* parent)
32 : SplitCommand(parent, "TOPIC", 1, 2)
33 , exemptionprov(parent)
34 , secretmode(parent, "secret")
35 , topiclockmode(parent, "topiclock")
37 syntax = "<channel> [:<topic>]";
41 CmdResult CommandTopic::HandleLocal(LocalUser* user, const Params& parameters)
43 Channel* c = ServerInstance->FindChan(parameters[0]);
46 user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
50 if (parameters.size() == 1)
52 if ((c->IsModeSet(secretmode)) && (!c->HasUser(user) && !user->HasPrivPermission("channels/auspex")))
54 user->WriteNumeric(Numerics::NoSuchChannel(c->name));
58 if (c->topic.length())
60 Topic::ShowTopic(user, c);
64 user->WriteNumeric(RPL_NOTOPICSET, c->name, "No topic is set.");
69 std::string t = parameters[1]; // needed, in case a module wants to change it
71 FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t));
73 if (res == MOD_RES_DENY)
75 if (res != MOD_RES_ALLOW)
77 if (!c->HasUser(user))
79 user->WriteNumeric(ERR_NOTONCHANNEL, c->name, "You're not on that channel!");
82 if (c->IsModeSet(topiclockmode))
84 ModResult MOD_RESULT = CheckExemption::Call(exemptionprov, user, c, "topiclock");
85 if (!MOD_RESULT.check(c->GetPrefixValue(user) >= HALFOP_VALUE))
87 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, "You do not have access to change the topic on this channel");
93 // Make sure the topic is not longer than the limit in the config
94 if (t.length() > ServerInstance->Config->Limits.MaxTopic)
95 t.erase(ServerInstance->Config->Limits.MaxTopic);
97 // Only change if the new topic is different than the current one
99 c->SetTopic(user, t, ServerInstance->Time());
103 void Topic::ShowTopic(LocalUser* user, Channel* chan)
105 user->WriteNumeric(RPL_TOPIC, chan->name, chan->topic);
106 user->WriteNumeric(RPL_TOPICTIME, chan->name, chan->setby, (unsigned long)chan->topicset);