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.

Again the Whois ..

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

Again the Whois ..

Post by juanamores »

There will be some way to modify this code to extract the value of a variable to another process?

Note that the other process (other TCL) should call at this.

Code: Select all

##############################################################################################
##  ##     whois.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help        ##  ##
##############################################################################################
## To use this script you must set channel flag +whois (ie .chanset #chan +whois)           ##
##############################################################################################
##      ____                __                 ###########################################  ##
##     / __/___ _ ___ _ ___/ /____ ___   ___   ###########################################  ##
##    / _/ / _ `// _ `// _  // __// _ \ / _ \  ###########################################  ##
##   /___/ \_, / \_, / \_,_//_/   \___// .__/  ###########################################  ##
##        /___/ /___/                 /_/      ###########################################  ##
##                                             ###########################################  ##
##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
namespace eval whois {
## change cmdchar to the trigger you want to use                                        ##  ##
  variable cmdchar "!"
## change command to the word trigger you would like to use.                            ##  ##
## Keep in mind, This will also change the .chanset +/-command                          ##  ##
  variable command "whois"
## change textf to the colors you want for the text.                                    ##  ##
  variable textf "\017\00302"
## change tagf to the colors you want for tags:                                         ##  ##
  variable tagf "\017\002"
## Change logo to the logo you want at the start of the line.                           ##  ##
  variable logo "\017\00304\002\[\00306W\003hois\00304\]\017"
## Change lineout to the results you want. Valid results are channel users modes topic  ##  ##
  variable lineout "channel users modes topic"
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################
  variable channel ""
  setudef flag $whois::command
  bind pub -|- [string trimleft $whois::cmdchar]${whois::command} whois::list
  bind raw -|- "311" whois::311
  bind raw -|- "312" whois::312
  bind raw -|- "319" whois::319
  bind raw -|- "317" whois::317
  bind raw -|- "313" whois::multi
  bind raw -|- "310" whois::multi
  bind raw -|- "335" whois::multi
  bind raw -|- "301" whois::301
  bind raw -|- "671" whois::multi
  bind raw -|- "320" whois::multi
  bind raw -|- "401" whois::multi
  bind raw -|- "318" whois::318
  bind raw -|- "307" whois::307
}
proc whois::311 {from key text} {
  if {[regexp -- {^[^\s]+\s(.+?)\s(.+?)\s(.+?)\s\*\s\:(.+)$} $text wholematch nick ident host realname]} {
    putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Host:${whois::textf} \
        $nick \(${ident}@${host}\) ${whois::tagf}Realname:${whois::textf} $realname"
  }
}
proc whois::multi {from key text} {
  if {[regexp {\:(.*)$} $text match $key]} {
    putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Info:${whois::textf} [subst $$key]"
        return 1
  }
}
proc whois::312 {from key text} {
  regexp {([^\s]+)\s\:} $text match server
  putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Servidor:${whois::textf} $server"
}
proc whois::319 {from key text} {
  if {[regexp {.+\:(.+)$} $text match channels]} {
    putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Canales:${whois::textf} $channels"
  }
}
proc whois::317 {from key text} {
  if {[regexp -- {.*\s(\d+)\s(\d+)\s\:} $text wholematch idle signon]} {
set A [ctime]
regsub -all "Mon" ctime "Lun" ctime
regsub -all "Tue" ctime "Mar" ctime
regsub -all "Wed" $signon "Mie" signon
regsub -all "Thur" $signon "Jue" signon
regsub -all "Fri" $signon "Vie" signon
regsub -all "Sat" $signon "Sab" signon
regsub -all "Sun" $signon "Dom" signon
regsub -all "Jan" $signon "Ene" signon
regsub -all "Apr" ctime "Abr" ctime
regsub -all "Aug" $signon "Ago" signon
regsub -all "Dec" $signon "Dic" signon

    putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Conectado prueba $A:${whois::textf} \
        [ctime $signon] ${whois::tagf}Inactivo:${whois::textf} [duration $idle]"
  }
}
proc whois::301 {from key text} {
  if {[regexp {^.+\s[^\s]+\s\:(.*)$} $text match awaymsg]} {
    putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Away:${whois::textf} $awaymsg"
  }
}
proc whois::318 {from key text} {
  namespace eval whois {
        variable channel ""
  }
  variable whois::channel ""
}
proc whois::307 {from key text} {
global nickreg
set nickreg 1
  putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Services:${whois::textf} Nick Registrado" 
}
proc whois::list {nick host hand chan text} {
  if {[lsearch -exact [channel info $chan] "+${whois::command}"] != -1} {
    namespace eval whois {
          variable channel ""
        }
    variable whois::channel $chan
    putserv "WHOIS $text"
  }
}
proc whois::307 {from key text} {
global nickreg
set nickreg 1
The value of the variable nickreg is who want to move to another process, which previously had to call this.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Again the Whois ..

Post by willyw »

juanamores wrote: ...
proc whois::307 {from key text} {
global nickreg
set nickreg 1
The value of the variable nickreg is who want to move to another process, which previously had to call this.
I am not 100% sure that I understand what you are asking.

If you are asking how to access the value currently stored in $nickreg in some other proc, then :

Code: Select all

proc another_proc { } {
global nickreg

# Now, within this proc, you can access the value in $nickreg.  You can 
# also change that value.

}

Here is where you can read more about the
global
command. http://www.tcl.tk/man/tcl8.5/TclCmd/global.htm

You might like to bookmark:
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
for your future reference.

I hope this helps.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Re: Again the Whois ..

Post by juanamores »

willyw wrote: I am not 100% sure that I understand what you are asking.
This topic has been discussed in that other thread.

What I want is to check if a nick is registered on the network, before adding that the staff of the bot.

This process named add_fan belongs to staff.tcl

I want to trigger another process whois which is on the other TCL(whois.tcl) I pasted above, only to move the value of the variable $nickreg. If the variable is 1, the nick is registered on the network, if the variable is 0, the nick is not registered.

This process belongs to staff.tcl:

Code: Select all

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

###HERE  I need to call the other TCL (!whois <nick>), take the value of the variable $nickreg and move to the next line. ###

  if {$nickreg == 0 } { putmsg $chan "Can not add to staff a nick NO Signup!";return 0}
  if {$nickreg == 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!"
  }}} 
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Again the Whois ..

