| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sat Apr 11, 2015 6:01 pm Post subject: Again the Whois .. |
|
|
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: | ##############################################################################################
## ## 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"
}
} |
| Quote: | 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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat Apr 11, 2015 10:07 pm Post subject: Re: Again the Whois .. |
|
|
| juanamores wrote: |
...
| Quote: | 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: |
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. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sun Apr 12, 2015 12:23 pm Post subject: Re: Again the Whois .. |
|
|
| 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: |
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!"
}}} |
|
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Apr 12, 2015 2:45 pm Post subject: Re: Again the Whois .. |
|
|
| 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 ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sun Apr 12, 2015 4:04 pm Post subject: Re: Again the Whois .. |
|
|
| 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 ?
| Quote: | 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 } {
..............................
|
|
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Apr 12, 2015 4:25 pm Post subject: Re: Again the Whois .. |
|
|
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: |
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 ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sun Apr 12, 2015 4:35 pm Post subject: Re: Again the Whois .. |
|
|
| willyw wrote: |
| Code: |
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sun Apr 12, 2015 4:57 pm Post subject: Re: Again the Whois .. |
|
|
| 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 ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sun Apr 12, 2015 6:19 pm Post subject: |
|
|
Friend we're not getting it.
The line I already tried is:
| Quote: | | putmsg $chan "!Whois $fan" |
Because I need is that the process of TCL I posted in the first place trigger.
| Quote: | ##############################################################################################
## ## 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 | Quote: | | 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? |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Mon Apr 13, 2015 8:57 am Post subject: |
|
|
| juanamores wrote: | Friend we're not getting it.
The line I already tried is:
| Quote: | | 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.
...
| Quote: |
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: |
bind raw -|- "307" whois::307
|
So I am expecting you to find it listed.
Elsewhere in your code above, I see:
| Code: |
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?
| Quote: |
If I try to | Quote: | | 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.
| Quote: |
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 ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue Apr 14, 2015 1:11 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Apr 14, 2015 1:57 am Post subject: |
|
|
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: |
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: |
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: |
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. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue Apr 14, 2015 2:32 pm Post subject: |
|
|
Very grateful caesar
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  |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue Apr 14, 2015 10:25 pm Post subject: |
|
|
I tried the first:
| Code: | 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: | 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  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Apr 15, 2015 2:41 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|