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.

Tcl scripting help

Old posts that have not been replied to for several years.
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Tcl scripting help

Post by the_crow »

Hello all :)
Im learning tcl scripting, but i have some problems :) .
Im trying to make a input in a local variable, just a exemple:

In pvt with bot i put:
- free me

and the bot keeps that in a local variable like $test

but i don't know how :(.
Can anyone explain to me how to make ?!!?!?
Thks :)
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

You must be a bot master or the bot owner for this to work.
In the pvt of the bot, you type - free me and the bot will store the value "free me" in the local variable test

Code: Select all

bind msg m "-" mypvtcommand

proc mypvtcommand {nick host hand arg} {
   if {$arg == ""} { 
      putserv "PRIVMSG $nick :You must enter a command"
   } else {
     set test $arg
  }
}
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

again me

Post by the_crow »

Hi.
Thks by that, but it wasn't what i want to learn :)

imagine this.
i put a trigger in a channel, like !teste, and then the bot, enter contact with me by pvt like this:

<Bot> Put a name:

then i put a name

<me> teste

Then the bot keeps the text "teste" in the variable test :)

Can you explain me this!!?!?
Thks :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: again me

Post by user »

the_crow wrote:i put a trigger in a channel, like !teste, and then the bot, enter contact with me by pvt like this:

<Bot> Put a name:

then i put a name

<me> teste

Then the bot keeps the text "teste" in the variable test :)
You mean GLOBAL variable, right? To catch the reply use a msgm bind. If you need to make sure the message you get is from the user typing the trigger you could store the nick and/or uhost of the person typing the trigger some where and check for the existance of a matching value in the proc triggered by the msgm bind.


eg:

Code: Select all

bind pub - !trigger trigged
bind msgm - * input

proc trigged {n u h c a} {
  global triggedBy
  set triggedBy $u
  putserv "PRIVMSG $n :Type something:"
}

proc input {n u h a} {
  global triggedBy test
  if {[info exists triggedBy]&&[string eq $triggedBy $u]} {
    set test $a
    unset triggedBy
    putserv "PRIVMSG $n :ok"
  }
}
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Again me 2 :)

Post by the_crow »

I understood :)

So if i want to put another text in other variable after the first one text insert, should i do this?!

bind pub - !trigger trigged
bind msgm - * input

proc trigged {n u h c a} {
global triggedBy
set triggedBy $u
putserv "PRIVMSG $n :Type something:"
}

proc input {n u h a} {
global triggedBy test
global triggedBy test2
if {[info exists triggedBy]&&[string eq $triggedBy $u]} {
set test $a
unset triggedBy
putserv "PRIVMSG $n :ok"
putserv "PRIVMSG $n : Insert another thing:"
set test2 $a
unset triggedBy
putserv "PRIVMSG $n : Ok again"
}
}

thks one more time :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Again me 2 :)

Post by user »

the_crow wrote:I understood :)
No you didn't...at least not entirely ;P

Try this:

Code: Select all

# some questions
set surveyQ {
	"How old are you?"
	"Where do you live?"
	"Can I come over to your place?"
}
# the binds
bind pub - !survey survey:pub
bind msgm - * survey:msgm
# start
proc survey:pub {n u h c a} { 
	global surveyQ surveyA
	set surveyA($u) {}
	putserv "PRIVMSG $n :[lindex $surveyQ 0]"
}
# fetching the answers
proc survey:msgm {n u h a} {
	global surveyQ surveyA
	if {[info exists surveyA($u)]} {
		lappend surveyA($u) $a
		if {[llength $surveyA($u)]<[llength $surveyQ]} {
			# there are more questions to be asked...
			putserv "PRIVMSG $n :[lindex $surveyQ [llength $surveyA($u)]]"
		} {
			# completed
			putserv "PRIVMSG $n :We're done. Now go away!"
			putlog "$n has completed the survey:"
			foreach q $surveyQ a $surveyA($u) {
				putlog "Q: $q"
				putlog "A: $a"
			}
			# DON'T keep surveyA($u) after completion. If you want to keep the
			# list of answers use a different variable.
			unset surveyA($u)
		}
	}
}
Was that clear? If you have questions about parts of the code, please don't re-post the entire thing, and please use the code tag to keep it readable.
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

