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.

Call and take values from another proc

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Call and take values from another proc

Post by juanamores »

Before you add a user to the staff, the bot should check the nick has to be added is registered in the network.

I've got a process that performs verification through WHOIS to return zero (0) if the nick is not registered and one (1) if the nick is registered on the network.

I would call this second process, taking the zero (0) value or a value of one (1) to another process and the truth gives me errors, not knowing invoke the process well.

My stuff :

Code: Select all

bind pub o|o !fieladd add_fan
bind pub o|o !fieldel del_fan
bind pub o|o !djadd add_dj
bind pub o|o !djdel del_dj
bind pub o|o !adminadd add_admin
bind pub o|o !admindel del_admin
bind pub n|n !rootadd add_root
bind pub n|n !rootdel del_root

set chan_radio #radioX 
set chanl_djs #radioX-Dj
set chan_admin #radioX-admin

proc add_fan {nick uhost hand chan text} {
  global chan_radio  
  if {$text == ""} {putmsg $chan "You must enter the nick of the fan to add!";return 0}
  set fan [join [lindex [split $text] 0]]

####HERE SHOULD BoT CHECK "FAN" IF A REGISTERED NICK, isnot return if yes continue####

    putserv "PRIVMSG chan :access $chan_radio add $fan 100"
  if {![validuser $fan]} {
  adduser $fan
  chattr $fan +c
   putmsg $chan "You have added a $fan as fan radio"
  } else {
  if {![matchattr $fan +c]} { 
  chattr $fan +c 
  putmsg $chan "You have added a $fan as fan radio";return}
  putmsg $chan "$fan was already a fan of the radio!"
  }}}