Post by willyw »

juanamores wrote: ...
only to move the value of the variable $nickreg. If the variable is 1, the nick is registered on the network, if the variable is 0, the nick is not registered.
Try it the way I posted then.

It is like this:
If a variable is in the global namespace, then all you need to do, to be able to access that variable and to be able to change what is stored in it - in any given procedure - is to declare it with the
global
command, in the procedure.

There is a link that will take you to the page that explains the
global
command, in my earlier post.

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Re: Again the Whois ..

Post by juanamores »

willyw wrote: Try it the way I posted then.

It is like this:
If a variable is in the global namespace, then all you need to do, to be able to access that variable and to be able to change what is stored in it - in any given procedure - is to declare it with the
global
command, in the procedure.
The issue of global variables I have it clear.
What line would put you in the staff.tcl procedure to trigger proc whois 307, which is in whois.tcl ?
bind pub o|o !fieladd add_fan
proc add_fan {nick uhost hand chan text} {
global chan_radio nickreg
if {$text == ""} {putmsg $chan "You must enter the nick of the fan to add!";return 0}
set fan [join [lindex [split $text] 0]]

###HERE willyw I need to call the other TCL, whois.tcl, triggers proc whois 307 with the command (!whois $fan), to set value of the variable nickreg. ###

if {$nickreg == 0 } { putmsg $chan "Can not add to staff a nick NO Signup!";return 0}
if {$nickreg == 1 } {
..............................
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Again the Whois ..

Post by willyw »

Your posts and questions are not easy to follow, necessitating a lot of scrolling and re-reading.

But this time, I think I understood your question :
All you need to do is have the bot send out a /whois on some nick.
Apparently you already have some raw binding that will trap 307 that is part of a /whois return.

juanamores wrote:
The issue of global variables I have it clear.
What line would put you in the staff.tcl procedure to trigger proc whois 307, which is in whois.tcl ?

...

###HERE willyw I need to call the other TCL, whois.tcl, triggers proc whois 307 with the command (!whois $fan), to set value of the variable nickreg. ###

...

Code: Select all

putserv "whois $fan"

That line will cause the bot to do a /whois on whatever nick is stored in $fan.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Re: Again the Whois ..

Post by juanamores »

willyw wrote:

Code: Select all

putserv "whois $fan"
That line will cause the bot to do a /whois on whatever nick is stored in $fan.
We already tried but the bot just write that text by the channel but the process is not triggered.

It only triggers the process if users type a command !Whois, NOT the bot.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Again the Whois ..

Post by willyw »

juanamores wrote: ...

We already tried but the bot just write that text by the channel but the process is not triggered.

Post the line of code that you already tried.

There is nothing in the line of code that I posted, that will have the bot post to a channel.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Friend we're not getting it.
The line I already tried is:
putmsg $chan "!Whois $fan"
Because I need is that the process of TCL I posted in the first place trigger.
##############################################################################################
## ## whois.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
##############################################################################################
## To use this script you must set channel flag +whois (ie .chanset #chan +whois) ##
##############################################################################################
## ____ __ ########################################### ##
## / __/___ _ ___ _ ___/ /____ ___ ___ ########################################### ##
## / _/ / _ `// _ `// _ // __// _ \ / _ \ ########################################### ##
## /___/ \_, / \_, / \_,_//_/ \___// .__/ ########################################### ##
## /___/ /___/ /_/ ########################################### ##
## ########################################### ##
##############################################################################################
## ## Start Setup. ## ##
##############################################################################################
namespace eval whois {
## change cmdchar to the trigger you want to use ## ##
variable cmdchar "!"
## change command to the word trigger you would like to use. ## ##
## Keep in mind, This will also change the .chanset +/-command ## ##
variable command "whois"
## change textf to the colors you want for the text. ## ##
variable textf "\017\00302"
## change tagf to the colors you want for tags: ## ##
variable tagf "\017\002"
## Change logo to the logo you want at the start of the line. ## ##
variable logo "\017\00304\002\[\00306W\003hois\00304\]\017"
## Change lineout to the results you want. Valid results are channel users modes topic ## ##
variable lineout "channel users modes topic"
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
This code I pasted is triggered with !whois <nick>
I need the correct line to trigger the above process.

If I try to
putserv "whois $fan"
all you'll get is that the bot will make a WHOIS a $fan, but not trigger the process that desire for the purpose of taking the value of the variable 'nickreg'.


Now you understand my idea?
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

juanamores wrote:Friend we're not getting it.
The line I already tried is:
putmsg $chan "!Whois $fan"
Thought so. And that is not what I posted. :)
And that explains why your bot simply posted it in the channel, instead of sending the /whois request to the server.

By the way, maybe you thought you could have the bot post a command that it recognizes?
Normally, that won't work - the bot doesn't see its own posts.


...
This code I pasted is triggered with !whois <nick>
I need the correct line to trigger the above process.
I told you. You need to make the bot send a whois command to the server.

Let's check a couple things.

First, do:
.binds *307*
and
.binds raw

in the partyline. You will get a list of binds that match the mask given.
You are looking for your bind that triggers on raw 307.
Do you see it listed?
If not, it means it is not loaded.
If you do see it listed - good. It is loaded.

Now notice the hit counter. By checking it repeatedly and at the right times, you can learn if this bind is triggering when you expect it to.
This is important.

Next - note the proc that is called by this bind. Is it the proc that you really want to be called? Go check, carefully.

If the hit counter IS incrementing when you expect it to, then that proc is being called.

In some of the code you have posted, I see:

Code: Select all

bind raw -|- "307" whois::307 
So I am expecting you to find it listed.

Elsewhere in your code above, I see:

Code: Select all

proc whois::307 {from key text} {
global nickreg
set nickreg 1
  putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Services:${whois::textf} Nick Registrado"
} 
So this is the proc that is run when the bot triggers on an incoming raw 307.

Next -
Check in your eggdrop.conf to see if you have enabled the use of raw logging for bot owner (you).
If not, turn it on for now. Save the file, and rehash.
In the partyline, do:
.console +r
to turn it on. (You can turn it back off later, with .console -r)
Now you will see everything coming into the bot.
Do:
.dump whois someNickHere
where someNickHere is a nick that is online and is reg'd and is id'd with nickserv.

If you have enabled the use of the .tcl and .set commands for yourself in the partyline -
Alternately you could do: .tcl putserv "whois someNickHere"

Watch the return from the irc server. You will see it, because you have
.console +r
now.
Look for the raw numerics.
See a 307 ?
If not, your proc that is bound to it, will not trigger.
Check, with
.binds raw
and/or
.binds *307*
again. Did the hit counter increment?
If I try to
putserv "whois $fan"
all you'll get is that the bot will make a WHOIS a $fan, but not trigger the process that desire for the purpose of taking the value of the variable 'nickreg'.
So do the things I've said above first. You've got to find out why it is not triggering the bind that you expect.
First, be sure the bind is loaded.
Next, be sure it is being triggered.
If it IS being triggered, examine that which is triggers. (Is it the proc you need/want?) If not, then there is likely your problem.
Now you understand my idea?
You have a mess. :)

I _think_ you are concerned with using two different scripts, each using the same variable.
That is not a problem, as long as both variables are in the global namespace, and I think that is what you have.

I _think_ you feel that the value of the variable is not being passed, and you feel that is the problem. However, I suspect that you might not even be calling the proc you expect, when you suspect. You need to prove all that, first.

As for checking the value of some variable at various points in your script to help you debug it, why not go right to the place in your script where you need to know exactly what the value of that variable is, and do:
putserv "privmsg YourNickHere :nickreg is : $nickreg"
and it will tell you every time it runs. :)
Maybe its value is not what you expect, at those critical points.


