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.

merge 2 TCLs into one

Old posts that have not been replied to for several years.
Locked
h
hide
Voice
Posts: 26
Joined: Mon Dec 22, 2003 12:02 pm

merge 2 TCLs into one

Post by hide »

Hello all!
Firstly, I'll try to explain what type of script do I need:

"When a user having ident "cht-v3.1" or "off" joins any channel, bot DCC sends him/her file "vkt.ini" and puts his hostmask (for example: *!*@user.domain.com) into a file, so when users from the same hostmask joins to channel again, the file won't be sent again".

Please note that bot should send that file only for people having idents "cht-v3.1" or "off" but not any other!

I've two skripts here:

This script sends the file only for cht-v3.1 or off ident owners but it doesn't check if that file was sent for a certain hostmask in the past, so it send it to user every time (s)he joins a channel:

Code: Select all

set sendfile "/home/hide/_stuff/vkt.ini" 
bind join - * join:send 

proc join:send {nick uhost hand chan} { 
  if {[isbotnick $nick]} { 
    return 
  } 
  set ident [lindex [split $uhost @] 0] 
  if {![regexp -all {cht-v3.1|off} $ident]} { 
    return 
  } 
  dccsend $::sendfile $nick 
} 

here I have another script but it doesn't work due to unknown reason but I give it You anyway (maybe it'll help).

Code: Select all

set myfile "/home/hide/send.txt" 
bind join - * join:pub 

proc join:pub {nick host hand chan} { 
  global myfile 
  set read [open "myfile" r] 
  while {[gets $read line] != -1} { 
    if {[string equal -nocase "$line" "$nick"]} { 
      close $read 
      return 1 
    } 
  } 
  dccsend /home/hide/vkt.ini $nick 
  set file [open "$myfile" a] 
  puts $file "$nick" 
  close $file 
  close $read 
}
Could anybody merge me these two scripts into ane according to my needs I mentioned in the beginning? It would be glad to get help. I'm looking forward to it. Thanks.[/b]
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Re: merge 2 TCLs into one

Post by demond »

hide wrote:Hello all!
Firstly, I'll try to explain what type of script do I need:

"When a user having ident "cht-v3.1" or "off" joins any channel, bot DCC sends him/her file "vkt.ini" and puts his hostmask (for example: *!*@user.domain.com) into a file, so when users from the same hostmask joins to channel again, the file won't be sent again".

Please note that bot should send that file only for people having idents "cht-v3.1" or "off" but not any other!

I've two skripts here:

This script sends the file only for cht-v3.1 or off ident owners but it doesn't check if that file was sent for a certain hostmask in the past, so it send it to user every time (s)he joins a channel:

Code: Select all

set sendfile "/home/hide/_stuff/vkt.ini" 
bind join - * join:send 

proc join:send {nick uhost hand chan} { 
  if {[isbotnick $nick]} { 
    return 
  } 
  set ident [lindex [split $uhost @] 0] 
  if {![regexp -all {cht-v3.1|off} $ident]} { 
    return 
  } 
  dccsend $::sendfile $nick 
} 
your regexp is incorrect, it should be ^~*(cht-v3\\.1|off)$
here I have another script but it doesn't work due to unknown reason but I give it You anyway (maybe it'll help).

Code: Select all

set myfile "/home/hide/send.txt" 
bind join - * join:pub 

proc join:pub {nick host hand chan} { 
  global myfile 
  set read [open "myfile" r] 
  while {[gets $read line] != -1} { 
    if {[string equal -nocase "$line" "$nick"]} { 
      close $read 
      return 1 
    } 
  } 
  dccsend /home/hide/vkt.ini $nick 
  set file [open "$myfile" a] 
  puts $file "$nick" 
  close $file 
  close $read 
}
Could anybody merge me these two scripts into ane according to my needs I mentioned in the beginning? It would be glad to get help. I'm looking forward to it. Thanks.[/b]
inefficient & poorly written

you should keep hostnames in a list, and [lsearch] through that list; save the list in a file (on timer or by command) and load the list from a file on script load
h
hide
Voice
Posts: 26
Joined: Mon Dec 22, 2003 12:02 pm

