• Welcome to Valhalla Legends Archive.
 

Simple Banning

Started by BorT, March 03, 2004, 09:30 PM

Previous topic - Next topic

BorT

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

Lenny

You react to the "!b Bort Sucker!" by sending "/ban" + Username + " Sucker!"
The Bovine Revolution
Something unimportant

Live Battle.net:

WARNING: The preceding message may have contained content unsuitable for young children.

Eli_1

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

BorT

Thanks Eli, and Lenny.

MyndFyre

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

BorT

#5
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?

Eli_1

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!$~"

hismajesty

Subtract 3 chars:
1 char = !
1 char = b
1 char = space

Eric

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.

ChR0NiC

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

Eric

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

Kp

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!