2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2005-2009 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2004-2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2004-2005 Craig McLure <craig@chatspike.net>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "modules/whois.h"
30 RPL_WHOISHELPOP = 310,
33 ERR_HELPNOTFOUND = 524,
39 typedef std::map<std::string, std::string, irc::insensitive_swo> HelpopMap;
40 static HelpopMap helpop_map;
42 /** Handles user mode +h
44 class Helpop : public SimpleUserModeHandler
47 Helpop(Module* Creator) : SimpleUserModeHandler(Creator, "helpop", 'h')
55 class CommandHelpop : public Command
58 const std::string startkey;
63 CommandHelpop(Module* Creator)
64 : Command(Creator, "HELPOP", 0)
67 syntax = "<any-text>";
70 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
72 const std::string& parameter = (!parameters.empty() ? parameters[0] : startkey);
74 if (parameter == "index")
76 /* iterate over all helpop items */
77 user->WriteNumeric(RPL_HELPSTART, parameter, "HELPOP topic index");
78 for (HelpopMap::const_iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
79 user->WriteNumeric(RPL_HELPTXT, parameter, InspIRCd::Format(" %s", iter->first.c_str()));
80 user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP topic index");
84 HelpopMap::const_iterator iter = helpop_map.find(parameter);
85 if (iter == helpop_map.end())
87 user->WriteNumeric(ERR_HELPNOTFOUND, parameter, nohelp);
91 const std::string& value = iter->second;
92 irc::sepstream stream(value, '\n', true);
93 std::string token = "*";
95 user->WriteNumeric(RPL_HELPSTART, parameter, InspIRCd::Format("*** HELPOP for %s", parameter.c_str()));
96 while (stream.GetToken(token))
98 // Writing a blank line will not work with some clients
100 user->WriteNumeric(RPL_HELPTXT, parameter, ' ');
102 user->WriteNumeric(RPL_HELPTXT, parameter, token);
104 user->WriteNumeric(RPL_ENDOFHELP, parameter, "*** End of HELPOP");
110 class ModuleHelpop : public Module, public Whois::EventListener
117 : Whois::EventListener(this)
123 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
127 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
128 for(ConfigIter i = tags.first; i != tags.second; ++i)
130 ConfigTag* tag = i->second;
131 std::string key = tag->getString("key");
133 tag->readString("value", value, true); /* Linefeeds allowed */
137 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
143 if (help.find("start") == help.end())
146 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
149 helpop_map.swap(help);
151 ConfigTag* tag = ServerInstance->Config->ConfValue("helpmsg");
152 cmd.nohelp = tag->getString("nohelp", "There is no help for the topic you searched for. Please try again.", 1);
155 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
157 if (whois.GetTarget()->IsModeSet(ho))
159 whois.SendLine(RPL_WHOISHELPOP, "is available for help.");
163 Version GetVersion() CXX11_OVERRIDE
165 return Version("Provides the HELPOP command for useful information", VF_VENDOR);
169 MODULE_INIT(ModuleHelpop)