I did a search and didn't really see anything come up so I figured I'd just ask. I'm trying to implement phrase banning into my bot but it's banning when it sees either 1) one word from the phrase is only needed instead of the whole phrase 2) Lately it's been banning whenever somebody talks.
Here is my code (Visual Basic):
Form_Load
Dim newline As String
Open App.Path & "\PhraseBans.txt" For Append As #2
Close #2
Open App.Path & "\PhraseBans.txt" For Input As #2
Do While Not EOF(2)
Line Input #2, newline
lstPhraseBans.AddItem (newline)
Loop
Close #2
The command:
Case "pban"
Select Case LCase(s(1))
Case "on"
pban = True
Send "/w " & username & " Phrase Bans Enabled."
Case "off"
pban = False
Send "/w " & username & " Phrase Bans Disabled."
Case "list"
Send "/w " & username & " Current PhraseBans Are:"
Dim newpban As String
Open App.Path & "\PhraseBans.txt" For Input As #4
DoEvents
Do
DoEvents
Line Input #4, newpban
DoEvents
Send "/w " & username & " " & newpban
Loop Until EOF(4)
Send "/w " & username & " End Of PhraseBans."
Case "status"
If pban = True Then
Send "/w " & username & " Phrase Ban Status: On"
Else
Send "/w " & username & " Phrase Ban Status: Off"
End If
Case "add"
Open App.Path & "\PhraseBans.txt" For Output As #1
Print #1, s(2)
frmMain.lstPhraseBans.AddItem s(2)
Send "/w " & username & " PhraseBan " & s(2) & " Successfully Added."
Close #1
Case "rem"
Dim zb As Integer
For zb = 0 To frmMain.lstPhraseBans.ListCount
If frmMain.lstPhraseBans.List(zb) = s(2) Then
frmMain.lstPhraseBans.RemoveItem (zb)
End If
Next zb
Kill App.Path & "\PhraseBans.txt"
Open App.Path & "\PhraseBans.txt" For Append As #2
Close #2
Open App.Path & "\PhraseBans.txt" For Output As #2
Dim zbc As Integer
For zbc = 0 To frmMain.lstPhraseBans.ListCount
Print #2, frmMain.lstPhraseBans.List(zbc)
Next zbc
Send "/w " & username & " PhraseBan " & s(2) & " Successfully Removed."
Close #2
End Select
Chat Event:
If pban = True Then
If Commands.CheckPhrase(message) = True Then
Send "/ban " & username & " PhraseBan Detected"
End If
End If
The Function:
Public Function CheckPhrase(ByVal message As String) As Boolean
On Error Resume Next
Dim hax As String
Close #1
CheckPhrase = False
Open (App.Path & "\PhraseBans.txt") For Input As #1
Do
Line Input #1, hax
If InStr(1, message, hax, vbTextCompare) Then
CheckPhrase = True
Else
CheckPhrase = False
End If
Loop Until EOF(1)
Close #1
End Function
Any help is appreciated
Quote
1) one word from the phrase is only needed instead of the whole phrase
I can only guess that the variable "message"
was changed before reaching CheckPhrase().
Quote
2) Lately it's been banning whenever somebody talks
You need to setup a check
so it won't process "hax" if "hax" is empty.
That might not be the cause but..
better safe then sorry.
Your function should exit the loop/function
when a match is found.
I think
If instr(phrase, message) then
'do stuff
end if
will work just fine for you.
Just place this in where you are checking you're phrase list.
If InStr(1, Message, Phrase) <> 0 Then
'Do Stuff
End If
Mine works, it should just be
message,phrase
Would be easier/more efficient to use the Like operator.
Quote from: LoRd[nK] on February 29, 2004, 01:27 PM
Would be easier/more efficient to use the Like operator.
Idk about that... The Like operator is pretty tough for some people (n3wbs) on this forum....
Quote from: Myndfyre on February 29, 2004, 01:45 PM
Quote from: LoRd[nK] on February 29, 2004, 01:27 PM
Would be easier/more efficient to use the Like operator.
Idk about that... The Like operator is pretty tough for some people (n3wbs) on this forum....
MsgBox "hrm" Like "*s"
MsgBox "hrm" Like "*m"
Note: There's other possibilities other than *, I don't know them all, so google it.
It returns either True or False.
Doesn't seem that difficult.
MsgBox "T3T" Like "T?T" '? For Single characters
MsgBox "T3T" Like "T#T" '# For Single Digits
MsgBox "T%T" Like "T[%]T" 'Special Characters
I think there is a way to get a range of characters but im not sure.
Quote from: CrAz3D on February 29, 2004, 10:22 AM
I think
If instr(phrase, message) then
'do stuff
end if
will work just fine for you.
Just place this in where you are checking you're phrase list.
He uses vbTextCompare so the comparison wouldn't be case sensitive.
If InStrB(1, message, hax, vbTextCompare) Then