From 211bab0f0078bdfbb4b5a36b4cc84f520c55aa77 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Tue, 1 Mar 2011 23:22:52 +0000 Subject: [PATCH] Update the perform command to use CModCommand --- modules/perform.cpp | 122 ++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/modules/perform.cpp b/modules/perform.cpp index 44fe857a..a877717d 100644 --- a/modules/perform.cpp +++ b/modules/perform.cpp @@ -10,8 +10,75 @@ #include class CPerform : public CModule { + void Add(const CString& sCommand) { + CString sPerf = sCommand.Token(1, true); + + if (sPerf.empty()) { + PutModule("Usage: add "); + return; + } + + m_vPerform.push_back(ParsePerform(sPerf)); + PutModule("Added!"); + Save(); + } + + void Del(const CString& sCommand) { + u_int iNum = sCommand.Token(1, true).ToUInt(); + + if (iNum > m_vPerform.size() || iNum <= 0) { + PutModule("Illegal # Requested"); + return; + } else { + m_vPerform.erase(m_vPerform.begin() + iNum - 1); + PutModule("Command Erased."); + } + Save(); + } + + void List(const CString& sCommand) { + int i = 1; + CString sExpanded; + for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++, i++) { + sExpanded = GetUser()->ExpandString(*it); + if (sExpanded != *it) + PutModule(CString(i) + ": " + *it + " (" + sExpanded + ")"); + else + PutModule(CString(i) + ": " + *it); + } + PutModule(" -- End of List"); + } + + void Execute(const CString& sCommand) { + OnIRCConnected(); + PutModule("perform commands sent"); + } + + void Swap(const CString& sCommand) { + u_int iNumA = sCommand.Token(1).ToUInt(); + u_int iNumB = sCommand.Token(2).ToUInt(); + + if (iNumA > m_vPerform.size() || iNumA <= 0 || iNumB > m_vPerform.size() || iNumB <= 0) { + PutModule("Illegal # Requested"); + } else { + std::iter_swap(m_vPerform.begin() + (iNumA - 1), m_vPerform.begin() + (iNumB - 1)); + PutModule("Commands Swapped."); + Save(); + } + } + public: - MODCONSTRUCTOR(CPerform) {} + MODCONSTRUCTOR(CPerform) { + AddHelpCommand(); + AddCommand("Add", static_cast(&CPerform::Add), + ""); + AddCommand("Del", static_cast(&CPerform::Del), + ""); + AddCommand("List", static_cast(&CPerform::List)); + AddCommand("Execute", static_cast(&CPerform::Execute)); + AddCommand("Swap", static_cast(&CPerform::Swap), + " "); + } virtual ~CPerform() {} @@ -41,59 +108,6 @@ public: return true; } - virtual void OnModCommand(const CString& sCommand) { - CString sCmdName = sCommand.Token(0).AsLower(); - if (sCmdName == "add") { - CString sPerf = sCommand.Token(1, true); - - if (sPerf.empty()) { - PutModule("Usage: add "); - return; - } - - m_vPerform.push_back(ParsePerform(sPerf)); - PutModule("Added!"); - Save(); - } else if (sCmdName == "del") { - u_int iNum = sCommand.Token(1, true).ToUInt(); - if (iNum > m_vPerform.size() || iNum <= 0) { - PutModule("Illegal # Requested"); - return; - } else { - m_vPerform.erase(m_vPerform.begin() + iNum - 1); - PutModule("Command Erased."); - } - Save(); - } else if (sCmdName == "list") { - int i = 1; - CString sExpanded; - for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++, i++) { - sExpanded = GetUser()->ExpandString(*it); - if (sExpanded != *it) - PutModule(CString(i) + ": " + *it + " (" + sExpanded + ")"); - else - PutModule(CString(i) + ": " + *it); - } - PutModule(" -- End of List"); - } else if (sCmdName == "execute") { - OnIRCConnected(); - PutModule("perform commands sent"); - } else if (sCmdName == "swap") { - u_int iNumA = sCommand.Token(1).ToUInt(); - u_int iNumB = sCommand.Token(2).ToUInt(); - - if (iNumA > m_vPerform.size() || iNumA <= 0 || iNumB > m_vPerform.size() || iNumB <= 0) { - PutModule("Illegal # Requested"); - } else { - std::iter_swap(m_vPerform.begin() + (iNumA - 1), m_vPerform.begin() + (iNumB - 1)); - PutModule("Commands Swapped."); - Save(); - } - } else { - PutModule("Commands: add , del , list, execute, swap "); - } - } - virtual void OnIRCConnected() { for (VCString::const_iterator it = m_vPerform.begin(); it != m_vPerform.end(); ++it) { PutIRC(GetUser()->ExpandString(*it));