| View previous topic :: View next topic |
| Author |
Message |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Mon Feb 08, 2021 4:27 am Post subject: Setting $chan when not a arg |
|
|
So say i am needing $chan and its not in the proc's args
how would i set it?
like say when usind bind msg.
| Code: |
proc name {nick host hand text} {
|
and not to just set a channel via script like
| Code: |
set chan "#channel"
|
i mean the current channel arg
Thanks in advanced
EDIT
Havent tested yet (about to head out)
would that be equivalent of $chan ? _________________ ComputerTech
Last edited by ComputerTech on Tue Feb 09, 2021 2:48 pm; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Feb 08, 2021 6:51 am Post subject: |
|
|
Well, you'd better read the doc:
| Quote: | | channels : Returns: a list of the channels the bot has a channel record for |
So, your line of code will create a list, including inactive channels.
Give us the context, or more your tcl, because our cristal ball is under repair _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Mon Feb 08, 2021 10:47 am Post subject: Re: Setting $chan when not a arg |
|
|
| ComputerTech wrote: | So say i am needing $chan and its not in the proc's args
...
|
Start by asking yourself : Where is it?
Where ever that is - start there.
Is the channel in question determined somewhere? Is it in some variable, somewhere?
If it is, you just need to figure out how to get it from there, to where ever you next need it.
One possibility might be to utilize the global command.
But CrazyCat is right.
We cannot read your mind. Need more info. _________________ 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 |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Feb 09, 2021 1:53 am Post subject: |
|
|
So i figured it out myself, and thought i could share what i wanted and hopefully help others
| Code: |
bind pub "!test1" test:one
proc test:one {nick host hand chan text} {
set pingchan $chan
putserv "PRIVMSG $pingchan :Blah"
}
bind pub "test2" test:two
proc test:two {nick host hand text} {
global pingchan
putserv "PRIVMSG $pingchan :Blah"
}
|
_________________ ComputerTech |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Feb 09, 2021 1:58 am Post subject: |
|
|
The function that is triggered by the bind pub expects 5 arguments and you provided just 4 in your second function.
| Code: |
proc test:two {nick host hand chan text} {
# your code
}
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Feb 09, 2021 5:42 am Post subject: |
|
|
Meh, i'll post my entire script and not bother creating examples heh
| Code: |
bind pub $ctping(flag) $ctping(trig)ping ct:pub:ping
bind ctcr - PING ct:pingr
set pingchan ""
proc pub:ping {nick host hand chan text} {
global pingchan pingwho
set pingwho [lindex [split $text] 0]
if {$pingwho == ""} {set pingwho $nick}
putquick "PRIVMSG $pingwho :\001PING [clock clicks -milliseconds]\001"
set pingchan $chan
}
proc ct:pingr {nick uhost hand dest keyword args} {
global pingchan ctping colo pingwho char
set time [expr {([clock clicks -milliseconds] - $args) / 1000.000}]
if {[expr {round($time / 0.5)}] > 10} {set red 10} else {set red [expr {round($time / 0.5)}]}
set green [expr {10 - $red}]
set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
if {($ctping(msg) == "0")} {
putquick "PRIVMSG $pingchan :\[\0030${colo}PING\003\] reply from $pingwho: $output \[\0030${colo}$time\003\] seconds"
} else {
putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds"
}
}
|
so as you can see proc 1 sets $pingchan and then use global to bring it to proc 2, script works perfect  _________________ ComputerTech |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Feb 09, 2021 11:39 am Post subject: |
|
|
It works because the ping reply is quick and you don't have a lot of queries.
If you have several users on several channels asking for a ping in a few delay, the reply can go to the bad chan.
You'd better store chan in an array:
| Code: | | set pingchan($nick) $chan |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Feb 09, 2021 2:47 pm Post subject: |
|
|
Oh i see CrazyCat, Thank You for the idea  _________________ ComputerTech |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Tue Feb 09, 2021 7:26 pm Post subject: |
|
|
| CrazyCat wrote: | :
...
| Code: | | set pingchan($nick) $chan |
|
Just thinking ...
Wouldn't it be possible, with a lot of users, to thus have a huge array?
Would it consume a lot of memory?
Would it be wise to come up with some code to clear it all, somehow? _________________ 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 |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Feb 10, 2021 1:59 am Post subject: |
|
|
Since there's no code to clear the array it will pile up and eat his RAM at some point. Apart this, he needs to add a piece of code to track nickname changes, parts, quits and maybe some flood control mechanism just to be on the safe side. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Feb 10, 2021 8:47 am Post subject: |
|
|
Sure, I just gave an indication on the kind of variable to use, no more.
There is several examples here about how to manage that. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Wed Feb 10, 2021 5:25 pm Post subject: |
|
|
got a working version which does the job
| Code: |
# Start Of Configuration #
##########################
#Set trigger of the Command.
set ctping(trig) "@"
##################
#Set flag for Commands.
##
#Owner = n
#Master = m
#Op = o
#Voice = v
#Friend = f
#Everyone = -
set ctping(flag) "-|-"
##################
#Set to use Notice Or Channel for Output of Command
##
#1 = Notice
#0 = Channel
set ctping(msg) "0"
##################
#Set Colour of Output
##
#White = 0
#Black = 1
#Dark Blue = 2
#Green = 3
#Red = 4
#Brown = 5
#Purple = 6
#Orange = 7
#Yellow = 8
#Light Green = 9
#DarkCyan = 10
#LightCyan = 11
#LightBlue = 12
#Pink = 13
#Dark Grey = 14
#Light Grey = 15
set colo "3"
##################
#Set Time per usage of Command
##
set ctping(time) "5"
########################
# End Of Configuration #
#################################################################################################################################################################
bind pub $ctping(flag) $ctping(trig)ping ct:pub:ping
bind ctcr - PING ct:pingr
proc ct:pub:ping {nick host hand chan text} {
global pingchan pingwho
set pingwho [lindex [split $text] 0]
if {$pingwho == ""} {set pingwho $nick}
putquick "PRIVMSG $pingwho :\001PING [clock clicks -milliseconds]\001"
set pingchan($pingwho) $chan
}
proc ct:pingr {nick uhost hand dest keyword text} {
global pingchan ctping colo pingwho
set time [expr {([clock clicks -milliseconds] - $text) / 1000.000}]
set char "="
if {[expr {round($time / 0.5)}] > 10} {set red 10} else {set red [expr {round($time / 0.5)}]}
set green [expr {10 - $red}]
set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
if {($ctping(msg) == "0")} {
putquick "PRIVMSG $pingchan($pingwho) :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds $output"
} else {
putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds"
}
unset pingchan
}
|
Probably not the best heh  _________________ ComputerTech
Last edited by ComputerTech on Wed Feb 10, 2021 7:58 pm; edited 1 time in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Wed Feb 10, 2021 7:29 pm Post subject: |
|
|
So you do:
You unset the full array when you got the first ping reply ? What about the others if they did !ping at the same moment ?
And you don't check if pingchan($pingwho) exists, you just use it... This code is not really better than your previous one, I'll try to show ytou how to do that in a few hours, it's sleepin time now  _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Wed Feb 10, 2021 7:55 pm Post subject: |
|
|
well maybe i could do
| Code: |
unset pingchan($nick)
|
I'll try come up with more ideas myself while you're sleeping.  _________________ ComputerTech |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Feb 10, 2021 8:00 pm Post subject: |
|
|
| ComputerTech wrote: |
| Code: |
...
putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from
...
|
... |
What's stored in $nick there?
Is that what you really want there? _________________ 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 |
|
 |
|