2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
5 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006-2007 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "modules/whois.h"
33 RPL_WHOISHELPOP = 310,
36 ERR_HELPNOTFOUND = 524,
42 typedef std::map<std::string, std::string, irc::insensitive_swo> HelpopMap;
43 static HelpopMap helpop_map;
47 class CommandHelpop : public Command
50 const std::string startkey;
55 CommandHelpop(Module* Creator)
56 : Command(Creator, "HELPOP", 0)
59 syntax = "<any-text>";
62 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
64 const std::string& parameter = (!parameters.empty() ? parameters[0] : startkey);
66 if (parameter == "index")
68 /* iterate over all helpop items */
69 user->WriteNumeric(RPL_HELPSTART, parameter, "HELPOP topic index");
70 for (HelpopMap::const_iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
71 user->WriteNumeric(RPL_HELPTXT, parameter, InspIRCd::Format(" %s", iter->first.c_str()));
72 user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP topic index");
76 HelpopMap::const_iterator iter = helpop_map.find(parameter);
77 if (iter == helpop_map.end())
79 user->WriteNumeric(ERR_HELPNOTFOUND, parameter, nohelp);
83 const std::string& value = iter->second;
84 irc::sepstream stream(value, '\n', true);
85 std::string token = "*";
87 user->WriteNumeric(RPL_HELPSTART, parameter, InspIRCd::Format("*** HELPOP for %s", parameter.c_str()));
88 while (stream.GetToken(token))
90 // Writing a blank line will not work with some clients
92 user->WriteNumeric(RPL_HELPTXT, parameter, ' ');
94 user->WriteNumeric(RPL_HELPTXT, parameter, token);
96 user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP");
104 , public Whois::EventListener
108 SimpleUserModeHandler ho;
112 : Whois::EventListener(this)
114 , ho(this, "helpop", 'h', true)
118 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
122 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
123 for(ConfigIter i = tags.first; i != tags.second; ++i)
125 ConfigTag* tag = i->second;
126 std::string key = tag->getString("key");
128 tag->readString("value", value, true); /* Linefeeds allowed */
132 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
138 if (help.find("start") == help.end())
141 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
144 helpop_map.swap(help);
146 ConfigTag* tag = ServerInstance->Config->ConfValue("helpmsg");
147 cmd.nohelp = tag->getString("nohelp", "There is no help for the topic you searched for. Please try again.", 1);
150 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
152 if (whois.GetTarget()->IsModeSet(ho))
154 whois.SendLine(RPL_WHOISHELPOP, "is available for help.");
158 Version GetVersion() CXX11_OVERRIDE
160 return Version("Provides the HELPOP command for useful information", VF_VENDOR);
164 MODULE_INIT(ModuleHelpop)