Valhalla Legends Forums Archive | Battle.net Bot Development References | Adding Phrase Bans

AuthorMessageTime
Sonic
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
[code]
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
[/code]

The command:
[code] 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[/code]

Chat Event:
[code] If pban = True Then
If Commands.CheckPhrase(message) = True Then
Send "/ban " & username & " PhraseBan Detected"
End If
End If[/code]

The Function:
[code]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[/code]

Any help is appreciated
February 29, 2004, 12:27 PM
o.OV
[quote]
1) one word from the phrase is only needed instead of the whole phrase
[/quote]
I can only guess that the variable "message"
was changed before reaching CheckPhrase().

[quote]
2) Lately it's been banning whenever somebody talks
[/quote]
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.
February 29, 2004, 2:03 PM
CrAz3D
I think
[code]
If instr(phrase, message) then
'do stuff
end if
[/code]
will work just fine for you.

Just place this in where you are checking you're phrase list.
February 29, 2004, 4:22 PM
Lobo.id
[code]
If InStr(1, Message, Phrase) <> 0 Then
'Do Stuff
End If
[/code]

February 29, 2004, 6:40 PM
CrAz3D
Mine works, it should just be

message,phrase
February 29, 2004, 7:17 PM
LoRd
Would be easier/more efficient to use the Like operator.
February 29, 2004, 7:27 PM
Myndfyr
[quote author=LoRd[nK] link=board=17;threadid=5508;start=0#msg46736 date=1078082821]
Would be easier/more efficient to use the Like operator.
[/quote]

Idk about that... The Like operator is pretty tough for some people (n3wbs) on this forum....
February 29, 2004, 7:45 PM
LoRd
[quote author=Myndfyre link=board=17;threadid=5508;start=0#msg46745 date=1078083906]
[quote author=LoRd[nK] link=board=17;threadid=5508;start=0#msg46736 date=1078082821]
Would be easier/more efficient to use the Like operator.
[/quote]

Idk about that... The Like operator is pretty tough for some people (n3wbs) on this forum....
[/quote]

[code]
MsgBox "hrm" Like "*s"
MsgBox "hrm" Like "*m"

Note: There's other possibilities other than *, I don't know them all, so google it.
[/code]

It returns either True or False.
Doesn't seem that difficult.
February 29, 2004, 7:49 PM
Lobo.id
[code]
MsgBox "T3T" Like "T?T" '? For Single characters
MsgBox "T3T" Like "T#T" '# For Single Digits
MsgBox "T%T" Like "T[%]T" 'Special Characters
[/code]
I think there is a way to get a range of characters but im not sure.
February 29, 2004, 8:19 PM
o.OV
[quote author=CrAz3D link=board=17;threadid=5508;start=0#msg46707 date=1078071724]
I think
[code]
If instr(phrase, message) then
'do stuff
end if
[/code]
will work just fine for you.

Just place this in where you are checking you're phrase list.
[/quote]

He uses vbTextCompare so the comparison wouldn't be case sensitive.

[code]
If InStrB(1, message, hax, vbTextCompare) Then
[/code]
February 29, 2004, 10:46 PM

Search