2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2008 Thomas Stagner <aquanight@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/>.
27 class CommandTopic : public SplitCommand
29 ChanModeReference secretmode;
30 ChanModeReference topiclockmode;
33 /** Constructor for topic.
35 CommandTopic(Module* parent)
36 : SplitCommand(parent, "TOPIC", 1, 2)
37 , secretmode(parent, "secret")
38 , topiclockmode(parent, "topiclock")
40 syntax = "<channel> [<topic>]";
45 * @param parameters The parameters to the command
46 * @param user The user issuing the command
47 * @return A value from CmdResult to indicate command success or failure.
49 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
52 CmdResult CommandTopic::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
54 Channel* c = ServerInstance->FindChan(parameters[0]);
57 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
61 if (parameters.size() == 1)
63 if ((c->IsModeSet(secretmode)) && (!c->HasUser(user)))
65 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", c->name.c_str());
69 if (c->topic.length())
71 user->WriteNumeric(RPL_TOPIC, "%s :%s", c->name.c_str(), c->topic.c_str());
72 user->WriteNumeric(RPL_TOPICTIME, "%s %s %lu", c->name.c_str(), c->setby.c_str(), (unsigned long)c->topicset);
76 user->WriteNumeric(RPL_NOTOPICSET, "%s :No topic is set.", c->name.c_str());
81 std::string t = parameters[1]; // needed, in case a module wants to change it
83 FIRST_MOD_RESULT(OnPreTopicChange, res, (user,c,t));
85 if (res == MOD_RES_DENY)
87 if (res != MOD_RES_ALLOW)
89 if (!c->HasUser(user))
91 user->WriteNumeric(ERR_NOTONCHANNEL, "%s :You're not on that channel!", c->name.c_str());
94 if (c->IsModeSet(topiclockmode) && !ServerInstance->OnCheckExemption(user, c, "topiclock").check(c->GetPrefixValue(user) >= HALFOP_VALUE))
96 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You do not have access to change the topic on this channel", c->name.c_str());
101 c->SetTopic(user, t);
106 COMMAND_INIT(CommandTopic)