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.

booleans with TCL?

Help for those learning Tcl or writing their own scripts.
Post Reply
r
reddy
Voice
Posts: 5
Joined: Sun Nov 26, 2006 11:56 am

booleans with TCL?

Post by reddy »

i have a message forwarding script, so when someone pm's my bot it does xxx. Im getting other bots pming my bot and spamming crap into my selected channel to which the private messages get sent :|

How can i use booleans with TCL?

As in

Declare Forward as a variable.

if (forward == true) send stuff to my channel
if (forward == false) dont send stuff to my channel?

Heres the code that needs to contain the trigger for the bool
bind pub - !dothis pub_dothis
proc pub_dothis {nick host hand chan lang text} {
SET BOOLEAN TO TRUE
putserv "PRIVMSG #mychannel : say something lalalalal"
}

heres the forward script, how can i convert this to switch on and off?

I run
bind msgm - "*" proc:laina

set chan "#myprivatechannel"
proc proc:laina {nick uhost hand arg} {
global chan
set line [string trim $arg]
if {$nick == "SeenServ"} {
puthelp "privmsg $chan :SeenServ returned: $line"
return 0
}

puthelp "PRIVMSG $chan :\0034 \002$nick : $line\002 ::\0032 /msg $nick"
puthelp "PRIVMSG $nick : Your message is logged, ill get back to you in a minute"
}
return 0
My ultimate goal would be to have both of those scripts contained within the same TCL file, can anyone help?

Cheers!

reddy
r
reddy
Voice
Posts: 5
Joined: Sun Nov 26, 2006 11:56 am

Post by reddy »

This compiles, but it doesnt work. can anyone help? please?
global var
set var TRUE

bind pub - !start pub_start
proc pub_start {nick host hand chan lang text} {
global var
set var TRUE
putserv "PRIVMSG #channel : FORWARD TURNED ON"
}

bind pub - !stop pub_stop
proc pub_stop {nick host hand chan lang text} {
global var
set var FALSE
putserv "PRIVMSG #channel : FORWARD TURNED OFF"
}


#########################

if {$var} {
bind msgm - "*" proc:laina
set chan "#channel"
proc proc:laina {nick uhost hand arg} {
global chan
set line [string trim $arg]
if {$nick == "SeenServ"} {
puthelp "privmsg $chan :SeenServ returned: $line"
return 0
}
puthelp "PRIVMSG $chan :\0034 \002$nick : $line\002 ::\0032 /msg $nick"
puthelp "PRIVMSG $nick :hey, Im the manager bot! Your message is logged, a member may, or may not contact you with a reply to your query. Thanks!"
}
}

if {!$var} {
putserv "PRIVMSG #channel : GO AWAY!"
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First of all, tcl does'nt compile..
As for the proc command, it only cares that it is given three arguments ("name", "header", and "body", where header is a list of arguments for the created proc and body it's contents). No parsing or checking other than the normal expansions is performed.

To find out wether there's any syntactical error within your proc, you'll have to make sure that part of the proc is executed once the proc itself has been defined.

Also, the idea behind your code is flawed. It seems you assume the whole script will be run every time you issue a command; that is not true. The script will only be evaluated when it's loaded with "script path/to/file". You'll have to check the value of your "var" inside any proc that uses it as a conditional, trying to put proc definitions within such a conditional would only affect wether that proc is (re)defined when the script is evaluated (usually only when your bot is (re)started or rehashed).

You probably want something like this:

Code: Select all

set cond true
bind msgm - * myproc
proc myproc {nick host hand text} {
 global cond
 if {$cond} {
  puthelp "PRIVMSG $nick :Message sent"
  ...
 }
}
NML_375
Post Reply