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.

change output of banmask checker

Help for those learning Tcl or writing their own scripts.
Post Reply
s
simo
Revered One
Posts: 1069
Joined: Sun Mar 22, 2015 2:41 pm

change output of banmask checker

Post by simo »

greetingz gentz,

i was trying out this small code wich checks wich nicks will be effected with banmasks on channel currently it outputs :
nick1 nick2 nick3 nick3 nick4
if possible i wanted it to output in the manner of like :
(4) Nicks are effected: (1) nick1 (2) nick2 (3) nick3 (4) nick4

Code: Select all


bind pub n !ipcheck Pub:BanMask-Tester

proc Pub:BanMask-Tester {nick host hand chan text} {

    set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
   set target [lindex [split $text] 0]

    if { [string first ":" $target] != -1 } { set target [lindex [split $target ":"] 1] }

	set users [list]

 foreach n [chanlist $chan] {
  if {[string match -nocase $target $n![getchanhost $n $chan]]} {
    lappend users $n
  }
 }
  if {[llength $users]} { putserv "notice $nick :$users"  }
}





thanks gentz,
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Pub: BanMask-Tester

Post by SpiKe^^ »

???

Code: Select all

####  Pub: BanMask-Tester v0.2  ####

bind pub n !ipcheck Pub:BanMask-Tester

proc Pub:BanMask-Tester {nick host hand chan text} {

  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set target [lindex [split $text] 0]

  if {[string first ":" $target] > -1} { set target [lindex [split $target ":"] 1] }

  set users [list]
  foreach n [chanlist $chan] {
    if {[matchaddr $target $n![getchanhost $n $chan]]} {  lappend users $n  }
  }

  if {[llength $users]} {  set cnt 0  ;  set say ""
    foreach n $users {  append say " ([incr cnt]) $n"  }
    if {$cnt == 1} {  set plural "Nick is"  } else {  set plural "Nicks are"  }

    putserv "notice $nick :($cnt) $plural affected:$say"
  } else {  putserv "notice $nick :No nicks are affected."  }

  return 0
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1069
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks for the swift reply SpiKe^^
i tested it and it seems to do exactly as expected excellent thanks for that
1 last request if i may , if it would be possible to have the output in alphabetical order as it seems to output in random order atm

thanks in advance,
s
simo
Revered One
Posts: 1069
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i did an attempt it seems to work but im not sure if its the proper way to do it

Code: Select all

bind pub n !ipcheck Pub:BanMask-Tester

proc Pub:BanMask-Tester {nick host hand chan text} {

  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set target [lindex [split $text] 0]

  if {[string first ":" $target] > -1} { set target [lindex [split $target ":"] 1] }

  set users [list]
  foreach n [chanlist $chan] {
    if {[matchaddr $target $n![getchanhost $n $chan]]} {  lappend users $n ; set users [lsort -dictionary $users] }
  }

  if {[llength $users]} {  set cnt 0  ;  set say ""
    foreach n $users {  append say " ([incr cnt]) $n"  }
    if {$cnt == 1} {  set plural "Nick is"  } else {  set plural "Nicks are"  }

    putserv "notice $nick :($cnt) $plural affected:$say"
  } else {  putserv "notice $nick :No nicks are affected."  }

  return 0
}
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Pub: BanMask-Tester v0.3

Post by SpiKe^^ »

Well, I don't think I would put the sort in the foreach loop. Try this one...

Code: Select all

####  Pub: BanMask-Tester v0.3  #### 

bind pub n !ipcheck Pub:BanMask-Tester

proc Pub:BanMask-Tester {nick host hand chan text} {

  set text [regsub -all -- {\s{2,}} [string trim [stripcodes * $text]] { }]
  set target [lindex [split $text] 0]

  if {[string first ":" $target] > -1} { set target [lindex [split $target ":"] 1] }

  set users [list]
  foreach n [chanlist $chan] {
    if {[matchaddr $target $n![getchanhost $n $chan]]} {  lappend users $n  }
  }

  if {[llength $users]} {  set cnt 0  ;  set say ""
    foreach n [lsort -dictionary $users] {  append say " ([incr cnt]) $n"  }
    if {$cnt == 1} {  set plural "Nick is"  } else {  set plural "Nicks are"  }

    putserv "notice $nick :($cnt) $plural affected:$say"
  } else {  putserv "notice $nick :No nicks are affected."  }

  return 0
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1069
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

Thanks SpiKe^^ for correcting it ive tested it and it seems to work as expected thanks for that much apreciated
Post Reply