1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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
23 ModuleAbbreviation(InspIRCd* Me)
26 Me->Modules->Attach(I_OnPreCommand, this);
27 /* Must do this first */
28 Me->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_FIRST);
31 virtual Version GetVersion()
33 return Version("$Id$",VF_VENDOR,API_VERSION);
36 virtual int OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User *user, bool validated, const std::string &original_line)
38 /* Command is already validated, has a length of 0, or last character is not a . */
39 if (validated || command.empty() || *command.rbegin() != '.')
42 /* Whack the . off the end */
43 command.erase(command.end() - 1);
45 /* Look for any command that starts with the same characters, if it does, replace the command string with it */
46 size_t clen = command.length();
47 std::string foundcommand, matchlist;
48 bool foundmatch = false;
49 for (Commandtable::iterator n = ServerInstance->Parser->cmdlist.begin(); n != ServerInstance->Parser->cmdlist.end(); ++n)
51 if (n->first.length() < clen)
54 if (command == n->first.substr(0, clen))
56 if (matchlist.length() > 450)
58 user->WriteNumeric(420, "%s :Ambiguous abbreviation and too many possible matches.", user->nick.c_str());
64 /* Found the command */
65 foundcommand = n->first;
69 matchlist.append(" ").append(n->first);
73 /* Ambiguous command, list the matches */
74 if (!matchlist.empty())
76 user->WriteNumeric(420, "%s :Ambiguous abbreviation, posssible matches: %s%s", user->nick.c_str(), foundcommand.c_str(), matchlist.c_str());
80 if (foundcommand.empty())
82 /* No match, we have to put the . back again so that the invalid command numeric looks correct. */
87 command = foundcommand;
94 MODULE_INIT(ModuleAbbreviation)