1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 static std::map<irc::string, std::string> helpop_map;
18 /** Handles user mode +h
20 class Helpop : public ModeHandler
23 Helpop(Module* Creator) : ModeHandler(Creator, "helpop", 'h', PARAM_NONE, MODETYPE_USER)
28 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
32 if (!dest->IsModeSet('h'))
34 dest->SetMode('h',true);
35 return MODEACTION_ALLOW;
40 if (dest->IsModeSet('h'))
42 dest->SetMode('h',false);
43 return MODEACTION_ALLOW;
47 return MODEACTION_DENY;
53 class CommandHelpop : public Command
56 CommandHelpop(Module* Creator) : Command(Creator, "HELP", 0)
58 syntax = "<any-text>";
61 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
63 irc::string parameter("start");
64 if (parameters.size() > 0)
65 parameter = parameters[0].c_str();
67 if (parameter == "index")
69 /* iterate over all helpop items */
70 user->WriteServ("290 %s :HELPOP topic index", user->nick.c_str());
71 for (std::map<irc::string, std::string>::iterator iter = helpop_map.begin(); iter != helpop_map.end(); iter++)
73 user->WriteServ("292 %s : %s", user->nick.c_str(), iter->first.c_str());
75 user->WriteServ("292 %s :*** End of HELPOP topic index", user->nick.c_str());
79 user->WriteServ("290 %s :*** HELPOP for %s", user->nick.c_str(), parameter.c_str());
80 user->WriteServ("292 %s : -", user->nick.c_str());
82 std::map<irc::string, std::string>::iterator iter = helpop_map.find(parameter);
84 if (iter == helpop_map.end())
86 iter = helpop_map.find("nohelp");
89 std::string value = iter->second;
90 irc::sepstream stream(value, '\n');
91 std::string token = "*";
93 while (stream.GetToken(token))
95 // Writing a blank line will not work with some clients
97 user->WriteServ("292 %s : ", user->nick.c_str());
99 user->WriteServ("292 %s :%s", user->nick.c_str(), token.c_str());
102 user->WriteServ("292 %s : -", user->nick.c_str());
103 user->WriteServ("292 %s :*** End of HELPOP", user->nick.c_str());
109 class ModuleHelpop : public Module
118 : cmd(this), ho(this)
125 ServerInstance->Modules->AddService(ho);
126 ServerInstance->Modules->AddService(cmd);
127 Implementation eventlist[] = { I_OnRehash, I_OnWhois };
128 ServerInstance->Modules->Attach(eventlist, this, 2);
135 ConfigTagList tags = ServerInstance->Config->ConfTags("helpop");
136 for(ConfigIter i = tags.first; i != tags.second; ++i)
138 ConfigTag* tag = i->second;
139 irc::string key = assign(tag->getString("key"));
141 tag->readString("value", value, true); /* Linefeeds allowed */
145 throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
148 helpop_map[key] = value;
151 if (helpop_map.find("start") == helpop_map.end())
154 throw ModuleException("m_helpop: Helpop file is missing important entry 'start'. Please check the example conf.");
156 else if (helpop_map.find("nohelp") == helpop_map.end())
159 throw ModuleException("m_helpop: Helpop file is missing important entry 'nohelp'. Please check the example conf.");
164 void OnRehash(User* user)
169 void OnWhois(User* src, User* dst)
171 if (dst->IsModeSet('h'))
173 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
179 return Version("/help command, works like Unreal helpop", VF_VENDOR);
183 MODULE_INIT(ModuleHelpop)