From 4e18ebf07a927309e3c5c0bc61ca072c9b1ea224 Mon Sep 17 00:00:00 2001 From: psychon Date: Fri, 7 Aug 2009 19:33:29 +0000 Subject: [PATCH] Import the autoreply module from znc-extra This module automatically replies to queries and private notices if no user is connected to ZNC. Svedrin submitted an initial version of this module, but due to my own stupidness I later rewrote it. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1593 726aef4b-f618-498e-8847-2d620e286838 --- AUTHORS | 1 + modules/autoreply.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 modules/autoreply.cpp diff --git a/AUTHORS b/AUTHORS index 8f740c0c..8f3a8325 100644 --- a/AUTHORS +++ b/AUTHORS @@ -21,3 +21,4 @@ Freman (http://fremnet.net/contact) Sebastian Ramacher cnu - master of destruction (security issues) Ingmar "KiNgMaR" Runge (mail@irsoft.de) +Michael "Svedrin" Ziegler (diese-addy@funzt-halt.net) diff --git a/modules/autoreply.cpp b/modules/autoreply.cpp new file mode 100644 index 00000000..01ec340e --- /dev/null +++ b/modules/autoreply.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004-2009 See the AUTHORS file for details. + * Copyright (C) 2008 Michael "Svedrin" Ziegler diese-addy@funzt-halt.net + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include "Modules.h" +#include "User.h" + +class CAutoReplyMod : public CModule { +public: + MODCONSTRUCTOR(CAutoReplyMod) { + m_Messaged.SetTTL(1000 * 120); + } + + virtual ~CAutoReplyMod() {} + + virtual bool OnLoad(const CString& sArgs, CString& sMessage) { + if (!sArgs.empty()) { + SetReply(sArgs); + } + + return true; + } + + void SetReply(const CString& sReply) { + SetNV("Reply", sReply); + } + + CString GetReply() { + CString sReply = GetNV("Reply"); + if (sReply.empty()) { + sReply = "%nick% is currently away, try again later"; + SetReply(sReply); + } + + return m_pUser->ExpandString(sReply); + } + + void Handle(const CString& sNick) { + if (m_Messaged.HasItem(sNick)) + return; + + if (m_pUser->IsUserAttached()) + return; + + m_Messaged.AddItem(sNick); + PutIRC("PRIVMSG " + sNick + " :" + GetReply()); + } + + virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) { + Handle(Nick.GetNick()); + return CONTINUE; + } + + virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) { + Handle(Nick.GetNick()); + return CONTINUE; + } + + virtual void OnModCommand(const CString& sCommand) { + const CString& sCmd = sCommand.Token(0); + + if (sCmd.Equals("SHOW")) { + PutModule("Current reply is: " + GetNV("Reply") + + " (" + GetReply() + ")"); + } else if (sCmd.Equals("SET")) { + SetReply(sCommand.Token(1, true)); + PutModule("New reply set"); + } else { + PutModule("Available commands are:"); + PutModule("Show - Displays the current query reply"); + PutModule("Set - Sets a new reply"); + } + } + +private: + TCacheMap m_Messaged; +}; + +MODULEDEFS(CAutoReplyMod, "Reply to queries when you are away") +