proc add_dj {nick uhost hand chan text} {
  global chan_radio chan_Dj 
  if {$text == ""} {putmsg $chan "You must enter the nick of the dj to add!";return 0}
  set dj [join [lindex [split $text] 0]]

####HERE SHOULD BoT CHECK "DJ" IF A REGISTERED NICK, isnot return if yes continue####

    putserv "PRIVMSG chan :access $chan_Dj add $dj 300"
  if {![validuser $dj]}
.................etc ....................
................................
PROC WHOIS ORIGINAL http://forum.egghelp.org/viewtopic.php?p=66160 :

Code: Select all

bind join - * foo

proc foo {n u h c} {
  puthelp "whois $n"
}

bind raw - 311 gotraw ;# first WHOIS reply
bind raw - 307 gotraw ;# nick has identified (registered)
bind raw - 318 gotraw ;# End of /WHOIS list

proc gotraw {f k t} {
  global whoised
  set n [lindex [split $t] 1]
  if {$k == "311"} {
    set whoised($n) "0"
  } elseif {$k == "307"} {
    incr whoised($n)
  } elseif {$k == "318"} {
    if {$whoised($n) == "0"} {
      puthelp "privmsg $n :please identify or register your nick U can register your nick with this (/msg NickServ REGISTER yourpassword youremail) without the ()."
      puthelp "privmsg $n :Also you can use this to identify yourself if you already registered (/msg NickServ IDENTIFY yourpass) without the ()."
    }
  }
}
putlog "nickreg loaded"
MY ATTEMPT TO UNITE BOTH PROCEDURES:

Code: Select all

proc add_fan {nick uhost hand chan text} {
  global chan_radio whoisnick 
  if {$text == ""} {putmsg $chan "You must enter the nick of the fan to add!";return 0}
 set fan [join [lindex [split $text] 0]]

set nickreg $fan
puthelp "whois $nickreg"
gotraw $nickreg
  if {$whoisnick == 0 } { putmsg $chan "Can not add to staff a nick NO Signup!";return 0}
  if {$whoisnick == 1 } {

    putserv "PRIVMSG chan :access $chan_radio add $fan 100"
  if {![validuser $fan]} {
  adduser $fan
  chattr $fan +c
   putmsg $chan "You have added a $fan as fan radio"
  } else {
  if {![matchattr $fan +c]} { 
  chattr $fan +c 
  putmsg $chan "You have added a $fan as fan radio";return}
  putmsg $chan "$fan was already a fan of the radio!"
  }}}

proc add_dj {nick uhost hand chan text} {
  global chan_radio chan_Dj 
  if {$text == ""} {putmsg $chan "You must enter the nick of the dj to add!";return 0}
  set dj [join [lindex [split $text] 0]]

set nickreg $dj
puthelp "whois $nickreg"
gotraw $nickreg
  if {$whoisnick == 0 } { putmsg $chan "Can not add to staff a nick NO Signup!";return 0}
  if {$whoisnick == 1 } {


    putserv "PRIVMSG chan :access $chan_Dj add $dj 300"
  if {![validuser $dj]}
.................etc ....................
................................
}

bind raw - 311 gotraw ;# first WHOIS reply
bind raw - 307 gotraw ;# nick has identified (registered)
bind raw - 318 gotraw ;# End of /WHOIS list

proc gotraw {f k t} {
  global whoised whoisnick
  set nickreg [lindex [split $t] 1]
  if {$k == "311"} {
    set whoised($nickreg) "0"
  } elseif {$k == "307"} {
    incr whoised($nickreg)
  } elseif {$k == "318"} {
    if {$whoised($nickreg) == "0"} {
      set whoisnick 0
    } else {
      set whoisnick 1
  }
}

putlog "nickreg loaded"

I recognize that the line 'gotraw $nickreg' is wrong because no calls procedure gotraw properly, missing parameters.

I further acknowledge that the variable 'whoisnick' does not exist because the procedure gotraw isnot call properly.

Someone can help me properly invoke the procedure 'gotraw' for purposes of the variable 'whoisnick' take appropriate values?

If you think of any other ideas will be welcome :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hi,
First of all, you'll have to change your approach to an asynchronous one. You cannot have add_fan wait for a server response - instead you would have to make sure the check for a registered nick had already been done when add_fan is called.

What you'd really want to do, is have the !fieladd command send the "whois"-instruction, and then let gotraw handle the part of adding the user, etc.

Further, the "whois"-instruction might very well be used by other scripts (I don't recall right now if eggdrop uses it itself), so most likely you'll also need some sort of queue for knowing whether this whois-response is related to your script or not.
NML_375
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Hello nml375,

I was struggling through reading the original posters code, and remembered that I once needed "check if id'd", and compared to my method. I wrote it. Seems to work. (If bot discovers that itself is not id'd, then it sends commands to NS to identify itself)

I'm glad you replied first, because I couldn't get it into words, and I knew it. :)

I did it with one proc calling another, and I chose to introduce some delay with utimers. The idea was to try to allow for the possibility of Nickserv being slow to respond.

I do have a question though:
nml375 wrote: ... then let gotraw handle the part of adding the user, etc.
I would be leery of the above, for fear that something someday might trigger it.
Further, the "whois"-instruction might very well be used by other scripts (I don't recall right now if eggdrop uses it itself), so most likely you'll also need some sort of queue for knowing whether this whois-response is related to your script or not.
This is interesting. Can you talk more about this queue technique?


I chose to protect against unintended raw bind triggers by unbinding them.
That necessitates including the raw binds in a called proc, too.
Is this a poor way to go about it?

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

Post by nml375 »

Hi willyw,
Regarding "queueing", the exact implementation would probably depend on the needs of the given application(s).

A slight example, though:
Build a list called rawQueue, where each item is a pair (list) of nickname and "action-proc". Once the "gotraw" proc triggers, extract the nickname from the server-text, and search/iterate through the list, calling each proc with a matching nickname. Once called, do some housekeeping by removing the item from the list.
Of course, you could extend the list to match against both nickname and numeric response-code, and you could also add some custom arguments when calling the function, etc, etc
NML_375
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

nml375 wrote: What you'd really want to do, is have the !fieladd command send the "whois"-instruction, and then let gotraw handle the part of adding the user, etc.
.
Dear nml375, first thank you for your quick reply and then tell me your idea seems very good.
The issue is that I am newbie in TCL and I dont know how carry your idea into practice.

If each command (!fieladd,!djadd,!adminadd, !rootadd) used a single process whois, would be excellent for the purpose of not repeating lines.

Could you help me with the code? :oops:

Edited Reason: my bad english :$
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hi again,
Just letting you know I haven't forgotten about this thread, just been rather occupied. I'll see if I can't craft something for you to build on, in the next few days or so.
NML_375
Post Reply