diff --git a/modules/notes.cpp b/modules/notes.cpp index 38c1a245..f17626d1 100644 --- a/modules/notes.cpp +++ b/modules/notes.cpp @@ -18,13 +18,70 @@ using std::stringstream; class CNotesMod : public CModule { -public: - MODCONSTRUCTOR(CNotesMod) { + void ListCommand(const CString &sLine) { + ListNotes(); } - virtual ~CNotesMod() { + void AddNoteCommand(const CString &sLine) { + CString sKey(sLine.Token(1)); + CString sValue(sLine.Token(2, true)); + + if (!GetNV(sKey).empty()) { + PutModule("That note already exists. Use MOD to overwrite."); + } else if (AddNote(sKey, sValue)) { + PutModule("Added note [" + sKey + "]"); + } else { + PutModule("Unable to add note [" + sKey + "]"); + } } + void ModCommand(const CString &sLine) { + CString sKey(sLine.Token(1)); + CString sValue(sLine.Token(2, true)); + + if (AddNote(sKey, sValue)) { + PutModule("Set note for [" + sKey + "]"); + } else { + PutModule("Unable to add note [" + sKey + "]"); + } + } + + void GetCommand(const CString &sLine) { + CString sNote = GetNV(sLine.Token(1, true)); + + if (sNote.empty()) { + PutModule("This note doesn't exist."); + } else { + PutModule(sNote); + } + } + + void DelCommand(const CString &sLine) { + CString sKey(sLine.Token(1)); + + if (DelNote(sKey)) { + PutModule("Deleted note [" + sKey + "]"); + } else { + PutModule("Unable to delete note [" + sKey + "]"); + } + } + +public: + MODCONSTRUCTOR(CNotesMod) { + AddHelpCommand(); + AddCommand("List", static_cast(&CNotesMod::ListCommand)); + AddCommand("Add", static_cast(&CNotesMod::AddNoteCommand), + " "); + AddCommand("Del", static_cast(&CNotesMod::DelCommand), + "", "Delete a note"); + AddCommand("Mod", static_cast(&CNotesMod::ModCommand), + " ", "Modify a note"); + AddCommand("Get", static_cast(&CNotesMod::GetCommand), + ""); + } + + virtual ~CNotesMod() {} + virtual bool OnLoad(const CString& sArgStr, CString& sMessage) { return true; } @@ -126,52 +183,6 @@ public: } } - virtual void OnModCommand(const CString& sLine) { - CString sCmd(sLine.Token(0)); - - if (sLine.Equals("LIST")) { - ListNotes(); - } else if (sCmd.Equals("ADD")) { - CString sKey(sLine.Token(1)); - CString sValue(sLine.Token(2, true)); - - if (!GetNV(sKey).empty()) { - PutModule("That note already exists. Use MOD to overwrite."); - } else if (AddNote(sKey, sValue)) { - PutModule("Added note [" + sKey + "]"); - } else { - PutModule("Unable to add note [" + sKey + "]"); - } - } else if (sCmd.Equals("MOD")) { - CString sKey(sLine.Token(1)); - CString sValue(sLine.Token(2, true)); - - if (AddNote(sKey, sValue)) { - PutModule("Set note for [" + sKey + "]"); - } else { - PutModule("Unable to add note [" + sKey + "]"); - } - } else if (sCmd.Equals("DEL")) { - CString sKey(sLine.Token(1)); - - if (DelNote(sKey)) { - PutModule("Deleted note [" + sKey + "]"); - } else { - PutModule("Unable to delete note [" + sKey + "]"); - } - } else if (sCmd.Equals("GET")) { - CString sNote = GetNV(sLine.Token(1, true)); - - if (sNote.empty()) { - PutModule("This note doesn't exist."); - } else { - PutModule(sNote); - } - } else { - PutModule("Commands are: Help, List, Add , Del , Mod , Get "); - } - } - virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { if (sPageName == "index") { for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {