• Welcome to Valhalla Legends Archive.
 

Adding Phrase Bans

Started by Sonic, February 29, 2004, 06:27 AM

Previous topic - Next topic

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

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

o.OV

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.
If the facts don't fit the theory, change the facts. - Albert Einstein

CrAz3D

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.
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Lobo

#3

If InStr(1, Message, Phrase) <> 0 Then
   'Do Stuff
End If


Look it's a signature.

CrAz3D

Mine works, it should just be

message,phrase
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Eric

#5
Would be easier/more efficient to use the Like operator.

MyndFyre

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....
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Eric

#7
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.

Lobo

#8

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.
Look it's a signature.

o.OV

#9
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
If the facts don't fit the theory, change the facts. - Albert Einstein