Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: pileofcrap on February 27, 2003, 07:01 PM

Title: command help
Post by: pileofcrap on February 27, 2003, 07:01 PM
Hey can someone GET MY STARTED (thats all) on exactly how to execute and create commands?
Title: Re: command help
Post by: ILurker on February 27, 2003, 07:10 PM
Private Sub CleanSlateBot1_UserTalk(ByVal username As String, ByVal flags As Long, ByVal message As String, ByVal Ping As Long, SimulatedEvent As Boolean)

If username = setupform.botmaster.text then
  If message = setupform.bottrigger.text & "CommandHere" then
     cleanslatebot1.send "Command Action"
  end if
end if
5 represents the number of characters in the command, including the trigger, and space after the command. So it basically represents that there is 5 characters in the command. "!SAY "
  If Left((LCase(message)), 5) = (setupform.bottrigger.text & "say") Then
    dim saymessage as string
    saymessage = Right(message, (Len(message) - 5))
    cleanslatebot1.send saymessage
   end if

There's two good examples of commands ;)
Title: Re: command help
Post by: pileofcrap on February 27, 2003, 07:19 PM
WOW..... i was competly off..... thanx man ...i knew i loved these forums for a reason ;)
Title: Re: command help
Post by: Banana fanna fo fanna on February 28, 2003, 01:05 PM
Easier if you do this:

dim trigger as string 'bot trigger

public sub onTextReceived(user as string, text as string)
Dim cmd as string
Dim args as string

cmd = left(text,instr(text," ")-1) 'get the first word
args = right(text, len(text) - instr(text," ") - 1) 'get the rest of the line

if left(text,len(trigger)) <> lcase(trigger) then exit sub 'if it doesn't start with the trigger, quit
text = right(len(text)-len(trigger))

select case cmd
case "say"
doSayCommand user, args
end select
end sub

sub doSayCommand(user as string, args as string)
botsay " " & user & " says " & chr(34) & args & chr(34)
end sub
Title: Re: command help
Post by: pileofcrap on February 28, 2003, 01:49 PM
Ok kickass ........ they both make sense. How do I make commands that, like, read profiles, ping and shit like that? can I take the examples you guys have given me and implement them into what I need?
Title: Re: command help
Post by: Banana fanna fo fanna on February 28, 2003, 02:52 PM
Yeah, see the Select Case cmd? Add a Case for the command word, then call the subroutine. In the subroutine, put all the code you should execute for that command.
Title: Re: command help
Post by: pileofcrap on February 28, 2003, 05:44 PM
OHHHHHHHHH OK I GET IT NOW =D
Title: Re: command help
Post by: Fr0z3N on March 09, 2003, 10:02 AM
If username = setupform.botmaster.text then
  If message = setupform.bottrigger.text & "master" then
     cleanslatebot1.send setupform.botmaster.text
  end if
end if

If username = setupform.botmaster.text then
  If message = "?trigger" then
     cleanslatebot1.send setupform.bottrigger.text
  end if
end if

keke
very common commands brought to you by Fr0z3N who is to lazy to login  ::)
Title: Re: command help
Post by: tA-Kane on March 09, 2003, 12:25 PM
Can we autolock old topics ???
Title: Re: command help
Post by: Camel on March 09, 2003, 12:27 PM
QuoteIf username = setupform.botmaster.text then
  If message = setupform.bottrigger.text & "master" then
     cleanslatebot1.send setupform.botmaster.text
  end if
end if

If username = setupform.botmaster.text then
  If message = "?trigger" then
     cleanslatebot1.send setupform.bottrigger.text
  end if
end if

keke
very common commands brought to you by Fr0z3N who is to lazy to login  ::)
why check if it's the bot's master twice?
Title: Re: command help
Post by: pile@school on March 10, 2003, 02:09 PM
I was thinking the same thing. It wouldmake sense to check if they were in different moduals, but in your code it isnt.
Title: Re: command help
Post by: tA-Kane on March 11, 2003, 05:26 AM
QuoteIt wouldmake sense to check if they were in different moduals, but in your code it isnt.
Better said...
QuoteIt would make sense to check for the master if they were in different modules. But in your code, it doesn't appear to be.
Title: Re: command help
Post by: Grok on March 11, 2003, 06:58 AM
I'd suggest a function that verifies someone has the authority to perform a command.
Public Sub ProcessSingleCommand(ByVal Command As ENUM_COMMANDS, ByVal Performer As String)
    If IsPermitted(Command, Performer) = False Then Exit Sub
    'do whatever it is
    Select Case Command
    Case CMD_BAN:
        'do ban
    Case CMD_KICK
        'do kick
    Case CMD_WHATEVER
        'do whatever
    End Select
