diff options
author | Adam <Adam@anope.org> | 2011-12-19 15:37:15 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-12-19 15:37:15 -0500 |
commit | 45fc3ce1c41b06af6e03712988870ead95b72435 (patch) | |
tree | 7b574d077f77707edb3916fb43dfa30dec8b0f54 /modules/commands/cs_akick.cpp | |
parent | d320c73f23ff7a9b848b86b59c6bf91c1254e410 (diff) |
Fixed formatting of many lists and INFO outputs
Diffstat (limited to 'modules/commands/cs_akick.cpp')
-rw-r--r-- | modules/commands/cs_akick.cpp | 295 |
1 files changed, 121 insertions, 174 deletions
diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index f4325ea3a..b87e97354 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -46,115 +46,6 @@ static void split_usermask(const Anope::string &mask, Anope::string &nick, Anope } } -class AkickListCallback : public NumberList -{ - protected: - CommandSource &source; - ChannelInfo *ci; - bool SentHeader; - public: - AkickListCallback(CommandSource &_source, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), ci(_ci), SentHeader(false) - { - } - - ~AkickListCallback() - { - if (!SentHeader) - source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); - } - - virtual void HandleNumber(unsigned Number) - { - if (!Number || Number > ci->GetAkickCount()) - return; - - if (!SentHeader) - { - SentHeader = true; - source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - } - - DoList(source, ci, Number - 1, ci->GetAkick(Number - 1)); - } - - static void DoList(CommandSource &source, ChannelInfo *ci, unsigned index, AutoKick *akick) - { - source.Reply(_(" %3d %s (%s)"), index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->reason.empty() ? akick->reason.c_str() : NO_REASON); - } -}; - -class AkickViewCallback : public AkickListCallback -{ - public: - AkickViewCallback(CommandSource &_source, ChannelInfo *_ci, const Anope::string &numlist) : AkickListCallback(_source, _ci, numlist) - { - } - - void HandleNumber(unsigned Number) - { - if (!Number || Number > ci->GetAkickCount()) - return; - - if (!SentHeader) - { - SentHeader = true; - source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - } - - DoList(source, ci, Number - 1, ci->GetAkick(Number - 1)); - } - - static void DoList(CommandSource &source, ChannelInfo *ci, unsigned index, AutoKick *akick) - { - Anope::string timebuf; - - if (akick->addtime) - timebuf = do_strftime(akick->addtime); - else - timebuf = UNKNOWN; - - source.Reply(CHAN_AKICK_VIEW_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->creator.empty() ? akick->creator.c_str() : UNKNOWN, timebuf.c_str(), !akick->reason.empty() ? akick->reason.c_str() : _(NO_REASON)); - - if (akick->last_used) - source.Reply(_(" Last used %s"), do_strftime(akick->last_used).c_str()); - } -}; - -class AkickDelCallback : public NumberList -{ - CommandSource &source; - ChannelInfo *ci; - Command *c; - unsigned Deleted; - public: - AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), Deleted(0) - { - } - - ~AkickDelCallback() - { - User *u = source.u; - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, c, ci) << "DEL on " << Deleted << " users"; - - if (!Deleted) - source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); - else if (Deleted == 1) - source.Reply(_("Deleted 1 entry from %s autokick list."), ci->name.c_str()); - else - source.Reply(_("Deleted %d entries from %s autokick list."), Deleted, ci->name.c_str()); - } - - void HandleNumber(unsigned Number) - { - if (!Number || Number > ci->GetAkickCount()) - return; - - ++Deleted; - ci->EraseAkick(Number - 1); - } -}; - class CommandCSAKick : public Command { void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) @@ -287,8 +178,41 @@ class CommandCSAKick : public Command /* Special case: is it a number/list? Only do search if it isn't. */ if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickDelCallback list(source, ci, this, mask); - list.Process(); + class AkickDelCallback : public NumberList + { + CommandSource &source; + ChannelInfo *ci; + Command *c; + unsigned Deleted; + public: + AkickDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), Deleted(0) + { + } + + ~AkickDelCallback() + { + bool override = !ci->AccessFor(source.u).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "DEL on " << Deleted << " users"; + + if (!Deleted) + source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); + else if (Deleted == 1) + source.Reply(_("Deleted 1 entry from %s autokick list."), ci->name.c_str()); + else + source.Reply(_("Deleted %d entries from %s autokick list."), Deleted, ci->name.c_str()); + } + + void HandleNumber(unsigned Number) + { + if (!Number || Number > ci->GetAkickCount()) + return; + + ++Deleted; + ci->EraseAkick(Number - 1); + } + } + delcallback(source, ci, this, mask); + delcallback.Process(); } else { @@ -318,30 +242,54 @@ class CommandCSAKick : public Command } } - void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void ProcessList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms, ListFormatter &list) { - User *u = source.u; - const Anope::string &mask = params.size() > 2 ? params[2] : ""; - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "LIST"; - - if (!ci->GetAkickCount()) - { - source.Reply(_("%s autokick list is empty."), ci->name.c_str()); - return; - } - if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickListCallback list(source, ci, mask); - list.Process(); + class AkickListCallback : public NumberList + { + ListFormatter &list; + ChannelInfo *ci; + + public: + AkickListCallback(ListFormatter &_list, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), list(_list), ci(_ci) + { + } + + void HandleNumber(unsigned number) + { + if (!number || number > ci->GetAkickCount()) + return; + + AutoKick *akick = ci->GetAkick(number - 1); + + Anope::string timebuf, lastused; + if (akick->addtime) + timebuf = do_strftime(akick->addtime, NULL, false); + else + timebuf = UNKNOWN; + if (akick->last_used) + lastused = do_strftime(akick->last_used, NULL, false); + else + lastused = UNKNOWN; + + ListFormatter::ListEntry entry; + entry["Number"] = stringify(number); + entry["Mask"] = akick->mask; + entry["Creator"] = akick->creator; + entry["Created"] = timebuf; + entry["Last used"] = lastused; + entry["Reason"] = akick->reason; + this->list.addEntry(entry); + } + } + nl_list(list, ci, mask); + nl_list.Process(); } else { - bool SentHeader = false; - for (unsigned i = 0, end = ci->GetAkickCount(); i < end; ++i) { AutoKick *akick = ci->GetAkick(i); @@ -354,68 +302,67 @@ class CommandCSAKick : public Command continue; } - if (!SentHeader) - { - SentHeader = true; - source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - } - - AkickListCallback::DoList(source, ci, i, akick); + Anope::string timebuf, lastused; + if (akick->addtime) + timebuf = do_strftime(akick->addtime); + else + timebuf = UNKNOWN; + if (akick->last_used) + lastused = do_strftime(akick->last_used); + else + lastused = UNKNOWN; + + ListFormatter::ListEntry entry; + entry["Number"] = stringify(i + 1); + entry["Mask"] = akick->mask; + entry["Creator"] = akick->creator; + entry["Created"] = timebuf; + entry["Last used"] = lastused; + entry["Reason"] = akick->reason; + list.addEntry(entry); } - - if (!SentHeader) - source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); } - } - void DoView(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) - { - User *u = source.u; + if (list.isEmpty()) + source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); + else + { + std::vector<Anope::string> replies; + list.Process(replies); - const Anope::string &mask = params.size() > 2 ? params[2] : ""; + source.Reply(_("Autokick list for %s:"), ci->name.c_str()); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "VIEW"; + source.Reply(_("End of autokick list")); + } + } + void DoList(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { if (!ci->GetAkickCount()) { source.Reply(_("%s autokick list is empty."), ci->name.c_str()); return; } - if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) + ListFormatter list; + list.addColumn("Number").addColumn("Mask").addColumn("Reason"); + this->ProcessList(source, ci, params, list); + } + + void DoView(CommandSource &source, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + { + if (!ci->GetAkickCount()) { - AkickViewCallback list(source, ci, mask); - list.Process(); + source.Reply(_("%s autokick list is empty."), ci->name.c_str()); + return; } - else - { - bool SentHeader = false; - for (unsigned i = 0, end = ci->GetAkickCount(); i < end; ++i) - { - AutoKick *akick = ci->GetAkick(i); - - if (!mask.empty()) - { - if (!akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->mask, mask)) - continue; - if (akick->HasFlag(AK_ISNICK) && !Anope::Match(akick->nc->display, mask)) - continue; - } - - if (!SentHeader) - { - SentHeader = true; - source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - } - - AkickViewCallback::DoList(source, ci, i, akick); - } - - if (!SentHeader) - source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); - } + ListFormatter list; + list.addColumn("Number").addColumn("Mask").addColumn("Creator").addColumn("Created").addColumn("Last used").addColumn("Reason"); + this->ProcessList(source, ci, params, list); } void DoEnforce(CommandSource &source, ChannelInfo *ci) |