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 /* $ModDesc: Provides the ability to abbreviate commands a-la BBC BASIC keywords. */
18 class ModuleAbbreviation : public Module
25 ServerInstance->Modules->Attach(I_OnPreCommand, this);
26 /* Must do this first */
27 ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_FIRST);
30 virtual Version GetVersion()
32 return Version("Provides the ability to abbreviate commands a-la BBC BASIC keywords.",VF_VENDOR);
35 virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser *user, bool validated, const std::string &original_line)
37 /* Command is already validated, has a length of 0, or last character is not a . */
38 if (validated || command.empty() || *command.rbegin() != '.')
39 return MOD_RES_PASSTHRU;
41 /* Whack the . off the end */
42 command.erase(command.end() - 1);
44 /* Look for any command that starts with the same characters, if it does, replace the command string with it */
45 size_t clen = command.length();
46 std::string foundcommand, matchlist;
47 bool foundmatch = false;
48 for (Commandtable::iterator n = ServerInstance->Parser->cmdlist.begin(); n != ServerInstance->Parser->cmdlist.end(); ++n)
50 if (n->first.length() < clen)
53 if (command == n->first.substr(0, clen))
55 if (matchlist.length() > 450)
57 user->WriteNumeric(420, "%s :Ambiguous abbreviation and too many possible matches.", user->nick.c_str());
63 /* Found the command */
64 foundcommand = n->first;
68 matchlist.append(" ").append(n->first);
72 /* Ambiguous command, list the matches */
73 if (!matchlist.empty())
75 user->WriteNumeric(420, "%s :Ambiguous abbreviation, posssible matches: %s%s", user->nick.c_str(), foundcommand.c_str(), matchlist.c_str());
79 if (foundcommand.empty())
81 /* No match, we have to put the . back again so that the invalid command numeric looks correct. */
86 command = foundcommand;
89 return MOD_RES_PASSTHRU;
93 MODULE_INIT(ModuleAbbreviation)