-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathantiidle.cpp
113 lines (89 loc) · 2.92 KB
/
antiidle.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
102
103
104
105
106
107
108
109
110
111
112
113
// Original antiidle module would message "\xAE" to ourself.
// Modified to send a message into a channel.
// Tip:
// If you don't want to idle in the channel you can do something like this to allow
// external messages.
// /msg chanserv register ##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE
// /msg chanserv set ##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE guard on
// /msg chanserv set ##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE mlock -n
// /part ##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE
// TODO:
// Recreate channel if cannot send.
// :irc.foobar.net 404 KindOne ##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE :Cannot send to nick/channel
// OnNumericMessage() { if 404 && match first chraracter as #, { join TARGET ; }}
// OnJoin() if (chan TARGET) && (nick ChanServ) { part TARGET }
/*
* Copyright (C) 2004-2012 See the AUTHORS file for details.
*
* 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 <znc/Nick.h>
#include <znc/IRCNetwork.h>
#define TARGET "##CHANGE_THIS_CHANNEL_NAME_INTO_SOMETHING_ELSE"
#define MESSAGE "anti-idle script..."
class CAntiIdle;
class CAntiIdleJob : public CTimer
{
public:
CAntiIdleJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription)
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {}
virtual ~CAntiIdleJob() {}
protected:
virtual void RunJob();
};
class CAntiIdle : public CModule
{
public:
MODCONSTRUCTOR(CAntiIdle) {
SetInterval(30);
}
virtual ~CAntiIdle() {}
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg)
{
if(!sArgs.Trim_n().empty())
SetInterval(sArgs.ToInt());
return true;
}
virtual void OnModCommand( const CString& sCommand )
{
CString sCmdName = sCommand.Token(0).AsLower();
if(sCmdName == "set")
{
CString sInterval = sCommand.Token(1, true);
SetInterval(sInterval.ToInt());
if(m_uiInterval == 0)
PutModule("AntiIdle is now turned off.");
else
PutModule("AntiIdle is now set to " + CString(m_uiInterval) + " seconds.");
} else if(sCmdName == "off") {
SetInterval(0);
PutModule("AntiIdle is now turned off");
} else if(sCmdName == "show") {
if(m_uiInterval == 0)
PutModule("AntiIdle is turned off.");
else
PutModule("AntiIdle is set to " + CString(m_uiInterval) + " seconds.");
} else {
PutModule("Commands: set, off, show");
}
}
private:
void SetInterval(int i)
{
if(i < 0)
return;
m_uiInterval = i;
RemTimer("AntiIdle");
if(m_uiInterval == 0) {
return;
}
AddTimer(new CAntiIdleJob(this, m_uiInterval, 0, "AntiIdle", "Periodically sends a msg to the user"));
}
unsigned int m_uiInterval;
};
void CAntiIdleJob::RunJob() {
GetModule()->PutIRC("PRIVMSG " TARGET " :" MESSAGE);
}
NETWORKMODULEDEFS(CAntiIdle, "Hides your real idle time")