diff options
| author | Adam <Adam@anope.org> | 2013-07-29 12:02:40 +0000 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2013-07-29 12:02:40 +0000 |
| commit | 402c624e455d13cc811bef2e8d1639846e892a34 (patch) | |
| tree | b6fd03ba6620167cb1365cd6739c651cfaf03b36 /modules/commands | |
| parent | fde83f6564c38635c7bfebd7edb60f30b012189c (diff) | |
Move chanstats stuff to stats/
Diffstat (limited to 'modules/commands')
| -rw-r--r-- | modules/commands/cs_fantasy_stats.cpp | 158 | ||||
| -rw-r--r-- | modules/commands/cs_fantasy_top.cpp | 195 | ||||
| -rw-r--r-- | modules/commands/cs_set.cpp | 63 | ||||
| -rw-r--r-- | modules/commands/ns_set.cpp | 85 |
4 files changed, 5 insertions, 496 deletions
diff --git a/modules/commands/cs_fantasy_stats.cpp b/modules/commands/cs_fantasy_stats.cpp deleted file mode 100644 index d54ed4a92..000000000 --- a/modules/commands/cs_fantasy_stats.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* Chanstats core functions - * - * (C) 2003-2013 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 "modules/sql.h" - -class MySQLInterface : public SQL::Interface -{ - public: - MySQLInterface(Module *o) : SQL::Interface(o) { } - - void OnResult(const SQL::Result &r) anope_override - { - } - - void OnError(const SQL::Result &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->SetDesc(_("Displays your Channel Stats")); - this->SetSyntax(_("\037nick\037")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - -class CommandCSGStats : public Command -{ - public: - CommandCSGStats(Module *creator) : Command (creator, "chanserv/gstats", 0, 2) - { - this->SetDesc(_("Displays your Global Stats")); - this->SetSyntax(_("\037nick\037")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - - -class CSStats; -static CSStats *me; -class CSStats : public Module -{ - CommandCSStats commandcsstats; - CommandCSGStats commandcsgstats; - ServiceReference<SQL::Provider> sql; - MySQLInterface sqlinterface; - Anope::string prefix; - public: - CSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcsstats(this), commandcsgstats(this), sql("", ""), sqlinterface(this) - { - me = this; - - } - - void OnReload(Configuration::Conf *conf) anope_override - { - prefix = conf->GetModule(this)->Get<const Anope::string>("prefix"); - if (prefix.empty()) - prefix = "anope_"; - this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule(this)->Get<const Anope::string>("engine")); - } - - SQL::Result RunQuery(const SQL::Query &query) - { - if (!this->sql) - throw SQL::Exception("Unable to locate SQL reference, is m_mysql loaded and configured correctly?"); - - SQL::Result res = this->sql->RunQuery(query); - if (!res.GetError().empty()) - throw SQL::Exception(res.GetError()); - return res; - } - - void DoStats(CommandSource &source, const bool is_global, const std::vector<Anope::string> ¶ms) - { - if (!source.c) - return; - - Anope::string display; - if (params.empty()) - display = source.nc->display; - else if (const NickAlias *na = NickAlias::Find(params[0])) - display = na->nc->display; - else - { - source.Reply(_("%s not found."), params[0].c_str()); - return; - } - - try - { - SQL::Query query; - query = "SELECT letters, words, line, smileys_happy+smileys_sad+smileys_other as smileys," - "actions FROM `" + prefix + "chanstats` " - "WHERE `nick` = @nick@ AND `chan` = @channel@ AND `type` = 'total';"; - if (is_global) - query.SetValue("channel", ""); - else - query.SetValue("channel", source.c->ci->name); - query.SetValue("nick", display); - SQL::Result 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 SQL::Exception &ex) - { - Log(LOG_DEBUG) << ex.GetReason(); - } - - } -}; - -void CommandCSStats::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoStats(source, false, params); -} - -void CommandCSGStats::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoStats(source, true, params); -} - -MODULE_INIT(CSStats) - diff --git a/modules/commands/cs_fantasy_top.cpp b/modules/commands/cs_fantasy_top.cpp deleted file mode 100644 index bc08c4c9d..000000000 --- a/modules/commands/cs_fantasy_top.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* Chanstats core functions - * - * (C) 2003-2013 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 "modules/sql.h" - -class MySQLInterface : public SQL::Interface -{ - public: - MySQLInterface(Module *o) : SQL::Interface(o) { } - - void OnResult(const SQL::Result &r) anope_override - { - } - - void OnError(const SQL::Result &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->SetDesc(_("Displays the top 3 users of a channel")); - this->SetSyntax(_("\037channel\037")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - -class CommandCSTop10 : public Command -{ - public: - CommandCSTop10(Module *creator) : Command (creator, "chanserv/top10", 0, 2) - { - this->SetDesc(_("Displays the top 10 users of a channel")); - this->SetSyntax(_("\037channel\037")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - -class CommandCSGTop : public Command -{ - public: - CommandCSGTop(Module *creator) : Command (creator, "chanserv/gtop", 0, 1) - { - this->SetDesc(_("Displays the top 3 users of the network")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - -class CommandCSGTop10 : public Command -{ - public: - CommandCSGTop10(Module *creator) : Command (creator, "chanserv/gtop10", 0, 1) - { - this->SetDesc(_("Displays the top 10 users of the network")); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); -}; - - -class CSTop; -static CSTop *me; -class CSTop : public Module -{ - CommandCSTop commandcstop; - CommandCSGTop commandcsgtop; - CommandCSTop10 commandcstop10; - CommandCSGTop10 commandcsgtop10; - ServiceReference<SQL::Provider> sql; - MySQLInterface sqlinterface; - Anope::string prefix; - - public: - CSTop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandcstop(this), commandcsgtop(this), commandcstop10(this), commandcsgtop10(this), sql("", ""), - sqlinterface(this) - { - me = this; - - } - - void OnReload(Configuration::Conf *conf) anope_override - { - prefix = conf->GetModule(this)->Get<const Anope::string>("prefix"); - if (prefix.empty()) - prefix = "anope_"; - this->sql = ServiceReference<SQL::Provider>("SQL::Provider", conf->GetModule(this)->Get<const Anope::string>("engine")); - } - - SQL::Result RunQuery(const SQL::Query &query) - { - if (!this->sql) - throw SQL::Exception("Unable to locate SQL reference, is m_mysql loaded and configured correctly?"); - - SQL::Result res = sql->RunQuery(query); - if (!res.GetError().empty()) - throw SQL::Exception(res.GetError()); - return res; - } - - void DoTop(CommandSource &source, const std::vector<Anope::string> ¶ms, bool is_global, int limit = 1) - { - if (!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 - { - SQL::Query query; - query = "SELECT nick, letters, words, line, actions," - "smileys_happy+smileys_sad+smileys_other as smileys " - "FROM `" + prefix + "chanstats` " - "WHERE `nick` != '' AND `chan` = @channel@ AND `type` = 'total' " - "ORDER BY `letters` DESC LIMIT @limit@;"; - query.SetValue("limit", limit, false); - - if (is_global) - query.SetValue("channel", ""); - else - query.SetValue("channel", channel.c_str()); - - SQL::Result 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, "nick").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 SQL::Exception &ex) - { - Log(LOG_DEBUG) << ex.GetReason(); - } - } -}; - -void CommandCSTop::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoTop(source, params, false, 3); -} - -void CommandCSTop10::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoTop(source, params, false, 10); -} - -void CommandCSGTop::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoTop(source, params, true, 3); -} - -void CommandCSGTop10::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) -{ - me->DoTop(source, params, true, 10); -} - - -MODULE_INIT(CSTop) diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 161b0b725..129e5be06 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -173,60 +173,6 @@ class CommandCSSetBanType : public Command } }; -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> ¶ms) anope_override - { - ChannelInfo *ci = ChannelInfo::Find(params[0]); - if (!ci) - { - source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); - return; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetChannelOption, MOD_RESULT, (source, this, ci, params[1])); - if (MOD_RESULT == EVENT_STOP) - return; - - if (MOD_RESULT != EVENT_ALLOW && !source.AccessFor(ci).HasPriv("SET") && source.permission.empty() && !source.HasPriv("chanserv/administration")) - { - source.Reply(ACCESS_DENIED); - return; - } - - if (params[1].equals_ci("ON")) - { - ci->Extend<bool>("CS_STATS"); - source.Reply(_("Chanstats statistics are now enabled for this channel.")); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable chanstats"; - } - else if (params[1].equals_ci("OFF")) - { - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable chanstats"; - ci->Shrink<bool>("CS_STATS"); - source.Reply(_("Chanstats statistics are now disabled for this channel.")); - } - else - this->OnSyntaxError(source, ""); - } - - 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 CommandCSSetDescription : public Command { public: @@ -989,13 +935,12 @@ class CommandCSSetNoexpire : public Command class CSSet : public Module { - SerializableExtensibleItem<bool> persist, noautoop, stats, peace, securefounder, + SerializableExtensibleItem<bool> persist, noautoop, peace, securefounder, restricted, secure, secureops, signkick, signkick_level, noexpire; CommandCSSet commandcsset; CommandCSSetAutoOp commandcssetautoop; CommandCSSetBanType commandcssetbantype; - CommandCSSetChanstats commandcssetchanstats; CommandCSSetDescription commandcssetdescription; CommandCSSetFounder commandcssetfounder; CommandCSSetPeace commandcssetpeace; @@ -1010,12 +955,12 @@ class CSSet : public Module public: CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - persist(this, "PERSIST"), noautoop(this, "NOAUTOOP"), stats(this, "CS_STATS"), peace(this, "PEACE"), + persist(this, "PERSIST"), noautoop(this, "NOAUTOOP"), peace(this, "PEACE"), securefounder(this, "SECUREFOUNDER"), restricted(this, "RESTRICTED"), secure(this, "CS_SECURE"), secureops(this, "SECUREOPS"), signkick(this, "SIGNKICK"), signkick_level(this, "SIGNKICK_LEVEL"), noexpire(this, "CS_NO_EXPIRE"), - commandcsset(this), commandcssetautoop(this), commandcssetbantype(this), commandcssetchanstats(this), + commandcsset(this), commandcssetautoop(this), commandcssetbantype(this), commandcssetdescription(this), commandcssetfounder(this), commandcssetpeace(this), commandcssetpersist(this), commandcssetrestricted(this), commandcssetsecure(this), commandcssetsecurefounder(this), commandcssetsecureops(this), commandcssetsignkick(this), @@ -1130,8 +1075,6 @@ class CSSet : public Module info.AddOption(_("Persistent")); if (noexpire.HasExt(ci)) info.AddOption(_("No expire")); - if (stats.HasExt(ci)) - info.AddOption(_("Chanstats")); time_t chanserv_expire = Config->GetModule(this)->Get<time_t>("expire", "14d"); if (!noexpire.HasExt(ci) && chanserv_expire && !Anope::NoExpire) diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 6f47750cb..df35f0582 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -286,81 +286,6 @@ class CommandNSSASetAutoOp : public CommandNSSetAutoOp } }; -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 ¶m) - { - NickAlias *na = NickAlias::Find(user); - if (!na) - { - source.Reply(NICK_X_NOT_REGISTERED, user.c_str()); - return; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, na->nc, param)); - if (MOD_RESULT == EVENT_STOP) - return; - - if (param.equals_ci("ON")) - { - Log(na->nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to enable chanstats for " << na->nc->display; - na->nc->Extend<bool>("NS_STATS"); - source.Reply(_("Chanstat statistics are now enabled for your nick.")); - } - else if (param.equals_ci("OFF")) - { - Log(na->nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to disable chanstats for " << na->nc->display; - na->nc->Shrink<bool>("NS_STATS"); - source.Reply(_("Chanstat statistics are now disabled for your nick.")); - } - else - this->OnSyntaxError(source, "CHANSTATS"); - } - - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - this->Run(source, source.nc->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> ¶ms) 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 CommandNSSetDisplay : public Command { public: @@ -1048,9 +973,6 @@ class NSSet : public Module CommandNSSetAutoOp commandnssetautoop; CommandNSSASetAutoOp commandnssasetautoop; - CommandNSSetChanstats commandnssetchanstats; - CommandNSSASetChanstats commandnssasetchanstats; - CommandNSSetDisplay commandnssetdisplay; CommandNSSASetDisplay commandnssasetdisplay; @@ -1074,7 +996,7 @@ class NSSet : public Module CommandNSSASetNoexpire commandnssasetnoexpire; - SerializableExtensibleItem<bool> autoop, chanstats, killprotect, kill_quick, kill_immed, + SerializableExtensibleItem<bool> autoop, killprotect, kill_quick, kill_immed, message, secure, noexpire; /* email, passcode */ @@ -1084,7 +1006,6 @@ class NSSet : public Module NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandnsset(this), commandnssaset(this), commandnssetautoop(this), commandnssasetautoop(this), - commandnssetchanstats(this), commandnssasetchanstats(this), commandnssetdisplay(this), commandnssasetdisplay(this), commandnssetemail(this), commandnssasetemail(this), commandnssetkill(this), commandnssasetkill(this), @@ -1094,7 +1015,7 @@ class NSSet : public Module commandnssetsecure(this), commandnssasetsecure(this), commandnssasetnoexpire(this), - autoop(this, "AUTOOP"), chanstats(this, "NS_STATS"), killprotect(this, "KILLPROTECT"), + autoop(this, "AUTOOP"), killprotect(this, "KILLPROTECT"), kill_quick(this, "KILL_QUICK"), kill_immed(this, "KILL_IMMED"), message(this, "MSG"), secure(this, "NS_SECURE"), noexpire(this, "NS_NO_EXPIRE"), @@ -1154,8 +1075,6 @@ class NSSet : public Module info.AddOption(_("Message mode")); if (autoop.HasExt(na->nc)) info.AddOption(_("Auto-op")); - if (chanstats.HasExt(na->nc)) - info.AddOption(_("Chanstats")); if (noexpire.HasExt(na)) info.AddOption(_("No expire")); } |
