This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

User Interaction example

Help for those learning Tcl or writing their own scripts.
Post Reply
t
terryd
Voice
Posts: 5
Joined: Tue Dec 27, 2005 6:16 pm

User Interaction example

Post by terryd »

I have been looking for an example of catching user input.
For example it !test
what is your name
The user replies joe
How to catch that reply which i could then write to a file or what ever.
Just and example or a pointer would be most helpfull

Cheers Terry.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

generally, you catch user's output via [bind pubm] on channel or [bind msgm] on private

if you need to track the response of a particular user on a particular question, you need to implement a mechanism for associating user's nick with his/her response; the obvious and natural way of doing that is using Tcl associative array:

Code: Select all

bind pubm - * getname
bind pub - !ask askname
proc askname {n u h c t} {
   putserv "privmsg $c :$t, what's your name?"
   set n [string tolower $t]
   set ::name($n) asked
}
proc getname {n u h c t} {
   set n [string tolower $n]
   if [info exists ::name($n)] {
      puthelp "privmsg $c :$n's name is $t"
      unset ::name($n)
   }
}
so, when you type !ask goober, the bot will output "goober, what's your name?", then upon first response from goober the bot will react with "goober's name is <response>"
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

I also have a question about some interaction with user but on party-line. How to force bot o leave party-line for some time and create a diffrent "channel" only with that one user.

For example:
user type a command, let it be ".register". Bot ask him directly "your username". User type what he want. Then bot ask him for "serial number", and again user type something. Then bot check if everything is OK, send proper reply and finish whole procedure.

I know that i can do it like this: ".register username serial" but i want some interaction ;)
Que?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

well, on the party line it's even easier since you have dedicated communication channel with that user which you access by its DCC sock index

of course, before proceeding with any interactive action, you need to seize control of that index by using [control], in order to be able to capture user's input
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Could you post some example?
Que?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

set idx [hand2idx goober]
putdcc $idx "Username:"
control $idx foo
proc foo {idx text} {
   if ![info exists ::response(username)] {
      set ::response(username) $text
      putdcc $idx "Authorization code:"
   } {
      set ::response(authcode) $text
      return 1 ;# yield control to eggdrop
   }
}
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply