-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBot.bas
More file actions
202 lines (167 loc) · 15.5 KB
/
Bot.bas
File metadata and controls
202 lines (167 loc) · 15.5 KB
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
#ifndef unicode
#define unicode
#endif
#include once "bot.bi"
#include once "BotEvents.bi"
#include once "IntegerToWString.bi"
#include once "Settings.bi"
#include once "Resources.rh"
#include once "Logging.bi"
Const DefaultIniFileName = "Qubick.ini"
Const AsciiFileName = "ascii.txt"
Const AnswersDatabaseFileName = "QubickAnswers.txt"
Const ChannelLogsFileName = "ChannelLogs.xml"
Const StatisticsFileName = "channelstats.xml"
Const DefaultIrcServer = "chat.freenode.net"
Const DefaultPort = "6667"
Const DefaultLocalAddress = "0.0.0.0"
Const DefaultLocalPort = "0"
#if __FB_DEBUG__ <> 0
Const DefaultBotNick = "Station922_mkv"
#else
Const DefaultBotNick = "Qubick"
#endif
Const DefaultUserString = "Qubick"
Const DefaultDescription = "Irc bot written in FreeBASIC"
Const DefaultRealName = "Qubick"
Const DefaultChannels = "#s2ch,#freebasic-ru"
Const DefaultMainChannel = "#freebasic-ru"
Const DefaultAdminNick1 = "writed"
' Версия бота \ Версия ОС \ Процессор \ Физическая память всего
' HexChat 2.12.4 [x86] / Microsoft Windows 10 Pro (x64) [Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz (3.60GHz)] via ZNC - http://znc.in
Const BotVersion1 = "IrcBot version "
Const BotVersion2 = " \ FreeBASIC \ Microsoft Windows "
Const ConnectionSectionString = "Connection"
Const IrcBotSectionString = "IrcBot"
Const ServerKeyString = "Server"
Const PortKeyString = "Port"
Const LocalAddressKeyString = "LocalAddress"
Const LocalPortKeyString = "LocalPort"
Const NickKeyString = "Nick"
Const ServerPasswordKeyString = "ServerPassword"
Const UserKeyString = "UserString"
Const DescriptionKeyString = "Description"
Const RealNameKeyString = "RealName"
Const ChannelsKeyString = "Channels"
Const MainChannelKeyString = "MainChannel"
Const AdminNick1KeyString = "AdminNick1"
Const AdminNick2KeyString = "AdminNick2"
Sub MakeBotVersion(ByVal Version As WString Ptr)
lstrcpy(Version, @BotVersion1)
lstrcat(Version, @VER_PRODUCTVERSION_STR)
Dim VersionLength As Integer = lstrlen(Version)
lstrcpy(Version + VersionLength - 2, @BotVersion2)
Dim osVersion As OsVersionInfoEx
osVersion.dwOSVersionInfoSize = SizeOf(OsVersionInfoEx)
If GetVersionEx(CPtr(OsVersionInfo Ptr, @osVersion)) <> 0 Then
Scope
Dim strNumber As WString * 256 = Any
itow(osVersion.dwMajorVersion, @strNumber, 10)
lstrcat(Version, @strNumber)
lstrcat(Version, @".")
End Scope
Scope
Dim strNumber As WString * 256 = Any
itow(osVersion.dwMinorVersion, @strNumber, 10)
lstrcat(Version, @strNumber)
lstrcat(Version, @".")
End Scope
Scope
Dim strNumber As WString * 256 = Any
itow(osVersion.dwBuildNumber, @strNumber, 10)
lstrcat(Version, @strNumber)
End Scope
End If
End Sub
Function InitializeIrcBot( _
ByVal pBot As IrcBot Ptr _
)As Boolean
' Имя исполняемого файла
Dim ExeFileName As WString * (MAX_PATH + 1) = Any
Dim ExeFileNameLength As DWORD = GetModuleFileName(0, @ExeFileName, MAX_PATH)
If ExeFileNameLength = 0 Then
Return False
End If
lstrcpy(@pBot->ExeDir, @ExeFileName)
PathRemoveFileSpec(@pBot->ExeDir)
' Файл с настройками
PathCombine(@pBot->IniFileName, @pBot->ExeDir, @DefaultIniFileName)
PathCombine(@pBot->AsciiFileName, @pBot->ExeDir, @AsciiFileName)
PathCombine(@pBot->AnswersDatabaseFileName, @pBot->ExeDir, @AnswersDatabaseFileName)
PathCombine(@pBot->ChannelLogsFileName, @pBot->ExeDir, @ChannelLogsFileName)
PathCombine(@pBot->StatisticsFileName, @pBot->ExeDir, @StatisticsFileName)
GetPrivateProfileString(@ConnectionSectionString, @ServerKeyString, @DefaultIrcServer, @pBot->IrcServer, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@ConnectionSectionString, @PortKeyString, @DefaultPort, @pBot->Port, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@ConnectionSectionString, @LocalAddressKeyString, @DefaultLocalAddress, @pBot->LocalAddress, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@ConnectionSectionString, @LocalPortKeyString, @DefaultLocalPort, @pBot->LocalPort, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @ServerPasswordKeyString, @"", @pBot->ServerPassword, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @NickKeyString, @DefaultBotNick, @pBot->BotNick, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @UserKeyString, @DefaultUserString, @pBot->UserString, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @DescriptionKeyString, @DefaultDescription, @pBot->Description, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @RealNameKeyString, @DefaultRealName, @pBot->AdminRealName, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @ChannelsKeyString, @DefaultChannels, @pBot->Channels, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @MainChannelKeyString, @DefaultMainChannel, @pBot->MainChannel, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @AdminNick1KeyString, @DefaultAdminNick1, @pBot->AdminNick1, IrcClient.MaxBytesCount, @pBot->IniFileName)
GetPrivateProfileString(@IrcBotSectionString, @AdminNick2KeyString, @DefaultAdminNick1, @pBot->AdminNick2, IrcClient.MaxBytesCount, @pBot->IniFileName)
pBot->ReconnectToServer = True
pBot->InHandle = GetStdHandle(STD_INPUT_HANDLE)
pBot->OutHandle = GetStdHandle(STD_OUTPUT_HANDLE)
pBot->ErrorHandle = GetStdHandle(STD_ERROR_HANDLE)
pBot->ReceivedRawMessagesCounter = 0
pBot->SendedRawMessagesCounter = 0
pBot->SavedChannel[0] = 0
pBot->SavedUser[0] = 0
pBot->AdminAuthenticated = False
pBot->Client.AdvancedClientData = pBot
pBot->Client.CodePage = CP_UTF8
pBot->Client.ClientUserInfo = @pBot->AdminRealName
MakeBotVersion(@pBot->RealBotVersion)
pBot->Client.ClientVersion = @pBot->RealBotVersion
pBot->Client.lpfnSendedRawMessageEvent = @SendedRawMessage
pBot->Client.lpfnReceivedRawMessageEvent = @ReceivedRawMessage
pBot->Client.lpfnServerMessageEvent = @ServerMessage
pBot->Client.lpfnChannelMessageEvent = @ChannelMessage
pBot->Client.lpfnPrivateMessageEvent = 0
pBot->Client.lpfnUserJoinedEvent = @UserJoined
pBot->Client.lpfnServerErrorEvent = 0
pBot->Client.lpfnNoticeEvent = 0
pBot->Client.lpfnChannelNoticeEvent = 0
pBot->Client.lpfnUserLeavedEvent = @UserLeaved
pBot->Client.lpfnNickChangedEvent = @NickChanged
pBot->Client.lpfnTopicEvent = 0
pBot->Client.lpfnQuitEvent = @UserQuit
pBot->Client.lpfnKickEvent = @Kick
pBot->Client.lpfnInviteEvent = 0
pBot->Client.lpfnPingEvent = 0
pBot->Client.lpfnPongEvent = 0
pBot->Client.lpfnModeEvent = 0
pBot->Client.lpfnCtcpPingRequestEvent = 0
pBot->Client.lpfnCtcpTimeRequestEvent = 0
pBot->Client.lpfnCtcpUserInfoRequestEvent = 0
pBot->Client.lpfnCtcpVersionRequestEvent = 0
pBot->Client.lpfnCtcpActionEvent = 0
pBot->Client.lpfnCtcpPingResponseEvent = @CtcpPingResponse
pBot->Client.lpfnCtcpTimeResponseEvent = 0
pBot->Client.lpfnCtcpUserInfoResponseEvent = 0
pBot->Client.lpfnCtcpVersionResponseEvent = @CtcpVersionResponse
End Function
Sub IrcBot.SayToMainChannel( _
ByVal MessageText As WString Ptr _
)
Say(@MainChannel, MessageText)
End Sub
Sub IrcBot.SayWithTimeOut( _
ByVal Channel As WString Ptr, _
ByVal MessageText As WString Ptr _
)
Say(Channel, MessageText)
SleepEx(MessageTimeWait, True)
End Sub
Sub IrcBot.Say( _
ByVal Channel As WString Ptr, _
ByVal MessageText As WString Ptr _
)
LogIrcMessage(@this, Channel, @BotNick, MessageText)
IncrementUserWords(Channel, @BotNick)
SendIrcMessage(@Client, Channel, MessageText)
End Sub