sorry

Post by the_crow »

Sorry just respond now, i went in a trip :)

Yes, i really understood :)

But can it be possible, each question, have one variable separate, just imagine:

First question to variable Qestion1
Second question to variable Question2
Third Question to variable question3

to when i want to access the variable i make $question1, $question2 or $question3

If this possible??

Thks one more time :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

lindex $surveyA($u) <INDEX> will give you the answers by number...just set the variables from within the "completed" part. (before it's unset)
Or insert this (at the same point):

Code: Select all

global Question1 Question2 Question3
foreach {Question1 Question2 Question3} $surveyA($u) break
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

again me 3 :)

Post by the_crow »

Hello.
I have made some thing like you said.
But i cant understand one thing.
I have made the tcl to put the variable inside a file so, i made the following

Code: Select all

....
 proc survey:msgm {n u h a} { 
   global surveyQ surveyA 
   if {[info exists surveyA($u)]} { 
      lappend surveyA($u) $a 
      if {[llength $surveyA($u)]<[llength $surveyQ]} { 
         # there are more questions to be asked... 
         putserv "PRIVMSG $n :[lindex $surveyQ [llength $surveyA($u)]]" 
      } { 
         # completed
         set fp [open $n a]
         puts $fp "..."
         ....... 
         close $fp
         putserv "PRIVMSG $n: This message don't appear "
         putserv "PRIVMSG $n :We're done. Now go away!" 
         putlog "$n has completed the survey:" 
         foreach q $surveyQ a $surveyA($u) { 
            putlog "Q: $q" 
            putlog "A: $a" 
         } 
         # DON'T keep surveyA($u) after completion. If you want tokeepthe 
         # list of answers use a different variable. 
         unset surveyA($u) 
But the putserv "PRIVMSG $n: this message don't appear" the bot dont say in pvt , why can it be!??!?!

Thks one more time :)
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

I solved the problem, i made a proc, and call him, after i close the file and worked :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: again me 3 :)

Post by user »

the_crow wrote:But the putserv "PRIVMSG $n: this message don't appear" the bot dont say in pvt , why can it be!??!?!
Probably because "$n:" ain't on irc.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

and by the way

Post by user »

the_crow wrote:Yes, i really understood
No, you didn't, or you would not have asked the question you asked.
the_crow wrote:So if i want to put another text in other variable after the first one text insert, should i do this?!
set test $a
unset triggedBy
putserv "PRIVMSG $n :ok"
putserv "PRIVMSG $n : Insert another thing:"
set test2 $a
unset triggedBy
putserv "PRIVMSG $n : Ok again"
This is what happens: Each time you trigger the msgm bind, the enire body of the proc is evaluated, and it has to return before anything else (except from the code currently being executed) can happen. There's no magic pause inserted at runtime to wait for more messages to arrive, just because you send a msg to a user asking for more info. The message is sent after the proc has returned, so you'll end up storing the same answer twice and asking more info that you won't store. (because the variable that is used to identify the user is unset (see complete code in your original post))
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

:)

Post by the_crow »

I have solved all my problems thanks to you. Thank you man :)
Can i make one more question?!?!
How can i make in tcl, to eggdrop del a file, after he created the file??
Thanks
I try to use the command exec rm $file but it didn't work :|
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: :)

Post by user »

the_crow wrote:How can i make in tcl, to eggdrop del a file
http://www.tcl.tk/man/tcl8.4/TclCmd/file.htm#M12
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

i make the command like

file delete -force pathname , and the file remains in :(
Locked