summaryrefslogtreecommitdiff
path: root/modules/extra/m_alias.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-11-14 15:12:32 -0500
committerAdam <Adam@anope.org>2010-12-12 19:33:58 -0500
commit3c9d4e9dafdd0918a3539e545cc99646e604757d (patch)
tree5206bf59ad26698932ca0119b2c04a5f70c88946 /modules/extra/m_alias.cpp
parentc792c7f62df41c48d0d813a809e5415cbefa38b2 (diff)
Added command aliases
Diffstat (limited to 'modules/extra/m_alias.cpp')
-rw-r--r--modules/extra/m_alias.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/modules/extra/m_alias.cpp b/modules/extra/m_alias.cpp
new file mode 100644
index 000000000..4eac38179
--- /dev/null
+++ b/modules/extra/m_alias.cpp
@@ -0,0 +1,80 @@
+/*
+ * (C) 2003-2010 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "module.h"
+
+struct CommandAlias
+{
+ bool fantasy;
+ bool operonly;
+ Anope::string client;
+ Anope::string alias;
+ Anope::string command;
+};
+
+class ModuleAlias : public Module
+{
+ std::map<Anope::string, CommandAlias, std::less<ci::string> > aliases;
+ public:
+ ModuleAlias(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
+ {
+ Implementation i[] = { I_OnReload, I_OnPreCommandRun };
+ ModuleManager::Attach(i, this, 2);
+
+ OnReload(false);
+ }
+
+ void OnReload(bool)
+ {
+ ConfigReader config;
+
+ this->aliases.clear();
+
+ for (int i = 0; i < config.Enumerate("alias"); ++i)
+ {
+ bool fantasy = config.ReadFlag("alias", "fantasy", "no", i);
+ bool operonly = config.ReadFlag("alias", "operonly", "no", i);
+ Anope::string client = config.ReadValue("alias", "client", "", i);
+ Anope::string aliasname = config.ReadValue("alias", "alias", "", i);
+ Anope::string command = config.ReadValue("alias", "command", "", i);
+
+ if (aliasname.empty() || command.empty())
+ continue;
+
+ CommandAlias alias;
+ alias.fantasy = fantasy;
+ alias.operonly = operonly;
+ alias.client = client;
+ alias.alias = aliasname;
+ alias.command = command;
+
+ this->aliases.insert(std::make_pair(aliasname, alias));
+ }
+ }
+
+ EventReturn OnPreCommandRun(User *u, BotInfo *bi, Anope::string &command, Anope::string &message, bool fantasy)
+ {
+ std::map<Anope::string, CommandAlias, std::less<ci::string> >::const_iterator it = aliases.find(command);
+ if (it != aliases.end())
+ {
+ const CommandAlias &alias = it->second;
+
+ if (fantasy != alias.fantasy)
+ return EVENT_CONTINUE;
+ else if (!is_oper(u) && alias.operonly)
+ return EVENT_CONTINUE;
+ else if (!fantasy && !bi->nick.equals_ci(alias.client))
+ return EVENT_CONTINUE;
+
+ command = alias.command;
+ }
+
+ return EVENT_CONTINUE;
+ }
+};
+
+MODULE_INIT(ModuleAlias)