-
Notifications
You must be signed in to change notification settings - Fork 6
/
m_insp_joinpartspam.cpp
118 lines (98 loc) · 2.74 KB
/
m_insp_joinpartspam.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
114
115
116
117
118
/*
* Support for InspIRCd 2.0 & 3 Contrib m_joinpartspam.
*
* (C) 2019 - Matt Schatz (genius3000@g3k.solutions)
* Please refer to the GPL License in use by Anope at:
* https://github.com/anope/anope/blob/master/docs/COPYING
*
* Provides the required logic for the mode to be mostly
* functional with ChanServ MODE but not abusable.
*
* Configuration to put into your modules config:
module { name = "m_insp_joinpartspam" }
*
*/
#include "module.h"
static Module *me;
class ChannelModeJoinPartSpam : public ChannelModeParam
{
bool ParseCycles(sepstream &stream) const
{
Anope::string strcycles;
if (!stream.GetToken(strcycles))
return false;
try
{
int result = convertTo<int>(strcycles);
if (result < 2 || result > 20)
return false;
}
catch (const ConvertException &)
{
return false;
}
return true;
}
bool ParseSeconds(sepstream &stream) const
{
Anope::string strseconds;
if (!stream.GetToken(strseconds))
return false;
try
{
int result = convertTo<int>(strseconds);
if (result < 1 || result > 43200)
return false;
}
catch (const ConvertException &)
{
return false;
}
return true;
}
public:
ChannelModeJoinPartSpam(const Anope::string &modename, const char modechar) : ChannelModeParam(modename, modechar, true) { }
bool IsValid(Anope::string &value) const anope_override
{
sepstream stream(value, ':');
if (!ParseCycles(stream))
return false;
// This checks duration first then block time.
if (!ParseSeconds(stream) || !ParseSeconds(stream))
return false;
// Disallow any redirect from here, we can't verify the parameter.
if (!stream.StreamEnd())
return false;
return true;
}
};
class InspJoinPartSpam : public Module
{
const Anope::string modename;
const char modechar;
public:
InspJoinPartSpam(const Anope::string &modname, const Anope::string &creator)
: Module(modname, creator, THIRD)
, modename("JOINPARTSPAM")
, modechar('x')
{
if (Anope::VersionMajor() != 2 || Anope::VersionMinor() != 0)
throw ModuleException("Requires version 2.0.x of Anope.");
if (!ModuleManager::FindModule("inspircd20") && !ModuleManager::FindModule("inspircd3"))
throw ModuleException("This module only works with InspIRCd versions 2.0.x and 3.x.");
ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar);
if (cm)
throw ModuleException("A channel mode with character '" + Anope::string(modechar) + "' already exists.");
this->SetAuthor("genius3000");
this->SetVersion("1.0.2");
me = this;
ModeManager::AddChannelMode(new ChannelModeJoinPartSpam(modename, modechar));
}
~InspJoinPartSpam()
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar);
if (cm)
ModeManager::RemoveChannelMode(cm);
}
};
MODULE_INIT(InspJoinPartSpam)