From bca6e2e39d4e3f59d5651bb5273c229eba5dff2b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 4 Nov 2014 00:01:31 +0100 Subject: [PATCH] stickychan: use CModCommand --- modules/stickychan.cpp | 62 ++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index 2783ed48..45071ec6 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -22,7 +22,12 @@ using std::vector; class CStickyChan : public CModule { public: - MODCONSTRUCTOR(CStickyChan) {} + MODCONSTRUCTOR(CStickyChan) { + AddHelpCommand(); + AddCommand("Stick", static_cast(&CStickyChan::OnStickCommand), "<#channel> [key]", "Sticks a channel"); + AddCommand("Unstick", static_cast(&CStickyChan::OnUnstickCommand), "<#channel>", "Unsticks a channel"); + AddCommand("List", static_cast(&CStickyChan::OnListCommand), "", "Lists sticky channels"); + } virtual ~CStickyChan() { } @@ -48,40 +53,39 @@ public: return CONTINUE; } - virtual void OnModCommand(const CString& sCommand) + void OnStickCommand(const CString& sCommand) { - CString sCmdName = sCommand.Token(0); - CString sChannel = sCommand.Token(1); - sChannel.MakeLower(); - if ((sCmdName == "stick") && (!sChannel.empty())) - { - SetNV(sChannel, sCommand.Token(2)); - PutModule("Stuck " + sChannel); + CString sChannel = sCommand.Token(1).AsLower(); + if (sChannel.empty()) { + PutModule("Usage: Stick <#channel> [key]"); + return; } - else if ((sCmdName == "unstick") && (!sChannel.empty())) - { - MCString::iterator it = FindNV(sChannel); - if (it != EndNV()) - DelNV(it); + SetNV(sChannel, sCommand.Token(2)); + PutModule("Stuck " + sChannel); + } - PutModule("UnStuck " + sChannel); + void OnUnstickCommand(const CString& sCommand) { + CString sChannel = sCommand.Token(1); + if (sChannel.empty()) { + PutModule("Usage: Unstick <#channel>"); + return; } - else if ((sCmdName == "list") && (sChannel.empty())) + MCString::iterator it = FindNV(sChannel); + if (it != EndNV()) + DelNV(it); + PutModule("Unstuck " + sChannel); + } + + void OnListCommand(const CString& sCommand) { + int i = 1; + for (MCString::iterator it = BeginNV(); it != EndNV(); ++it, i++) { - int i = 1; - for (MCString::iterator it = BeginNV(); it != EndNV(); ++it, i++) - { - if (it->second.empty()) - PutModule(CString(i) + ": " + it->first); - else - PutModule(CString(i) + ": " + it->first + " (" + it->second + ")"); - } - PutModule(" -- End of List"); - } - else - { - PutModule("USAGE: [un]stick #channel [key], list"); + if (it->second.empty()) + PutModule(CString(i) + ": " + it->first); + else + PutModule(CString(i) + ": " + it->first + " (" + it->second + ")"); } + PutModule(" -- End of List"); } virtual void RunJob()