forked from adinardi/znc-privreplay
-
Notifications
You must be signed in to change notification settings - Fork 1
/
privreplay.cpp
102 lines (82 loc) · 2.59 KB
/
privreplay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "User.h"
#include <sys/stat.h>
class CPrivReplay : public CModule
{
public:
MODCONSTRUCTOR(CPrivReplay)
{
AddCommand(CString("clear"), static_cast<CModCommand::ModCmdFunc>(&CPrivReplay::ClearPrivateMessages));
}
virtual ~CPrivReplay()
{
RemCommand(CString("clear"));
}
void ClearPrivateMessages(const CString &command)
{
if (command != "clear") {
return;
}
m_vMessages.clear();
PutModule(CString("Private messages cleared"));
}
virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage)
{
CString msg = m_pUser->AddTimestamp(CString("[->] ") + sMessage);
StoreMessage(Nick, msg);
return (CONTINUE);
}
virtual EModRet OnUserRaw(CString &sLine)
{
//PutModule("Raw: " + sLine);
if (sLine.Left(7).Equals("PRIVMSG"))
{
//PutModule("OUTBOUND PRIVMSG");
VCString vsRet;
sLine.Split(" ", vsRet);
// Check the prefix on the to name and ignore special users, control channels and channels.
CString toNamePrefix = vsRet[1].Left(1);
if (toNamePrefix.Equals("*") || toNamePrefix.Equals("&") || toNamePrefix.Equals("#"))
{
return CONTINUE;
}
CString msg = vsRet[2];
msg.LeftChomp(1);
// Don't process outgoing CTCP
if (msg.Left(1).Equals("\x01"))
return (CONTINUE);
for (int c = 3; vsRet.size() > c; c++)
{
msg += " " + vsRet[c];
}
CString timestamp_msg = m_pUser->AddTimestamp(CString("[<-] ") + msg);
StoreRawMessage(":" + vsRet[1] + " PRIVMSG " + m_pUser->GetIRCNick().GetNick() + " :" + timestamp_msg);
}
return (CONTINUE);
}
virtual void OnClientLogin()
{
ReplayMessages();
}
private:
void StoreMessage(const CNick & Nick, CString & sMessage)
{
StoreRawMessage(":" + Nick.GetNickMask() + " PRIVMSG " + m_pUser->GetIRCNick().GetNick() + " :" + sMessage);
}
void StoreRawMessage(const CString & sText)
{
m_vMessages.push_back(sText);
}
void ReplayMessages()
{
if (!m_vMessages.empty())
{
vector<CString>::iterator iter;
for (iter = m_vMessages.begin(); iter != m_vMessages.end(); iter++)
{
PutUser(*iter);
}
}
}
vector<CString> m_vMessages;
};
MODULEDEFS(CPrivReplay, "Stores private messages and replays them");