Files
znc/modules/autoreply.cpp
psychon 4e18ebf07a 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
2009-08-07 19:33:29 +00:00

86 lines
1.9 KiB
C++

/*
* 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")