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 static std::map<irc::string, std::string> helpop_map;
28 /** Handles user mode +h
30 class Helpop : public SimpleUserModeHandler
33 Helpop(Module* Creator) : SimpleUserModeHandler(Creator, "helpop", 'h')
41 class CommandHelpop : public Command
44 CommandHelpop(Module* Creator) : Command(Creator, "HELPOP", 0)
46 syntax = "<any-text>";
49 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
51 irc::string parameter("start");
52 if (parameters.size() > 0)
53 parameter = parameters[0].c_str();
55 if (parameter == "index")
57 /* iterate over all helpop items */
58 user->WriteNumeric(290, ":HELPOP topic index");
59 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
60 user->WriteNumeric(292, ": %s", iter->first.c_str());
61 user->WriteNumeric(292, ":*** End of HELPOP topic index");
65 user->WriteNumeric(290, ":*** HELPOP for %s", parameter.c_str());
66 user->WriteNumeric(292, ": -");
68 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
70 if (iter == helpop_map.end())
72 iter = helpop_map.find("nohelp");
75 std::string value = iter->second;
76 irc::sepstream stream(value, '\n');
77 std::string token = "*";
79 while (stream.GetToken(token))
81 // Writing a blank line will not work with some clients
83 user->WriteNumeric(292, ": ");
85 user->WriteNumeric(292, ":%s", token.c_str());
88 user->WriteNumeric(292, ": -");
89 user->WriteNumeric(292, ":*** End of HELPOP");
95 class ModuleHelpop : public Module
103 : cmd(this), ho(this)
107 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
111 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
112 for(ConfigIter i = tags.first; i != tags.second; ++i)
114 ConfigTag* tag = i->second;
115 irc::string key = assign(tag->getString("key"));
117 tag->readString("value", value, true); /* Linefeeds allowed */
121 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
124 helpop_map[key] = value;
127 if (helpop_map.find("start") == helpop_map.end())
130 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
132 else if (helpop_map.find("nohelp") == helpop_map.end())
135 throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf.");
140 void OnWhois(User* src, User* dst) CXX11_OVERRIDE
142 if (dst->IsModeSet(ho))
144 ServerInstance->SendWhoisLine(src, dst, 310, dst->nick+" :is available for help.");
148 Version GetVersion() CXX11_OVERRIDE
150 return Version("Provides the /HELPOP command for useful information", VF_VENDOR);
154 MODULE_INIT(ModuleHelpop)