Post by hide »

I've fixed my regexp line thanks.

But still: how can I manipulate the hostlist in *real time*? I mean, those 'special' people joing channels quite often so I don't think there'll help a periodic timer. It should be something more quicker than that.

I'm verry sorry but I'm still very lame in tcl scripts, I don't script by myself. Could anybody write me an example-script which does both mentioned checks (ident chech and then it verifies if the file wasn't already sent to certain hostmask)? Please note that from time to time I'll need to flush all entries (all hostmasks from the list), so the list should be kept in human-readable file or something near that. Thank You.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

set sent {}
set file /some/file
set save /some/savefile

bind join - * myjoin
bind time - "% % % % %" mysave

if ![catch {set f [open $save]}] {
  while {![eof $f]} {lappend sent [gets $f]}
  close $f
}

proc myjoin {n u h c} {
  scan $u %\[^@\]@%s user host
  if [regexp ^~?(cht-v3\\.1|off)$ $user] {
    set host [string tolower $host]
    if {[lsearch $::sent $host] == -1} {
      lappend ::sent $host
      dccsend $::file $n
    }
  }
}

proc mysave {m h d mn y} {
  set f [open $::save w]
  foreach h $::sent {puts $f $h}
  close $f
}
h
hide
Voice
Posts: 26
Joined: Mon Dec 22, 2003 12:02 pm

Post by hide »

script seems to work perfectly. A *GREAT* thanks for You. :wink:
h
hide
Voice
Posts: 26
Joined: Mon Dec 22, 2003 12:02 pm

modifying a tcl script..

Post by hide »

Hello everyone.. I have a problem. This is a TCL script I have:

Code: Select all

set sent {} 
set file /home/hide/public_html/vkt.ini 
set save /home/hide/public_html/sent.txt 

bind join - * myjoin 
bind time - "% % % % %" mysave 

if ![catch {set f [open $save]}] { 
  while {![eof $f]} {lappend sent [gets $f]} 
  close $f 
} 

proc myjoin {n u h c} { 
  scan $u %\[^@\]@%s user host 
  if [regexp ^~?(cht-v3\\.1|off)$ $user] { 
    set host [string tolower $host] 
    if {[lsearch $::sent $host] == -1} { 
      lappend ::sent $host 
      dccsend $::file $n 
    } 
  } 
} 

proc mysave {m h d mn y} { 
  set f [open $::save w] 
  foreach h $::sent {puts $f $h} 
  close $f 
}
but the problem is that my eggdrop bot puts the remote host entry into the file despite the file was sended successfully or sending failed.. Could anybody fix me that script so it would only write that hosts to file, that have successfuly dcc send completed (if sending failes I will not write anything to that file..).

I guess in the last block (mysave) there should be something like: if dccsend is successful then write the host to file, esle if dcc sending timed out-do nothing.. However, I dunno how to write that.. :(

Thanks. :)
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

set sent {} 
set file /some/file 
set save /some/savefile 

bind join - * myjoin 
bind time - "% % % % %" mysave 
bind sent - * mysent

if ![catch {set f [open $save]}] { 
  while {![eof $f]} {lappend sent [gets $f]} 
  close $f 
} 

proc myjoin {n u h c} { 
  scan $u %\[^@\]@%s user host 
  if [regexp ^~?(cht-v3\\.1|off)$ $user] { 
    set host [string tolower $host] 
    if {[lsearch $::sent $host] == -1} { 
      dccsend $::file $n 
    } 
  } 
} 

proc mysent {h n p} {
  scan [getchanhost $n] %\[^@\]@%s user host 
  set host [string tolower $host] 
  lappend ::sent $host
}

proc mysave {m h d mn y} { 
  set f [open $::save w] 
  foreach h $::sent {puts $f $h} 
  close $f 
} 
h
hide
Voice
Posts: 26
Joined: Mon Dec 22, 2003 12:02 pm

Post by hide »

Thanks a lot again!! It works perfectly.
Locked