I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Thanks willyw for this complete information.
Everything you've shared with me helped me :)

Anyway I will not use the Whois command for this, because the user has to be online.

I replaced my original idea for reading private messages of CHaN bot, when we try to add a user to staff.

Then, search the text of certain words message indicating that the user is or is not registered on the network.
Also this information helped me to learn more about the operation of TCL. :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

All raw procs have useless regexp matches in them when the returned text will always match it, and 317 in particular doesn't have or uses some variables like ctime and A.

On top of that, if you want to change the content of a string with something different then should use string map instead of multiple regsub -all lines.

For example, instead of:

Code: Select all

regsub -all "Mon" ctime "Lun" ctime
regsub -all "Tue" ctime "Mar" ctime
regsub -all "Wed" $signon "Mie" signon
regsub -all "Thur" $signon "Jue" signon
regsub -all "Fri" $signon "Vie" signon
regsub -all "Sat" $signon "Sab" signon
regsub -all "Sun" $signon "Dom" signon
could go nicely with just:

Code: Select all

set signon [string map [list "Mon" "Lun" "Tue" "Mar" "Wed" "Mie" "Thur" "Jue" "Fri" "Vie" "Sat" "Sab" "Sun" "Dom"] $signon]
Where for example "Mon" will be replaced with "Lun" in the $signon variable.

