From 2cbf26f5ff7615062862b5866732baba058a489b Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 1 Jan 2012 16:57:02 +0700 Subject: [PATCH] Support RusNet's NickServ. It requires to use /nickserv instead of /msg nickserv, so now all commands used by nickserv module are customizable. --- modules/nickserv.cpp | 70 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index 2bfa6295..a9a04d4a 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -10,6 +10,12 @@ #include class CNickServ : public CModule { + void DoNickCommand(const CString& sCmd, const CString& sNick) { + MCString msValues; + msValues["nickname"] = sNick; + msValues["password"] = GetNV("Password"); + PutIRC(CString::NamedFormat(GetNV(sCmd), msValues)); + } public: void SetCommand(const CString& sLine) { SetNV("Password", sLine.Token(1, true)); @@ -24,7 +30,7 @@ public: if (sLine.Token(1).empty()) { PutModule("Syntax: ghost "); } else { - PutIRC("PRIVMSG NickServ :GHOST " + sLine.Token(1) + " " + GetNV("Password")); + DoNickCommand("GhostCmd", sLine.Token(1)); } } @@ -32,7 +38,7 @@ public: if (sLine.Token(1).empty()) { PutModule("Syntax: recover "); } else { - PutIRC("PRIVMSG NickServ :RECOVER " + sLine.Token(1) + " " + GetNV("Password")); + DoNickCommand("RecoverCmd", sLine.Token(1)); } } @@ -40,7 +46,7 @@ public: if (sLine.Token(1).empty()) { PutModule("Syntax: release "); } else { - PutIRC("PRIVMSG NickServ :RELEASE " + sLine.Token(1) + " " + GetNV("Password")); + DoNickCommand("ReleaseCmd", sLine.Token(1)); } } @@ -48,10 +54,38 @@ public: if (sLine.Token(1).empty()) { PutModule("Syntax: group "); } else { - PutIRC("PRIVMSG NickServ :GROUP " + sLine.Token(1) + " " + GetNV("Password")); + DoNickCommand("GroupCmd", sLine.Token(1)); } } + void ViewCommandsCommand(const CString& sLine) { + PutModule("IDENTIFY=" + GetNV("IdentifyCmd")); + PutModule("GHOST=" + GetNV("GhostCmd")); + PutModule("RECOVER=" + GetNV("RecoverCmd")); + PutModule("RELEASE=" + GetNV("ReleaseCmd")); + PutModule("GROUP=" + GetNV("GroupCmd")); + } + + void SetCommandCommand(const CString& sLine) { + CString sCmd = sLine.Token(1); + CString sNewCmd = sLine.Token(2, true); + if (sCmd.Equals("IDENTIFY")) { + SetNV("IdentifyCmd", sNewCmd); + } else if (sCmd.Equals("GHOST")) { + SetNV("GhostCmd", sNewCmd); + } else if (sCmd.Equals("RECOVER")) { + SetNV("RecoverCmd", sNewCmd); + } else if (sCmd.Equals("RELEASE")) { + SetNV("ReleaseCmd", sNewCmd); + } else if (sCmd.Equals("GROUP")) { + SetNV("GroupCmd", sNewCmd); + } else { + PutModule("No such editable command. See ViewCommands for list."); + return; + } + PutModule("Ok"); + } + MODCONSTRUCTOR(CNickServ) { AddHelpCommand(); AddCommand("Set", static_cast(&CNickServ::SetCommand), @@ -66,7 +100,10 @@ public: "nickname"); AddCommand("Group", static_cast(&CNickServ::GroupCommand), "nickname"); - + AddCommand("ViewCommands", static_cast(&CNickServ::ViewCommandsCommand), + "", "Show patterns for lines, which are being sent to NickServ"); + AddCommand("SetCommand", static_cast(&CNickServ::SetCommandCommand), + "cmd new-pattern", "Set pattern for commands"); } virtual ~CNickServ() {} @@ -77,6 +114,22 @@ public: SetArgs(""); } + if (GetNV("IdentifyCmd").empty()) { + SetNV("IdentifyCmd", "PRIVMSG NickServ :IDENTIFY {password}"); + } + if (GetNV("GhostCmd").empty()) { + SetNV("GhostCmd", "PRIVMSG NickServ :GHOST {nickname} {password}"); + } + if (GetNV("RecoverCmd").empty()) { + SetNV("RecoverCmd", "PRIVMSG NickServ :RECOVER {nickname} {password}"); + } + if (GetNV("ReleaseCmd").empty()) { + SetNV("ReleaseCmd", "PRIVMSG NickServ :RELEASE {nickname} {password}"); + } + if (GetNV("GroupCmd").empty()) { + SetNV("GroupCmd", "PRIVMSG NickServ :GROUP {nickname} {password}"); + } + return true; } @@ -84,10 +137,13 @@ public: if (!GetNV("Password").empty() && Nick.GetNick().Equals("NickServ") && (sMessage.find("msg") != CString::npos - || sMessage.find("authenticate") != CString::npos) + || sMessage.find("authenticate") != CString::npos + || sMessage.find("choose a different nickname") != CString::npos) && sMessage.AsUpper().find("IDENTIFY") != CString::npos && sMessage.find("help") == CString::npos) { - PutIRC("PRIVMSG NickServ :IDENTIFY " + GetNV("Password")); + MCString msValues; + msValues["password"] = GetNV("Password"); + PutIRC(CString::NamedFormat(GetNV("IdentifyCmd"), msValues)); } }