📄 cbotfactory.cls
字号:
BotConns.Item(szKey).SetPerms GetPrivProfSection(BotConns.Item(szKey).User) 'load the perms
Call SendData(ConnID, "Welcome " & BotConns.Item(szKey).User & vbCrLf)
'send join message to party line
SendToPartyLine "** " & BotConns.Item(szKey).User & " joined the party line."
Else
BotConns.Item(szKey).Status = 0
Call SendData(ConnID, "Access Denied!" & vbCrLf)
Call closesocket(ConnID)
RemoveConn ConnID
End If
Case 2 'authenticated
'Everything is cool, process commands
ProcessUserCommands ConnID, BotConns.Item(szKey), szLine
End Select
End Sub
Private Function Authenticate(ByVal szUser As String, ByVal szPass As String) As Integer
'*Returns Levels of User if auhenticated
'*else returns 0 for no access
'*note that level 0 has no access
Authenticate = 0
If Mid(szUser, 1, 1) = "#" Then Exit Function
If Decrypt(GetPrivProfString(szUser, "pass", "pass.txt")) = szPass Then
Authenticate = 1
End If
End Function
Private Sub ProcessUserCommands(ByVal ConnID As Long, bot As CBotConn, ByVal szLine As String)
Dim szCommand As String, temp As String, param1$, param2$, param3$, param4$, test$
Dim num As Integer
Dim szKey As String
szKey = CStr(ConnID)
szCommand = getNextToken(szLine, " ")
RaiseEvent onUserCommand(BotConns.Item(szKey), szCommand, szLine) 'send to event for outside script processing
If mvarDisableDefaultOps = False Then 'speeds things up by accepting default bot ops
Select Case LCase$(szCommand)
Case ".op"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_OP) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " +o " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.op #channel nick>"
End If
Case ".deop"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_DEOP) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " -o " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.deop #channel nick>"
End If
Case ".+v"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_PV) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " +v " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.+v #channel nick>"
End If
Case ".-v"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_MV) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " -v " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.-v #channel nick>"
End If
Case ".+ban"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_BAN) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " +b " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.+ban #channel params>"
End If
Case ".-ban"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_UNBAN) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " -b " & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.-ban #channel params>"
End If
Case ".banlist"
BotConns.Item(szKey).LastCommand = szCommand
Case ".kick"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_KICK) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
param2$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "KICK " & param1$ & " " & param2$ & " :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.kick #channel nickname kickmessage>"
End If
Case ".kickban"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_KICKBAN) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
param2$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "MODE " & param1$ & " +b " & param2$ & vbCrLf)
Call SendData(mvarlpIRC_SOCKET, "KICK " & param1$ & " " & param2$ & " :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.kickban #channel nickname kickmessage>"
End If
Case ".permban"
BotConns.Item(szKey).LastCommand = szCommand 'priv_permban
Case ".say"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckBotPerms(PRIV_SAY) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") 'target
Call SendData(mvarlpIRC_SOCKET, "PRIVMSG " & param1$ & " :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.say TARGET my message goes here>"
End If
Case ".who"
BotConns.Item(szKey).LastCommand = szCommand
Call SendData(BotConns.Item(szKey).ConnID, "- Begin Who List -" & vbCrLf)
For num = 1 To BotConns.count
If BotConns.Item(num).Status = 2 Then
Call SendData(BotConns.Item(szKey).ConnID, "- " & BotConns.Item(num).User & vbCrLf)
End If
Next num
Call SendData(BotConns.Item(szKey).ConnID, "- End of Who List -" & vbCrLf)
Case ".topic"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckChanPerms(GetChannel(szLine), PRIV_TOPIC) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") >= 2 Then
param1$ = getNextToken(szLine, " ") '#channel
Call SendData(mvarlpIRC_SOCKET, "TOPIC " & param1$ & " :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.topic #channel my topic goes here>"
End If
Case ".join"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckBotPerms(PRIV_JOIN) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") = 1 Then
Call SendData(mvarlpIRC_SOCKET, "JOIN :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.join #channel>"
End If
Case ".part"
BotConns.Item(szKey).LastCommand = szCommand
If BotConns.Item(szKey).CheckBotPerms(PRIV_PART) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") = 1 Then
Call SendData(mvarlpIRC_SOCKET, "PART :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.part #channel>"
End If
Case ".passwd"
BotConns.Item(szKey).LastCommand = szCommand
If CountTokens(szLine, " ") = 1 Then
param1$ = getNextToken(szLine, " ") 'password
WritePrivProfString Encrypt(param1$), BotConns.Item(szKey).User, "pass", "pass.txt"
Call SendData(BotConns.Item(szKey).ConnID, "-Password for " & BotConns.Item(szKey).User & " has been changed!-" & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.passwd new-password-goes-here>"
End If
Case ".adduser"
BotConns.Item(szKey).LastCommand = szCommand 'priv_adduser
If BotConns.Item(szKey).CheckBotPerms(PRIV_ADDUSER) Then
SendBotError ConnID, "Wrong Access Privileges!"
Exit Sub
End If
If CountTokens(szLine, " ") = 2 Then
'Call SendData(mvarlpIRC_SOCKET, "PART :" & szLine & vbCrLf)
Else
SendBotError ConnID, "Syntax Error! <.adduser username password>"
End If
Case ".deluser"
BotConns.Item(szKey).LastCommand = szCommand 'priv_deluser
Case ".lsusers"
BotConns.Item(szKey).LastCommand = szCommand 'priv_lsusers
Case ".info"
BotConns.Item(szKey).LastCommand = szCommand
Case ".note"
BotConns.Item(szKey).LastCommand = szCommand
Case ".help"
BotConns.Item(szKey).LastCommand = szCommand
If szLine = szCommand Then
Open App.Path & "\bothelp.txt" For Input As #1
param1$ = Input(LOF(1), 1)
Close #1
Call SendData(ConnID, "- Begin Help File -" & vbCrLf)
Call SendData(ConnID, param1$ & vbCrLf)
Call SendData(ConnID, "- End Help File -" & vbCrLf)
End If
Case Else
If Mid(szCommand, 1, 1) = "." Then
BotConns.Item(szKey).LastCommand = szCommand
'hit our script
'pass it command, params
Else
'msg to party line
If LCase$(szCommand) = LCase$(szLine) Then
SendToPartyLine "<" & BotConns.Item(szKey).User & "> " & szLine
Else
SendToPartyLine "<" & BotConns.Item(szKey).User & "> " & szCommand & " " & szLine
End If
End If
End Select
Else 'it was false, so everything goes to the script
If Mid(szCommand, 1, 1) = "." Then
BotConns.Item(szKey).LastCommand = szCommand
'hit our script
'pass it command, params
Else
'msg to party line
If LCase$(szCommand) = LCase$(szLine) Then
SendToPartyLine "<" & BotConns.Item(szKey).User & "> " & szLine
Else
SendToPartyLine "<" & BotConns.Item(szKey).User & "> " & szCommand & " " & szLine
End If
End If
End If
End Sub
Public Sub SendToPartyLine(ByVal szLine As String)
Dim num As Integer
For num = 1 To BotConns.count
If BotConns.Item(num).Status = 2 Then
Call SendData(BotConns.Item(num).ConnID, szLine & vbCrLf)
End If
Next num
End Sub
Private Sub SendBotError(ByVal ConnID As Long, ByVal szErr As String)
Call SendData(ConnID, "ERROR: " & szErr & vbCrLf)
End Sub
Public Function GetVersion() As String
GetVersion = "[" & App.Title & "] " & App.Major & "." & App.Minor & "." & App.Revision
End Function
Private Sub SetLevels()
PRIV_OP = CInt(GetPrivProfString("Levels", "op", "bot.ini"))
PRIV_DEOP = CInt(GetPrivProfString("Levels", "deop", "bot.ini"))
PRIV_PV = CInt(GetPrivProfString("Levels", "pv", "bot.ini"))
PRIV_MV = CInt(GetPrivProfString("Levels", "mv", "bot.ini"))
PRIV_KICK = CInt(GetPrivProfString("Levels", "kick", "bot.ini"))
PRIV_BAN = CInt(GetPrivProfString("Levels", "ban", "bot.ini"))
PRIV_UNBAN = CInt(GetPrivProfString("Levels", "unban", "bot.ini"))
PRIV_SAY = CInt(GetPrivProfString("Levels", "say", "bot.ini"))
PRIV_KICKBAN = CInt(GetPrivProfString("Levels", "kickban", "bot.ini"))
PRIV_PERMBAN = CInt(GetPrivProfString("Levels", "permban", "bot.ini"))
PRIV_TOPIC = CInt(GetPrivProfString("Levels", "topic", "bot.ini"))
PRIV_JOIN = CInt(GetPrivProfString("Levels", "join", "bot.ini"))
PRIV_PART = CInt(GetPrivProfString("Levels", "part", "bot.ini"))
PRIV_ADDUSER = CInt(GetPrivProfString("Levels", "adduser", "bot.ini"))
PRIV_DELUSER = CInt(GetPrivProfString("Levels", "deluser", "bot.ini"))
PRIV_LSUSERS = CInt(GetPrivProfString("Levels", "lsusers", "bot.ini"))
PRIV_SETPERMS = CInt(GetPrivProfString("Levels", "setperms", "bot.ini"))
End Sub
Private Sub Class_Initialize()
SetLevels
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -