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/>.
26 typedef std::map<std::string, std::string, irc::insensitive_swo> HelpopMap;
27 static HelpopMap helpop_map;
29 /** Handles user mode +h
31 class Helpop : public SimpleUserModeHandler
34 Helpop(Module* Creator) : SimpleUserModeHandler(Creator, "helpop", 'h')
42 class CommandHelpop : public Command
44 const std::string startkey;
46 CommandHelpop(Module* Creator)
47 : Command(Creator, "HELPOP", 0)
50 syntax = "<any-text>";
53 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
55 const std::string& parameter = (!parameters.empty() ? parameters[0] : startkey);
57 if (parameter == "index")
59 /* iterate over all helpop items */
60 user->WriteNumeric(290, ":HELPOP topic index");
61 for (HelpopMap::const_iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
62 user->WriteNumeric(292, ": %s", iter->first.c_str());
63 user->WriteNumeric(292, ":*** End of HELPOP topic index");
67 user->WriteNumeric(290, ":*** HELPOP for %s", parameter.c_str());
68 user->WriteNumeric(292, ": -");
70 HelpopMap::const_iterator iter = helpop_map.find(parameter);
72 if (iter == helpop_map.end())
74 iter = helpop_map.find("nohelp");
77 const std::string& value = iter->second;
78 irc::sepstream stream(value, '\n');
79 std::string token = "*";
81 while (stream.GetToken(token))
83 // Writing a blank line will not work with some clients
85 user->WriteNumeric(292, ": ");
87 user->WriteNumeric(292, ":%s", token.c_str());
90 user->WriteNumeric(292, ": -");
91 user->WriteNumeric(292, ":*** End of HELPOP");
97 class ModuleHelpop : public Module, public Whois::EventListener
104 : Whois::EventListener(this)
110 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
114 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
115 for(ConfigIter i = tags.first; i != tags.second; ++i)
117 ConfigTag* tag = i->second;
118 std::string key = tag->getString("key");
120 tag->readString("value", value, true); /* Linefeeds allowed */
124 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
130 if (help.find("start") == help.end())
133 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
135 else if (help.find("nohelp") == help.end())
138 throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf.");
141 helpop_map.swap(help);
144 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
146 if (whois.GetTarget()->IsModeSet(ho))
148 whois.SendLine(310, ":is available for help.");
152 Version GetVersion() CXX11_OVERRIDE
154 return Version("Provides the /HELPOP command for useful information", VF_VENDOR);
158 MODULE_INIT(ModuleHelpop)