End Sub

Public Function IsPermitted(ByVal Command As ENUM_COMMANDS, ByVal UserName As String) As Boolean
    IsPermitted = False    'default to false
    'get user rights from database (or user level)
    'check command against user rights
    'set to true if user's permission allows this command
End Sub
Title: Re: command help
Post by: AnThRaX on March 11, 2003, 09:22 PM
QuoteI'd suggest a function that verifies someone has the authority to perform a command.

Hey Grok, I like that function, think you could do a demonstration on the "user access" stuffs? I'm kinda having some trouble with it.
Title: Re: command help
Post by: Kp on March 11, 2003, 09:48 PM
QuoteHey Grok, I like that function, think you could do a demonstration on the "user access" stuffs? I'm kinda having some trouble with it.

Its implementation is going to depend on whether you use flags-based access control or level based access control.  If you use flags control, then such a function would call a QueryUserFlags function, mask the result with the flags required for the command, and return true on nonzero or false on zero.  If you prefer a level based access, then you should look up the user's level, and return true if it meets or exceeds the level required for the command.  Storing what flag/level a command requires is both language and programmer dependent (there are several ways to do it in most languages, depending on speed/space requirements), so I'll leave that to you to decide.

Also notice that again the hard work has been passed off to an undescribed subroutine. ;)
Title: Re: command help
Post by: AnThRaX on March 11, 2003, 10:20 PM
Well I am definetly going to be using a flags system, access levels with numbers from 1-100 kinda suck in my opinion but anyways, thanks for the info and everyone else feel free to add to what Kp said or give some other ideas!
Title: Re: command help
Post by: Grok on March 12, 2003, 11:27 AM
QuoteHey Grok, I like that function, think you could do a demonstration on the "user access" stuffs? I'm kinda having some trouble with it.

QuoteAlso notice that again the hard work has been passed off to an undescribed subroutine. ;)

Very undescribed.  My purpose was to suggest a clean and layered way to handle permissions checking.  Too often I see code (including in this thread) where large if-then or select-case structures exist for comparing commands to access levels or flags.

My way offloads the labor into a function which can end up looking very pretty if done right, and would be implementation-specific.  Someone else could simply replace IsPermitted() function with a new implementation, and just drop it into the bot.
Title: Re: command help
Post by: Kp on March 12, 2003, 11:39 AM
QuoteVery undescribed.  My purpose was to suggest a clean and layered way to handle permissions checking.  Too often I see code (including in this thread) where large if-then or select-case structures exist for comparing commands to access levels or flags.

My way offloads the labor into a function which can end up looking very pretty if done right, and would be implementation-specific.  Someone else could simply replace IsPermitted() function with a new implementation, and just drop it into the bot.
It's still entirely possible for this subroutine to be very clean.  My preferred implementation would be to have an array of bitmasks, indexed by the command's ID.  If the bitmask logical ANDed with the user's current flags yields nonzero, the command is permitted.  Nicely compact, and quite clean.
Title: Re: command help
Post by: AnThRaX on March 12, 2003, 12:38 PM
Alright, I think I understand now, I'll try some stuff and see if I can get it to work. If I do, I'll post code to a fully working "commands" function with reading accesses and such if it's ok with the creators/writers of the above codes. Thanks guys!

Also, I'm wanting some tests done on my bot for stability and such... If anyone here can do that for me and check for bad coding (not source code but just simple errors in the program) then please contact me at [email protected] Thanks again!
Title: Re: command help
Post by: pile@school on March 12, 2003, 01:02 PM
Im not going to use the 1-100 thing. I would prefer Character not Numeral system. I guess like Ultimate Bot.
Title: Re: command help
Post by: Grok on March 12, 2003, 05:23 PM
QuoteAlright, I think I understand now, I'll try some stuff and see if I can get it to work. If I do, I'll post code to a fully working "commands" function with reading accesses and such if it's ok with the creators/writers of the above codes. Thanks guys!

Of course it's OK.  Any source code posted on this forum is admitted into public domain by EULA.