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/>.
32 typedef std::map<std::string, std::string, irc::insensitive_swo> HelpopMap;
33 static HelpopMap helpop_map;
35 /** Handles user mode +h
37 class Helpop : public SimpleUserModeHandler
40 Helpop(Module* Creator) : SimpleUserModeHandler(Creator, "helpop", 'h')
48 class CommandHelpop : public Command
50 const std::string startkey;
52 CommandHelpop(Module* Creator)
53 : Command(Creator, "HELPOP", 0)
56 syntax = "<any-text>";
59 CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
61 const std::string& parameter = (!parameters.empty() ? parameters[0] : startkey);
63 if (parameter == "index")
65 /* iterate over all helpop items */
66 user->WriteNumeric(290, "HELPOP topic index");
67 for (HelpopMap::const_iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
68 user->WriteNumeric(292, InspIRCd::Format(" %s", iter->first.c_str()));
69 user->WriteNumeric(292, "*** End of HELPOP topic index");
73 user->WriteNumeric(290, InspIRCd::Format("*** HELPOP for %s", parameter.c_str()));
74 user->WriteNumeric(292, " -");
76 HelpopMap::const_iterator iter = helpop_map.find(parameter);
78 if (iter == helpop_map.end())
80 iter = helpop_map.find("nohelp");
83 const std::string& value = iter->second;
84 irc::sepstream stream(value, '\n');
85 std::string token = "*";
87 while (stream.GetToken(token))
89 // Writing a blank line will not work with some clients
91 user->WriteNumeric(292, ' ');
93 user->WriteNumeric(292, token);
96 user->WriteNumeric(292, " -");
97 user->WriteNumeric(292, "*** End of HELPOP");
103 class ModuleHelpop : public Module, public Whois::EventListener
110 : Whois::EventListener(this)
116 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
120 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
121 for(ConfigIter i = tags.first; i != tags.second; ++i)
123 ConfigTag* tag = i->second;
124 std::string key = tag->getString("key");
126 tag->readString("value", value, true); /* Linefeeds allowed */
130 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
136 if (help.find("start") == help.end())
139 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
141 else if (help.find("nohelp") == help.end())
144 throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf.");
147 helpop_map.swap(help);
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)