Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: BorT on March 03, 2004, 09:30 PM

Title: Simple Banning
Post by: BorT on March 03, 2004, 09:30 PM
How would I ban a User?

Ex: the user types !b Bort Sucker!
How would I make that ban Bort and post the message "Sucker!" after?

Thanks agian,
Bort
Title: Re:Simple Banning
Post by: Lenny on March 03, 2004, 09:33 PM
You react to the "!b Bort Sucker!" by sending "/ban" + Username + " Sucker!"
Title: Re:Simple Banning
Post by: Eli_1 on March 03, 2004, 09:44 PM
Quote
You react to the "!b Bort Sucker!" by sending "/ban" + Username + " Sucker!"

well, in the most simple way I can think...

if left(lcase(message), 3) = trigger & "b " and len(message) > 3 then
     CSB.send "/ban " & right(message, len(message) - 3)
end if
Title: Re:Simple Banning
Post by: BorT on March 04, 2004, 06:21 PM
Thanks Eli, and Lenny.
Title: Re:Simple Banning
Post by: MyndFyre on March 04, 2004, 07:45 PM
Quote from: BorT on March 04, 2004, 06:21 PM
Thanks Eli, and Lenny.

Do you know why Eli's code works how it does?


if left(lcase(message), 3) = trigger & "b " and len(message) > 3 then
     CSB.send "/ban " & right(message, len(message) - 3)
end if


Break it down expression by expression:

lcase(string) returns the lowercase version of the expression.  If it was !B, then the expression would be !b.

left(string, integer) returns at most integer number of characters of string from the left side of the string.  So if your string message is:
"!b Bort Sucker!"
then left("!b Bort Sucker!", 3) would return "!b ".

Combining the left and lcase functions (or are the operators?  I'm not a VB programmer; I know they turn blue, but w/e), your example expression becomes:

left(lcase("!b Bort Sucker!", 3))

which returns "!b ".

Assuming "trigger" is defined elsewhere as "!". your left Boolean expression returns true; "!b " equals "!" & "b ".

The right Boolean expresion, len(message) > 3, uses the Len (Length) operator.  Len(string) returns an integer telling you how long the string is.  The reason you want to do this is, in case you have a malformed command, such as:

!b

the bot doesn't respond.  When it's greater than 3, the bot uses the conditional statements (see below).

The right(string, integer) function does the same as left, except taking the text from the right side of the string.  The conditional statement, then, CSB.send (...) should be pretty easy to understand then.
Title: Re:Simple Banning
Post by: BorT on March 04, 2004, 09:09 PM
Thanks for the Sum up Myndfyre!
Just to clear one thing up:

if left(lcase(message), 3) = trigger & "b " and len(message) > 4 then
     CSB.send "/ban " & right(message, len(message) - 4)
end if

If the code were like that, then it wouldnt ban, correct?
Title: Re:Simple Banning
Post by: Eli_1 on March 04, 2004, 09:54 PM
Quote from: BorT on March 04, 2004, 09:09 PM
Thanks for the Sum up Myndfyre!
Just to clear one thing up:

if left(lcase(message), 3) = trigger & "b " and len(message) > 4 then
     CSB.send "/ban " & right(message, len(message) - 4)
end if

If the code were like that, then it wouldnt ban, correct?
well, it would ATTEMPT to ban, only to recieve 'That user is not logged on' from bnet

because: message = "!b BorT bwahahah-Hax)or!$~"

right(message, len(message) - 4)


that would remove the left 4 most characters from the string
causing you to send "orT bwahahahah-Hax)or!$~"
Title: Re:Simple Banning
Post by: hismajesty on March 05, 2004, 02:16 PM
Subtract 3 chars:
1 char = !
1 char = b
1 char = space
Title: Re:Simple Banning
Post by: Eric on March 05, 2004, 02:21 PM
Quote from: hismajesty on March 05, 2004, 02:16 PM
Subtract 3 chars:
1 char = !
1 char = b
1 char = space

Personally, I find it best to store the trigger as a dynamic variable, then take the length of the variable and subtract it from the message. That way you can change the trigger later on and it's not restricted to one character.
Title: Re:Simple Banning
Post by: ChR0NiC on March 05, 2004, 06:14 PM
Quote from: hismajesty on March 05, 2004, 02:16 PM
Subtract 3 chars:
1 char = !
1 char = b
1 char = space

Quote from: LoRd[nK] on March 05, 2004, 02:21 PM
Personally, I find it best to store the trigger as a dynamic variable, then take the length of the variable and subtract it from the message. That way you can change the trigger later on and it's not restricted to one character.

I find that quite annoying actually, when you got little immature punks saying
queersay LOL
<Operator'sName> LOL
Title: Re:Simple Banning
Post by: Eric on March 05, 2004, 06:49 PM
Quote from: ChR0NiC on March 05, 2004, 06:14 PM
Quote from: hismajesty on March 05, 2004, 02:16 PM
Subtract 3 chars:
1 char = !
1 char = b
1 char = space

Quote from: LoRd[nK] on March 05, 2004, 02:21 PM
Personally, I find it best to store the trigger as a dynamic variable, then take the length of the variable and subtract it from the message. That way you can change the trigger later on and it's not restricted to one character.

I find that quite annoying actually, when you got little immature punks saying
queersay LOL
<Operator'sName> LOL

Shouldn't allow immature people to control your bot.

The trigger allows you to give each bot it's own tag, for instance: Op1 say hi, Op2 say hi, Op3 say hi, LoRd[nK]#2: say hi
Title: Re:Simple Banning
Post by: Kp on March 05, 2004, 07:33 PM
As an extension to this idea that I've had implemented for a very long time, consider having the bot respond to its own name as a trigger (possibly with additional characters).  In such a situation, multiple bots on the same configuration profile will each have a unique trigger since the trigger is derived in part from the bot's logon name, which the server guarantees unique.