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.

proc under proc problems - dubble logs

Help for those learning Tcl or writing their own scripts.
Post Reply
T
Thib
Voice
Posts: 9
Joined: Mon Jan 11, 2010 11:45 am

proc under proc problems - dubble logs

Post by Thib »

Hellow,

I'm creating my own script, i have 2 questions.

When an user comes, he's noticed by the bot called Eva. When he "/notice botnick confirm", he's noticed by Eva, and kicked after 5 secs.

here is my code :

Code: Select all

set salon "#channel"
bind notc - * notc:confirm
proc notc:confirm { nick uhost handle text {dest "Eva"} } {
        global salon
        if {$text == "confirm"} {
                putserv "NOTICE $nick :Vous avez maintenant confirmé"
                pushmode $salon +v $nick
                putlog "$nick - $uhost à confirmé"
                utimer 5 { proc_kick }
        }

        proc proc_kick {} {
                global salon
                putkick $salon $nick "test"
        }
}
first question, when i hit /notice botnick confirm, i can seen two times the confirmation in partyline :
(16:44:24) (Eva) [16:43] aaa - a@hide-D4B501FE.unknown.uunet.be à confirmé
(16:44:25) (Eva) [16:43] aaa - a@hide-D4B501FE.unknown.uunet.be à confirmé
(16:44:25) (Eva) [16:43] -aaa (a@hide-D4B501FE.unknown.uunet.be)- confirm
Why ? Same problem for the timer, two timers are started .. ?
Why is all cloned ?

--

Second question, is concerning the proc_kick.
I want it to start after 5 secs, it works. But the user isnt kicked !
What do i have to insert here :
proc proc_kick {} {
to catch the nick again ?

Thank you for your answers :)

Thib
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off,
I'd recommend that you don't create the proc_kick proc from within the notc:confirm proc. I take it you are accustomed with Java classes (especially events)? Unfortunately, tcl does not work that way - the proc_kick proc will be created at a global level, not within any notc:confirm proc/"object".

Secondly, this is partly due to the first part;
Variable scope. $nick is not available within proc_kick, as it is not defined as a variable within proc_kick's namespace. What you'll need to do, is add a parameter for your proc_kick:

Code: Select all

proc proc_kick {nickname} {
  global salon
  putkick $salon $nickname "test"
}
Next, you'll have to provide the nickname as an argument when calling the proc. In a trivial case, you'd simply do proc_kick $nick, but since you use utimer things get alittle more complicated. To avoid double evaluations and possible exploits, you'll need to do it like this:

Code: Select all

  utimer 5 [list proc_kick $nick]
Much simplified, we use the list command to build a proper command line that can be executed safely when the timer expires.

Third, as for the multiple triggers, most likely you've loaded the script twice, generating 2 bindings (using .rehash will not wipe the current tcl environment, and any already existing bindings will remain).

All in all, I'd write the script something like this:

Code: Select all

#Fancy tweak to see if the binding has already been created, just in case of a .rehash
if {[lsearch -glob -- [binds notc] "* notc:confirm"] == -1} {
 bind notc - * notc:confirm
}

proc notc:confirm { nick uhost handle text {dest "Eva"} } {
 global salon
 if {$text == "confirm"} {
  putserv "NOTICE $nick :Vous avez maintenant confirmé"
  pushmode $salon +v $nick
  putlog "$nick - $uhost à confirmé"
  utimer 5 [list proc_kick $nick]
 }
}

proc proc_kick {nickname} {
 global salon
 if {[onchan $nickname $salon]} {
  putkick $salon $nickname "test"
 }
}
NML_375
T
Thib
Voice
Posts: 9
Joined: Mon Jan 11, 2010 11:45 am

Post by Thib »

It works, thanks :)

Other question : when my egg joins, he's noticed by itself .. because of the join.. ( i also have a bind join in my code )

How can i avoid it ?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

For that, I'd suggest you test the nickname of the "joiner" using the "isbotnick" command:

Code: Select all

proc myjoin {nick host handle channel} {
  if {[isbotnick $nick]} {
    return
  }
  ... rest goes here ...
}
NML_375
T
Thib
Voice
Posts: 9
Joined: Mon Jan 11, 2010 11:45 am

Post by Thib »

thank you !

another problem :

Code: Select all

proc proc_kick {nick uhost} {
        global salon
                if {[isvoice $nick $salon]} {
                  putserv "NOTICE $nick :Bon tchat !"
                } else {
                  newchanban $salon $uhost Eva "test test" 120
                }
}
(10:12:56) (Eva) [10:12] wrong # args: should be "proc_kick nick uhost"
If i only " proc proc_kick {nick}", i'm told "$uhost no suhc variable" what is normal.
But where the hell is my mistake ? :evil:
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If you add a second parameter to your proc declaration, then you must remember to provide the appropriate argument when calling the proc
NML_375
T
Thib
Voice
Posts: 9
Joined: Mon Jan 11, 2010 11:45 am

Post by Thib »

thanks :D
Post Reply