summaryrefslogtreecommitdiff
path: root/modules/commands
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands')
-rw-r--r--modules/commands/cs_fantasy_stats.cpp168
-rw-r--r--modules/commands/cs_fantasy_top.cpp213
-rw-r--r--modules/commands/cs_info.cpp1
-rw-r--r--modules/commands/cs_set_chanstats.cpp90
-rw-r--r--modules/commands/ns_info.cpp1
-rw-r--r--modules/commands/ns_set_chanstats.cpp115
-rw-r--r--modules/commands/os_defcon.cpp4
7 files changed, 590 insertions, 2 deletions
diff --git a/modules/commands/cs_fantasy_stats.cpp b/modules/commands/cs_fantasy_stats.cpp
new file mode 100644
index 000000000..7a4419e30
--- /dev/null
+++ b/modules/commands/cs_fantasy_stats.cpp
@@ -0,0 +1,168 @@
+/* Chanstats core functions
+ *
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+#include "../extra/sql.h"
+
+class MySQLInterface : public SQLInterface
+{
+ public:
+ MySQLInterface(Module *o) : SQLInterface(o) { }
+
+ void OnResult(const SQLResult &r) anope_override
+ {
+ }
+
+ void OnError(const SQLResult &r) anope_override
+ {
+ if (!r.GetQuery().query.empty())
+ Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
+ else
+ Log(LOG_DEBUG) << "Chanstats: Error executing query: " << r.GetError();
+ }
+};
+
+
+class CommandCSStats : public Command
+{
+ public:
+ CommandCSStats(Module *creator) : Command (creator, "chanserv/stats", 0, 2)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays your Channel Stats"));
+ this->SetSyntax(_("\037nick\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+class CommandCSGStats : public Command
+{
+ public:
+ CommandCSGStats(Module *creator) : Command (creator, "chanserv/gstats", 0, 2)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays your Global Stats"));
+ this->SetSyntax(_("\037nick\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+
+class CSStats;
+static CSStats *me;
+class CSStats : public Module
+{
+ CommandCSStats commandcsstats;
+ CommandCSGStats commandcsgstats;
+ service_reference<SQLProvider> sql;
+ MySQLInterface sqlinterface;
+ public:
+ CSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ commandcsstats(this), commandcsgstats(this), sql("", ""), sqlinterface(this)
+ {
+ me = this;
+ this->SetAuthor("Anope");
+
+ Implementation i[] = { I_OnReload };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+ this->OnReload();
+ }
+
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+ Anope::string engine = config.ReadValue("chanstats", "engine", "", 0);
+ this->sql = service_reference<SQLProvider>("SQLProvider", engine);
+ }
+
+ SQLResult RunQuery(const SQLQuery &query)
+ {
+ if (!this->sql)
+ throw SQLException("Unable to locate SQL reference, is m_mysql loaded and configured correctly?");
+
+ SQLResult res = this->sql->RunQuery(query);
+ if (!res.GetError().empty())
+ throw SQLException(res.GetError());
+ return res;
+ }
+
+ void DoStats(CommandSource &source, const bool is_global, const std::vector<Anope::string> &params)
+ {
+ if (!source.u || !source.c)
+ return;
+
+ Anope::string display;
+ if (params.empty())
+ display = source.u->Account()->display;
+ else if (NickAlias *na = findnick(params[0]))
+ display = na->nc->display;
+ else
+ {
+ source.Reply(_("%s not found."), params[0].c_str());
+ return;
+ }
+
+ try
+ {
+ SQLQuery query;
+ if (is_global)
+ query = "SELECT sum(letters) as letters, sum(words) as words, sum(line) as line,"
+ " sum(smileys) as smileys, sum(actions) as actions"
+ " FROM `anope_bs_chanstats_view_sum_all`"
+ " WHERE `nickserv_display` = @display@";
+ else
+ {
+ query = "SELECT letters, words, line, smileys, actions "
+ " FROM `anope_bs_chanstats_view_sum_all` "
+ " WHERE `nickserv_display` = @display@ AND `chanserv_name` = @channel@;";
+ query.setValue("channel", source.c->ci->name);
+ }
+ query.setValue("display", display);
+ SQLResult res = this->RunQuery(query);
+
+ if (res.Rows() > 0)
+ {
+ if (is_global)
+ source.Reply(_("Network stats for %s:"), display.c_str());
+ else
+ source.Reply(_("Channel stats for %s on %s:"), display.c_str(), source.c->name.c_str());
+
+ source.Reply(_("letters: %s, words: %s, lines: %s, smileys %s, actions: %s"),
+ res.Get(0, "letters").c_str(), res.Get(0, "words").c_str(),
+ res.Get(0, "line").c_str(), res.Get(0, "smileys").c_str(),
+ res.Get(0, "actions").c_str());
+ }
+ else
+ source.Reply(_("No stats for %s"), display.c_str());
+ }
+ catch (const SQLException &ex)
+ {
+ Log(LOG_DEBUG) << ex.GetReason();
+ }
+
+ }
+};
+
+void CommandCSStats::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoStats(source, false, params);
+}
+
+void CommandCSGStats::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoStats(source, true, params);
+}
+
+MODULE_INIT(CSStats) \ No newline at end of file
diff --git a/modules/commands/cs_fantasy_top.cpp b/modules/commands/cs_fantasy_top.cpp
new file mode 100644
index 000000000..7e4c0bb3b
--- /dev/null
+++ b/modules/commands/cs_fantasy_top.cpp
@@ -0,0 +1,213 @@
+/* Chanstats core functions
+ *
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+#include "../extra/sql.h"
+
+class MySQLInterface : public SQLInterface
+{
+ public:
+ MySQLInterface(Module *o) : SQLInterface(o) { }
+
+ void OnResult(const SQLResult &r) anope_override
+ {
+ }
+
+ void OnError(const SQLResult &r) anope_override
+ {
+ if (!r.GetQuery().query.empty())
+ Log(LOG_DEBUG) << "Chanstats: Error executing query " << r.finished_query << ": " << r.GetError();
+ else
+ Log(LOG_DEBUG) << "Chanstats: Error executing query: " << r.GetError();
+ }
+};
+
+class CommandCSTop : public Command
+{
+ public:
+ CommandCSTop(Module *creator) : Command (creator, "chanserv/top", 0, 2)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays the top 3 users of a channel"));
+ this->SetSyntax(_("\037channel\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+class CommandCSTop10 : public Command
+{
+ public:
+ CommandCSTop10(Module *creator) : Command (creator, "chanserv/top10", 0, 2)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays the top 10 users of a channel"));
+ this->SetSyntax(_("\037channel\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+class CommandCSGTop : public Command
+{
+ public:
+ CommandCSGTop(Module *creator) : Command (creator, "chanserv/gtop", 0, 1)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays the top 3 users of the network"));
+ this->SetSyntax("");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+class CommandCSGTop10 : public Command
+{
+ public:
+ CommandCSGTop10(Module *creator) : Command (creator, "chanserv/gtop10", 0, 1)
+ {
+ this->SetFlag(CFLAG_STRIP_CHANNEL);
+ this->SetDesc(_("Displays the top 10 users of the network"));
+ this->SetSyntax("");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params);
+};
+
+
+class CSTop;
+static CSTop *me;
+class CSTop : public Module
+{
+ CommandCSTop commandcstop;
+ CommandCSGTop commandcsgtop;
+ CommandCSTop10 commandcstop10;
+ CommandCSGTop10 commandcsgtop10;
+ service_reference<SQLProvider> sql;
+ MySQLInterface sqlinterface;
+
+ public:
+ CSTop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ commandcstop(this), commandcsgtop(this), commandcstop10(this), commandcsgtop10(this), sql("", ""),
+ sqlinterface(this)
+ {
+ me = this;
+ this->SetAuthor("Anope");
+
+ Implementation i[] = { I_OnReload };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+ this->OnReload();
+ }
+
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+ Anope::string engine = config.ReadValue("chanstats", "engine", "", 0);
+ this->sql = service_reference<SQLProvider>("SQLProvider", engine);
+ }
+
+ SQLResult RunQuery(const SQLQuery &query)
+ {
+ if (!this->sql)
+ throw SQLException("Unable to locate SQL reference, is m_mysql loaded and configured correctly?");
+
+ SQLResult res = sql->RunQuery(query);
+ if (!res.GetError().empty())
+ throw SQLException(res.GetError());
+ return res;
+ }
+
+ void DoTop(CommandSource &source, const std::vector<Anope::string> &params, bool is_global, int limit = 1)
+ {
+ if (!source.u || !source.c || !source.c->ci)
+ return;
+
+ Anope::string channel;
+ if (is_global || params.empty())
+ channel = source.c->ci->name;
+ else if (!params.empty())
+ channel = params[0];
+ else
+ {
+ source.Reply(_("%s not found."), params[0].c_str());
+ return;
+ }
+
+ try
+ {
+ SQLQuery query;
+
+
+ if (is_global)
+ {
+ query = Anope::printf("SELECT nickserv_display, sum(letters) as letters, sum(words) as words,"
+ " sum(line) as line, sum(smileys) as smileys, sum(actions) as actions"
+ " FROM `anope_bs_chanstats_view_sum_all`"
+ " WHERE nickserv_display IS NOT NULL"
+ " GROUP BY nickserv_display ORDER BY letters DESC LIMIT %i;", limit);
+ }
+ else
+ {
+ query = Anope::printf("SELECT nickserv_display, sum(letters) as letters, sum(words) as words,"
+ " sum(line) as line, sum(smileys) as smileys, sum(actions) as actions"
+ " FROM `anope_bs_chanstats_view_sum_all`"
+ " WHERE nickserv_display IS NOT NULL AND `chanserv_name` = @channel@"
+ " GROUP BY nickserv_display ORDER BY letters DESC LIMIT %i;", limit);
+ query.setValue("channel", channel.c_str());
+ }
+
+ SQLResult res = this->RunQuery(query);
+
+ if (res.Rows() > 0)
+ {
+ source.Reply(_("Top %i of %s"), limit, (is_global ? "Network" : channel.c_str()));
+ for (int i = 0; i < res.Rows(); ++i)
+ {
+ source.Reply(_("%2lu \002%-16s\002 letters: %s, words: %s, lines: %s, smileys %s, actions: %s"),
+ i+1, res.Get(i, "nickserv_display").c_str(), res.Get(i, "letters").c_str(),
+ res.Get(i, "words").c_str(), res.Get(i, "line").c_str(),
+ res.Get(0, "smileys").c_str(), res.Get(0, "actions").c_str());
+ }
+ }
+ else
+ source.Reply(_("No stats for %s"), is_global ? "Network" : channel.c_str());
+ }
+ catch (const SQLException &ex)
+ {
+ Log(LOG_DEBUG) << ex.GetReason();
+ }
+ }
+};
+
+void CommandCSTop::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoTop(source, params, false, 3);
+}
+
+void CommandCSTop10::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoTop(source, params, false, 10);
+}
+
+void CommandCSGTop::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoTop(source, params, true, 3);
+}
+
+void CommandCSGTop10::Execute(CommandSource &source, const std::vector<Anope::string> &params)
+{
+ me->DoTop(source, params, true, 10);
+}
+
+
+MODULE_INIT(CSTop) \ No newline at end of file
diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp
index 1554a0693..290ead3ba 100644
--- a/modules/commands/cs_info.cpp
+++ b/modules/commands/cs_info.cpp
@@ -94,6 +94,7 @@ class CommandCSInfo : public Command
CheckOptStr(optbuf, CI_TOPICLOCK, _("Topic Lock"), ci, u->Account());
CheckOptStr(optbuf, CI_PERSIST, _("Persistant"), ci, u->Account());
CheckOptStr(optbuf, CI_NO_EXPIRE, _("No expire"), ci, u->Account());
+ CheckOptStr(optbuf, CI_STATS, _("Chanstats"), ci, u->Account());
info["Options"] = optbuf.empty() ? _("None") : optbuf;
info["Mode lock"] = ci->GetMLockAsString(true);
diff --git a/modules/commands/cs_set_chanstats.cpp b/modules/commands/cs_set_chanstats.cpp
new file mode 100644
index 000000000..dd58c3ac4
--- /dev/null
+++ b/modules/commands/cs_set_chanstats.cpp
@@ -0,0 +1,90 @@
+/* NickServ core functions
+ *
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+
+class CommandCSSetChanstats : public Command
+{
+ public:
+ CommandCSSetChanstats(Module *creator) : Command(creator, "chanserv/set/chanstats", 2, 2)
+ {
+ this->SetDesc(_("Turn chanstat statistics on or off"));
+ this->SetSyntax(_("\037channel\037 {ON | OFF}"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ {
+ User *u = source.u;
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (!ci)
+ {
+ source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
+ return;
+ }
+
+ if (source.permission.empty() && !ci->AccessFor(u).HasPriv("SET"))
+ {
+ source.Reply(ACCESS_DENIED);
+ return;
+ }
+
+ if (params[1].equals_ci("ON"))
+ {
+ ci->SetFlag(CI_STATS);
+ source.Reply(_("Chanstats statistics are now enabled for this channel"));
+ }
+ else if (params[1].equals_ci("OFF"))
+ {
+ ci->UnsetFlag(CI_STATS);
+ source.Reply(_("Chanstats statistics are now disabled for this channel"));
+ }
+ else
+ this->OnSyntaxError(source, "");
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply("Turn Chanstats channel statistics ON or OFF");
+ return true;
+ }
+};
+
+class CSSetChanstats : public Module
+{
+ CommandCSSetChanstats commandcssetchanstats;
+ bool CSDefChanstats;
+ public:
+ CSSetChanstats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ commandcssetchanstats(this)
+ {
+ this->SetAuthor("Anope");
+ Implementation i[] = { I_OnReload, I_OnChanRegistered };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+ this->OnReload();
+ }
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+ CSDefChanstats = config.ReadFlag("chanstats", "CSDefChanstats", "0", 0);
+ }
+ void OnChanRegistered(ChannelInfo *ci) anope_override
+ {
+ if (CSDefChanstats)
+ ci->SetFlag(CI_STATS);
+ }
+};
+
+MODULE_INIT(CSSetChanstats)
diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp
index 2af036a96..a30b5452b 100644
--- a/modules/commands/ns_info.cpp
+++ b/modules/commands/ns_info.cpp
@@ -120,6 +120,7 @@ class CommandNSInfo : public Command
CheckOptStr<NickCoreFlag, NI_END>(u, optbuf, NI_MSG, _("Message mode"), na->nc);
CheckOptStr<NickCoreFlag, NI_END>(u, optbuf, NI_AUTOOP, _("Auto-op"), na->nc);
CheckOptStr<NickCoreFlag, NI_END>(u, optbuf, NI_SUSPENDED, _("Suspended"), na->nc);
+ CheckOptStr<NickCoreFlag, NI_END>(u, optbuf, NI_STATS, _("Chanstats"), na->nc);
CheckOptStr<NickNameFlag, NS_END>(u, optbuf, NS_NO_EXPIRE, _("No expire"), na);
info[_("Options")] = optbuf.empty() ? _("None") : optbuf;
diff --git a/modules/commands/ns_set_chanstats.cpp b/modules/commands/ns_set_chanstats.cpp
new file mode 100644
index 000000000..3d5064839
--- /dev/null
+++ b/modules/commands/ns_set_chanstats.cpp
@@ -0,0 +1,115 @@
+/* NickServ core functions
+ *
+ * (C) 2003-2012 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+/*************************************************************************/
+
+#include "module.h"
+
+class CommandNSSetChanstats : public Command
+{
+ public:
+ CommandNSSetChanstats(Module *creator, const Anope::string &sname = "nickserv/set/chanstats", size_t min = 1 ) : Command(creator, sname, min, min + 1)
+ {
+ this->SetDesc(_("Turn chanstat statistic on or off"));
+ this->SetSyntax(_("{ON | OFF}"));
+ }
+ void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
+ {
+ NickAlias *na = findnick(user);
+ if (!na)
+ {
+ source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
+ return;
+ }
+
+ if (param.equals_ci("ON"))
+ {
+ na->nc->SetFlag(NI_STATS);
+ source.Reply(_("Chanstat statistics are now enabled for your nick"));
+ }
+ else if (param.equals_ci("OFF"))
+ {
+ na->nc->UnsetFlag(NI_STATS);
+ source.Reply(_("Chanstat statistics are now disabled for your nick"));
+ }
+ else
+ this->OnSyntaxError(source, "CHANSTATS");
+
+ return;
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ {
+ this->Run(source, source.u->Account()->display, params[0]);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Turns Chanstats statistics ON or OFF"));
+ return true;
+ }
+};
+
+class CommandNSSASetChanstats : public CommandNSSetChanstats
+{
+ public:
+ CommandNSSASetChanstats(Module *creator) : CommandNSSetChanstats(creator, "nickserv/saset/chanstats", 2)
+ {
+ this->ClearSyntax();
+ this->SetSyntax(_("\037nickname\037 {ON | OFF}"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
+ {
+ this->Run(source, params[0], params[1]);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &) anope_override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Turns chanstats channel statistics ON or OFF for this user"));
+ return true;
+ }
+};
+
+class NSSetChanstats : public Module
+{
+ CommandNSSetChanstats commandnssetchanstats;
+ CommandNSSASetChanstats commandnssasetchanstats;
+ bool NSDefChanstats;
+
+ public:
+ NSSetChanstats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
+ commandnssetchanstats(this), commandnssasetchanstats(this)
+ {
+ this->SetAuthor("Anope");
+
+ Implementation i[] = { I_OnReload, I_OnNickRegister };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+
+ this->OnReload();
+ }
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+ NSDefChanstats = config.ReadFlag("chanstats", "NSDefChanstats", "0", 0);
+ }
+ void OnNickRegister(NickAlias *na) anope_override
+ {
+ if (NSDefChanstats)
+ na->nc->SetFlag(NI_STATS);
+ }
+};
+
+MODULE_INIT(NSSetChanstats)
diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp
index a8b9891a4..1cf09c259 100644
--- a/modules/commands/os_defcon.cpp
+++ b/modules/commands/os_defcon.cpp
@@ -438,7 +438,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
- EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const Anope::string &param) anope_override
+ EventReturn OnChannelModeSet(Channel *c, User *setter, ChannelModeName Name, const Anope::string &param) anope_override
{
ChannelMode *cm = ModeManager::FindChannelModeByName(Name);
@@ -452,7 +452,7 @@ class OSDefcon : public Module
return EVENT_CONTINUE;
}
- EventReturn OnChannelModeUnset(Channel *c, ChannelModeName Name, const Anope::string &) anope_override
+ EventReturn OnChannelModeUnset(Channel *c, User *setter, ChannelModeName Name, const Anope::string &) anope_override
{
ChannelMode *cm = ModeManager::FindChannelModeByName(Name);