Or if it's too confusing on what and where to change, and instead want to have them in two variables to be easier then:

Code: Select all

set es [list "Dom" "Lun" "Mar" "Mie" "Jue" "Vie" "Sab"]
set en [list "Sun" "Mon" "Tue" "Wed" "Thur" "Fri" "Sat"]

foreach a $en b $es { lappend map "$a $b" }
set signon [string map $map $signon]
Once the game is over, the king and the pawn go back in the same box.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Very grateful caesar :D

Precisely the code was giving me errors in that part and was trying to fix.
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

I tried the first:

Code: Select all

proc whois::317 {from key text} {
set signon [string map [list "Mon" "Lun" "Tue" "Mar" "Wed" "Mie" "Thur" "Jue" "Fri" "Vie" "Sat" "Sab" "Sun" "Dom"] $signon] 
  if {[regexp -- {.*\s(\d+)\s(\d+)\s\:} $text wholematch idle signon]} {
     putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Conectado :${whois::textf} \
        [ctime $signon] ${whois::tagf}Inactivo:${whois::textf} [duration $idle]"
  }
} 
And the second:

Code: Select all

proc whois::317 {from key text} {
set es [list "Dom" "Lun" "Mar" "Mie" "Jue" "Vie" "Sab"]
set en [list "Sun" "Mon" "Tue" "Wed" "Thur" "Fri" "Sat"]
foreach a $en b $es { lappend map "$a $b" }
set signon [string map $map $signon] 
  if {[regexp -- {.*\s(\d+)\s(\d+)\s\:} $text wholematch idle signon]} {
     putserv "PRIVMSG $whois::channel :${whois::logo} ${whois::tagf}Conectado :${whois::textf} \
        [ctime $signon] ${whois::tagf}Inactivo:${whois::textf} [duration $idle]"
  }
}
I tried testing both codes but I get the following error:
Tcl error [whois::317]: wrong # args: should be "list nick host hand chan text"
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You get that error cos you seem to have a function named list. Find it and replace it with something else.
Once the game is over, the king and the pawn go back in the same box.
Post Reply