egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting $chan when not a arg
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Mon Feb 08, 2021 4:27 am    Post subject: Setting $chan when not a arg Reply with quote

So say i am needing $chan and its not in the proc's args

how would i set it? Laughing

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 Rolling Eyes

Thanks in advanced

EDIT
Havent tested yet (about to head out)
Code:

set c [channels] {

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
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Mon Feb 08, 2021 6:51 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Mon Feb 08, 2021 10:47 am    Post subject: Re: Setting $chan when not a arg Reply with quote

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. Smile 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
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Tue Feb 09, 2021 1:53 am    Post subject: Reply with quote

So i figured it out myself, and thought i could share what i wanted and hopefully help others Smile

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
View user's profile Send private message Send e-mail Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Feb 09, 2021 1:58 am    Post subject: Reply with quote

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
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Tue Feb 09, 2021 5:42 am    Post subject: Reply with quote

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 Smile
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Feb 09, 2021 11:39 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Tue Feb 09, 2021 2:47 pm    Post subject: Reply with quote

Oh i see CrazyCat, Thank You for the idea Very Happy
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Feb 09, 2021 7:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Feb 10, 2021 1:59 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Feb 10, 2021 8:47 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Wed Feb 10, 2021 5:25 pm    Post subject: Reply with quote

got a working version which does the job Very Happy

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 Laughing
_________________
ComputerTech


Last edited by ComputerTech on Wed Feb 10, 2021 7:58 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Feb 10, 2021 7:29 pm    Post subject: Reply with quote

So you do:
Code:
unset pingchan

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 Smile
_________________
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
View user's profile Send private message Visit poster's website
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Wed Feb 10, 2021 7:55 pm    Post subject: Reply with quote

well maybe i could do

Code:

unset pingchan($nick)



I'll try come up with more ideas myself while you're sleeping. Cool
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Feb 10, 2021 8:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber