-
Notifications
You must be signed in to change notification settings - Fork 2
/
BotEvents.bas
274 lines (224 loc) · 15 KB
/
BotEvents.bas
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include once "BotEvents.bi"
#include once "IrcReplies.bi"
#include once "Bot.bi"
#include once "Settings.bi"
#include once "ProcessCommands.bi"
#include once "QuestionToChat.bi"
#include once "AnswerToChat.bi"
#include once "WriteLine.bi"
#include once "CharConstants.bi"
#include once "IntegerToWString.bi"
#include once "DateTimeToString.bi"
#include once "Logging.bi"
Const NickServNick = "NickServ"
Const PasswordKey = "NickServPassword"
Sub ChannelMessage( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal Channel As WString Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
LogIrcMessage(pBot, Channel, pIrcPrefix->Nick, MessageText)
IncrementUserWords(Channel, pIrcPrefix->Nick)
If ProcessUserCommand(pBot, pIrcPrefix->Nick, Channel, MessageText) Then
Exit Sub
End If
If QuestionToChat(pBot, Channel, MessageText) Then
Exit Sub
End If
AnswerToChat(pBot, Channel, MessageText)
End Sub
Sub ServerMessage( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal IrcCommand As WString Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
If lstrcmp(IrcCommand, @RPL_WELCOME) = 0 Then
Dim PasswordBuffer As WString * (IrcClient.MaxBytesCount + 1) = Any
Dim Result As Integer = GetSettingsValue(@PasswordBuffer, IrcClient.MaxBytesCount, @PasswordKey)
If Result <> -1 Then
If lstrlen(@PasswordBuffer) > 0 Then
Dim Buffer As WString * (IrcClient.MaxBytesCount + 1) = Any
lstrcpy(@Buffer, "IDENTIFY ")
lstrcat(@Buffer, @PasswordBuffer)
SendIrcMessage(@pBot->Client, @NickServNick, @Buffer)
End If
End If
JoinChannel(@pBot->Client, @pBot->Channels)
Exit Sub
End If
If lstrcmp(IrcCommand, @RPL_WHOISLOGGEDAS) = 0 Then
':orwell.freenode.net 330 Station922_mkv PERDOLIKS writed :is logged in as
Dim WordsCount As Long = Any
Dim Lines As WString Ptr Ptr = CommandLineToArgvW(MessageText, @WordsCount)
If WordsCount > 4 Then
If lstrcmp(Lines[1], @pbot->AdminNick1) = 0 OrElse lstrcmp(Lines[1], @pBot->AdminNick2) = 0 Then
If lstrcmp(Lines[2], @pbot->AdminNick1) = 0 Then
If StrStr(MessageText, ":is logged in as") <> 0 Then
pBot->AdminAuthenticated = True
If lstrlen(pBot->SavedChannel) <> 0 Then
pBot->Say(pBot->SavedChannel, @"Аутентификация успешно пройдена.")
pBot->SavedChannel[0] = 0
End If
End If
End If
Else
If lstrlen(pBot->SavedChannel) <> 0 Then
pBot->Say(pBot->SavedChannel, @"Ты никто и судьбы твоей нет. Ты проиграл свою душу, она не принадлежит тебе уже.")
pBot->SavedChannel[0] = 0
End If
End If
End If
LocalFree(Lines)
Exit Sub
End If
If lstrcmp(IrcCommand, @RPL_NAMREPLY) = 0 Then
Dim wStart As WString Ptr = StrChr(MessageText, ColonChar)
If wStart <> 0 Then
wStart += 1
' Список пользователей в дерево
Dim WordsCount As Long = Any
Dim Lines As WString Ptr Ptr = CommandLineToArgvW(MessageText, @WordsCount)
LocalFree(Lines)
End If
Exit Sub
End If
End Sub
Sub UserJoined( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal Channel As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
Dim wChannel As WString Ptr = Any
If Channel[0] = ColonChar Then
wChannel = @Channel[1]
Else
wChannel = @Channel[0]
End If
LogUserJoined(pBot, wChannel, pIrcPrefix->Nick)
If lstrcmp(@pbot->MainChannel, wChannel) <> 0 Then
Exit Sub
End If
If lstrcmp(pBot->BotNick, pIrcPrefix->Nick) <> 0 Then
SendCtcpVersionRequest(@pBot->Client, pIrcPrefix->Nick)
End If
End Sub
Sub UserLeaved( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal Channel As WString Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
LogPartChannel(pBot, Channel, pIrcPrefix->Nick, MessageText)
End Sub
Sub UserQuit( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
LogUserQuit(pBot, pIrcPrefix->Nick, MessageText)
If lstrcmp(pIrcPrefix->Nick, @pBot->AdminNick1) = 0 OrElse lstrcmp(pIrcPrefix->Nick, @pBot->AdminNick2) = 0 Then
pBot->AdminAuthenticated = False
End If
End Sub
Sub NickChanged( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal NewNick As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
LogNickChanged(pBot, pIrcPrefix->Nick, NewNick)
If lstrcmp(pIrcPrefix->Nick, @pbot->AdminNick1) = 0 Then
pBot->AdminAuthenticated = False
End If
If lstrcmp(pIrcPrefix->Nick, @pbot->AdminNick2) = 0 Then
pBot->AdminAuthenticated = False
End If
End Sub
Sub Ping( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal Server As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
SendPong(@pBot->Client, Server)
End Sub
Sub CtcpPingResponse( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal ToUser As WString Ptr, _
ByVal TimeValue As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
Dim CurrentSystemDateTicks As ULARGE_INTEGER = GetCurrentSystemDateTicks()
If lstrcmp(pIrcPrefix->Nick, ToUser) = 0 Then
Exit Sub
End If
If lstrlen(pBot->SavedChannel) = 0 Then
Exit Sub
End If
Dim UserDateTicks As ULARGE_INTEGER = Any
If StrToInt64Ex(TimeValue, STIF_DEFAULT, @UserDateTicks.QuadPart) = 0 Then
Exit Sub
End If
Dim UserDelay As Integer = CurrentSystemDateTicks.QuadPart - UserDateTicks.QuadPart
UserDelay = UserDelay \ 100
UserDelay = UserDelay \ 2
Dim strUserDelay As WString * (IrcClient.MaxBytesCount + 1) = Any
lstrcpy(@strUserDelay, pBot->SavedUser)
lstrcat(@strUserDelay, ": ping from you ")
itow(UserDelay, @strUserDelay + lstrlen(@strUserDelay), 10)
lstrcat(@strUserDelay, " microseconds.")
pBot->Say(pBot->SavedChannel, @strUserDelay)
pBot->SavedChannel[0] = 0
End Sub
Sub CtcpVersionResponse( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal ToUser As WString Ptr, _
ByVal Version As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
If lstrcmp(pIrcPrefix->Nick, ToUser) <> 0 Then
Dim ClientVersion As WString * (IrcClient.MaxBytesCount + 1)
lstrcpy(@ClientVersion, pIrcPrefix->Nick)
lstrcat(@ClientVersion, @" is using ")
lstrcat(@ClientVersion, Version)
pBot->SayToMainChannel(@ClientVersion)
End If
End Sub
Sub Kick( _
ByVal ClientData As Any Ptr, _
ByVal pIrcPrefix As IrcPrefix Ptr, _
ByVal Channel As WString Ptr, _
ByVal KickedUser As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
JoinChannel(@pBot->Client, Channel)
End Sub
Sub SendedRawMessage( _
ByVal ClientData As Any Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
pBot->SendedRawMessagesCounter += 1
#ifndef service
WriteLine(pBot->OutHandle, MessageText)
#endif
End Sub
Sub ReceivedRawMessage( _
ByVal ClientData As Any Ptr, _
ByVal MessageText As WString Ptr _
)
Dim pBot As IrcBot Ptr = CPtr(IrcBot Ptr, ClientData)
pBot->ReceivedRawMessagesCounter += 1
#ifndef service
WriteLine(pBot->OutHandle, MessageText)
#endif
End Sub