-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomPhraseKick.txt
240 lines (209 loc) · 8.46 KB
/
RandomPhraseKick.txt
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Script("Name") = "Random Phrase Kicker"
Script("Author") = "Pyro"
Script("Major") = 2
Script("Minor") = 1
'// Changelog
'// v2.1
'// - Added a per-user kick limit. Users will be banned once they exceed this limit. Set to 0 to disable.
'// - Changed phrases to be lower cased in the ban message (to look more natural).
'// - Changed the SPEAKERACCESS parameter used in BanKickUnban() to be configurable. Default: 1
'// - Moved the display of kick count from the ban message to the console.
'// - Changed phrase processing to choose a small subset of the phrase if it's too long.
'// - Removed wildcard support for victims.
Const MODE_BAN = 0
Const MODE_KICK = 1
Const BASE_COMMAND = "rpk"
Public victims, kickLimit, useNaturalPhrases, speakerAccess
Sub Event_Load()
Dim arrVics, i, curVic
'// Loads the list of victims.
Set victims = CreateObject("Scripting.Dictionary")
arrVics = Split(GetSettingsEntry("victims"), "|")
For i = LBound(arrVics) To UBound(arrVics)
Set curVic = New RPKVictim
curVic.Name = Split(arrVics(i), ":")(0)
If InStr(arrVics(i), ":") > 0 Then
curVic.TotalKicks = Int(Split(arrVics(i), ":")(1))
Else
curVic.TotalKicks = 0
End If
curVic.KickCount = 0
victims.Add curVic.Name, curVic
Next
'// Loads various settings.
kickLimit = GetSettingsEntry("kickLimit")
If kickLimit = vbNullString Then kickLimit = 0 Else kickLimit = CInt(kickLimit) End If
speakerAccess = GetSettingsEntry("speakerAccess")
If speakerAccess = vbNullString Then speakerAccess = 1 Else speakerAccess = CInt(speakerAccess) End If
'// Check to see if the script's command has already been made.
Dim cmd, param, rank, flags
Set cmd = OpenCommand(BASE_COMMAND)
If cmd Is Nothing Then
rank = 70
flags = "O"
Else
'// Preserve user defined rank and flags.
rank = cmd.RequiredRank
flags = cmd.RequiredFlags
Set cmd = DeleteCommand(BASE_COMMAND)
End If
'// Create the script's command.
Set cmd = CreateCommand(BASE_COMMAND)
With cmd
Set param = .NewParameter("option", False, "word")
With param
.Description = "The action to execute. add/remove/list"
End With
.Parameters.Add param
Set param = .NewParameter("value", True, "word")
With param
.Description = "The value to go with the action."
End With
.Parameters.Add param
.RequiredRank = rank
.RequiredFlags = flags
.Description = "Manages the RPK victims list and associated settings."
.Save
End With
End Sub
Sub Event_Close()
'// Save victim list/kick counts and settings.
Dim i, strVics
strVics = vbNullString
For i = 0 To (victims.Count - 1)
strVics = strVics & victims.Items(i).Name & ":" & victims.Items(i).TotalKicks & "|"
Next
WriteSettingsEntry "victims", strVics
WriteSettingsEntry "kickLimit", CStr(kickLimit)
WriteSettingsEntry "speakerAccess", CStr(speakerAccess)
End Sub
Sub Event_UserTalk(Username, Flags, Message, Ping)
Call processChat(Username, Message)
End Sub
Sub Event_UserEmote(Username, Flags, Message)
Call processChat(Username, Message)
End Sub
Sub processChat(Username, Message)
Dim i, mSplit, nRand
If GetVictim(Username) Then
AddChat vbGreen, StringFormat("Found RPK match: {0} - Kick Count: {1} - Total Kicks: {2}", vic.Name, vic.KickCount, vic.TotalKicks)
mSplit = Split(Message, " ")
nRand = Int(Rnd * UBound(mSplit))
vic.Kick mSplit(nRand)
End If
End Sub
Sub Event_Command(cmd)
If cmd.Docs.Owner = Script("Name") Then
Select Case LCase(cmd.Name)
Case "rpk":
If cmd.IsValid Then
Dim opt, val
opt = LCase(cmd.Argument("option"))
val = cmd.Argument("value")
Select Case opt
Case "a", "add":
Dim vic
If GetVictim(val) Is Nothing Then
If val <> vbNullString Then
Set vic = New RPKVictim
vic.Name = val
vic.KickCount = 0
vic.TotalKicks = 0
victims.Add vic.Name, vic
cmd.Respond StringFormat("Added ""{0}"" to the RPK victims list.", vic.Name)
Else
cmd.Respond "Please specify a user to add to the RPK victims list."
End If
Else
cmd.Respond StringFormat("User ""{0}"" is already a victim.", val)
End If
Case "r", "rem", "remove", "d", "del", "delete":
If val <> vbNullString Then
If GetVictim(val) Is Nothing Then
cmd.Respond StringFormat("User ""{0}"" is not a victim.", val)
Else
victims.Remove val
cmd.Respond StringFormat("Removed user ""{0}"" from the RPK victims list.", val)
End If
Else
cmd.Respond "Please specify a user to remove from the RPK victims list."
End If
Case "l", "list":
Dim i, v
If victims.Count > 0 Then
Dim strVictims
strVictims = vbNullString
v = victims.Items
For i = 0 To (victims.Count - 1)
strVictims = strVictims & StringFormat("{0} [{1}], ", v(i).Name, v(i).TotalKicks)
Next
strVictims = Left(strVictims, Len(strVictims) - 2)
cmd.Respond StringFormat("RPK victims (total: {0}): {1}", victims.Count, strVictims)
Else
cmd.Respond "There are no users on the RPK victims list."
End If
Case "limit"
If IsNumeric(val) Then
val = CInt(val)
If val < 0 Then
cmd.Respond "Invalid kick limit. Must be greater than or equal to 0."
Else
kickLimit = val
cmd.Respond StringFormat("Kick limit set to {0}.", kickLimit)
End If
Else
cmd.Respond "Invalid kick limit. Must be a number."
End If
Case "strength"
If IsNumeric(val) Then
val = CInt(val)
If val < 0 Then
cmd.Respond "Invalid kick strength (speaker access) value. Must be greater than or equal to 0."
Else
speakerAccess = val
cmd.Respond StringFormat("Kick strength (speaker access) set to {0}.", speakerAccess)
End If
Else
cmd.Respond "Invalid kick strength (speaker access) value. Must be a number."
End If
Case Else
cmd.Respond "Unknwon RPK option. Valid options include 'add', 'emove', and 'list'."
End Select
Else
cmd.Respond StringFormat("Proper syntax for this command is: {0}{1} <option> [value]", BotVars.Trigger, BASE_COMMAND)
End If
End Select
End If
End Sub
'// Returns the RPKVictim class instance for the specified user, or NOTHING if the user is not a victim.
Function GetVictim(Username)
Dim i
For i = 0 To (victims.Count - 1)
If LCase(Username) = LCase(victims.Items(i).Name) Then
Set GetVictim = victims.Items(i)
End If
Next
Set GetVictim = Nothing
End Function
Class RPKVictim
Public Name '// Name of the user.
Public KickCount '// Kicks this session/since last ban.
Public TotalKicks '// Total kicks ever.
'// Kicks the victim for using the specified phrase.
Public Sub Kick(phrase)
BanKickUnban StringFormat("{0} Phrasekick: {1}", Me.Name, LCase(phrase)), speakerAccess, MODE_KICK
Me.KickCount = Me.KickCount + 1
If Me.KickCount > kickLimit Then
Me.Ban()
End If
End Sub
'// Bans the victim for being phrasekicked too many times.
Public Sub Ban()
BanKickUnban StringFormat("{0} Phrasekick limit exceeded. [{1}]", Me.Name, speakerAccess, MODE_BAN
Me.ResetKicks
End Sub
'// Resets a user's kick count to 0.
Public Sub ResetKicks()
Me.KickCount = 0
End Sub
End Class