It should though have the "watchip" command for ops...(note I did none of the optimizations that I could have done - just added watchip)
Code: Select all
Dim sBotName
Dim lInterval, lCountDown
Dim oFW, oUW, oIW
Dim sConfirmMsg
Dim sFileMsg, sUserMsg, sAddUserMsg, sAddFileMsg
Dim sResetMsg, sUserOnline, sWelcomeMsg
Sub Main()
Set oFW = CreateObject("Scripting.Dictionary")
Set oUW = CreateObject("Scripting.Dictionary")
Set oIW = CreateObject("Scripting.Dictionary")
'Set these basic parameters.
sBotName = "WatchBot" ' <- name of the bot
lInterval = 6 ' <- how often to search for files (* 10 seconds)
'The messages sent at different actions.
sFileMsg = "$usr has files matching '$file'."
sUserMsg = "$name logged on."
sAddUserMsg = "Waiting for $name to log on..."
sAddFileMsg = "Started searching for '$file'..."
sResetMsg = "Your watch list was cleared."
sUserOnline = "That user is already online!"
sWelcomeMsg = "Hi there! I will watch for users or files which are " & _
"not here, and then tell you when they come online. Please type the " & _
"commands in mainchat:" & vcBRLF & vbCRLF & _
" watchuser <user_name>" & vbTab & "- adds a user to my list" & vbCRLF & _
" watchfile <file_name>" & vbTab & "- adds a file to my list" & vbCRLF & _
" watchreset" & vbTab & vbTab & "- clears the list" & vbCRLF
lCountDown = lInterval
tmrScriptTimer.Interval = 10000
tmrScriptTimer.Enabled = True
End Sub
Sub TimerMethod()
Dim sFind
For Each sFind In oFW.Keys
colUsers.SendToAll "$Search Hub:" & CStr(sBotName) & " F?F?0?0?" & sFind
frmHub.DoEventsForMe
Next
End Sub
Sub DataArival(curUser, sCurData)
Dim sTheText, lPos
Dim sUsrName
Dim sFind, sTmpMsg
If Left(sCurdata, 1) = "<" Or _
Left(sCurData, 5 + Len(sBotName)) = "$To: " & sBotName Then
lPos = InStr(1, sCurData, ">")
sTheText = Mid(sCurData, lPos + 2)
sUsrName = CStr(curUser.sName)
If Left(sTheText, 9) = "watchuser" Then
sFind = Mid(sTheText, 11)
If Not colUsers.Online(CStr(sFind)) Then
If oUW.Exists(sFind) Then
oUW(sFind) = oUW(sFind) & ":" & sUsrName
Else
oUW(sFind) = sUsrName
End If
curUser.PrivateMessage CStr(sBotName), _
Replace(sAddUserMsg, "$name", sFind)
Else
curUser.PrivateMessage CStr(sBotName), CStr(sUserOnline)
End If
ElseIf Left(sTheText, 9) = "watchfile" Then
sFind = Mid(sTheText, 11)
If oFW.Exists(sFind) Then
oFW(sFind) = oFW(sFind) & ":" & sUsrName
Else
oFW(sFind) = sUsrName
End If
curUser.PrivateMessage CStr(sBotName), _
Replace(sAddFileMsg, "$file", sFind)
frmHub.DoEventsForMe
Call TimerMethod
ElseIf sTheText = "watchreset" Then
For Each sFind In oUW.Keys
oUW(sFind) = Replace(oUW(sFind), ":" & sUsrName, "")
If oUW(sFind) = sUsrName Then oUW.Remove(sFind)
Next
For Each sFind In oFW.Keys
oFW(sFind) = Replace(oFW(sFind), ":" & sUsrName, "")
If oFW(sFind) = sUsrName Then oFW.Remove(sFind)
Next
curUser.PrivateMessage CStr(sBotName), CStr(sResetMsg)
ElseIf sTheText = "watchdump" Then
For Each sFind In oUW.Keys
curUser.PrivateMessage CStr(sBotName), _
sFind & " (" & oUW(sFind) & ")"
frmHub.DoEventsForMe
Next
For Each sFind In oFW.Keys
curUser.PrivateMessage CStr(sBotName), _
sFind & " (" & oFW(sFind) & ")"
frmHub.DoEventsForMe
Next
ElseIf Left(sTheText, 7) = "watchip" Then
If curUser.bOperator Then
Dim oUser
sTheText = Mid(sTheText, InStr(1, sTheText, " ") + 1)
For Each oUser In colUsers
If oUser.IP = CStr(sTheText) Then
curUser.PrivateMessage CStr(sBotName), CStr(sTheText) & " is already connected as " & curUser.sName
Exit Sub
End If
Next
If oIW.Exists(sTheText) Then oIW(sTheText) = oIW(sTheText) & ":" & CStr(sTheText) Else oIW.Add CStr(sTheText), curUser.sName
curUser.PrivateMessage CStr(sBotName), "Watching for the ip : " & CStr(sTheText)
End If
End If
ElseIf Left(sCurData, 3) = "$SR" Then 'incoming search result
If Right(sCurData, Len(sBotName)) = CStr(sBotName) Then
lPos = InStr(5, sCurData, " ")
sWhatUser = Mid(sCurData, 5, lPos - 5)
For Each sFind In oFW.Keys
If InStr(1, LCase(sCurData), LCase(sFind)) > 0 Then
sTmpMsg = Replace(sFileMsg, "$file", sFind)
sTmpMsg = Replace(sTmpMsg, "$usr", sWhatUser)
Call NotifyUsers(oFW(sFind), sTmpMsg)
Call oFW.Remove(sFind)
End If
Next
End If
End If
End Sub
Sub NewUserConnected(curUser)
Dim sUsrName
sUsrName = CStr(curUser.sName)
If oUW.Exists(sUsrName) Then
Call NotifyUsers(oUW(sUsrName), Replace(sUserMsg, "$name", sUsrName))
Call oUW.Remove(sUsrName)
End If
sUsrName = curUser.IP
If oIW.Exists(sUsrName) Then
Call NotifyUsers(oUW(sUsrName), "IP : " & CStr(sUsrName) & " has connected as " & curUser.sName)
Call oIW.Remove(sUsrName)
End If
If curUser.bOperator Then curUser.PrivateMessage CStr(sBotName), CStr(sWelcomeMessage) & vbCrLf & " watchip <ip>" & vbTab & vbTab & " - watches for an ip to connect" & vbCrLf _
Else curUser.PrivateMessage CStr(sBotName), CStr(sWelcomeMsg)
End Sub
Sub OpConnected(curUser)
Call NewUserConnected(curUser)
End Sub
Sub NotifyUsers(sUserList, sMsg)
Dim aNicks, sNick
Dim tmpUser
aNicks = Split(sUserList, ":")
For Each sNick In aNicks
If colUsers.Online(CStr(sNick)) Then
Set tmpUser = colUsers.ItemByName(CStr(sNick))
tmpUser.PrivateMessage CStr(sBotName), CStr(sMsg)
frmHub.DoEventsForMe
End If
Next
End Sub
Sub tmrScriptTimer_Timer()
lCountDown = lCountDown - 1
If lCountDown = 0 Then
Call TimerMethod
lCountDown = lInterval
End If
End Sub