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
This commit is contained in:
psychon
2009-08-07 19:33:29 +00:00
parent 75a342304c
commit 4e18ebf07a
2 changed files with 86 additions and 0 deletions
+1
View File
@@ -21,3 +21,4 @@ Freman (http://fremnet.net/contact)
Sebastian Ramacher <sebastinas@users.sourceforge.net>
cnu - master of destruction (security issues)
Ingmar "KiNgMaR" Runge (mail@irsoft.de)
Michael "Svedrin" Ziegler (diese-addy@funzt-halt.net)
+85
View File
@@ -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 <reply> - Sets a new reply");
}
}
private:
TCacheMap<CString> m_Messaged;
};
MODULEDEFS(CAutoReplyMod, "Reply to queries when you are away")