diff --git a/scripts/alltools.tcl b/scripts/alltools.tcl index 78b901fe9..58b50bdce 100644 --- a/scripts/alltools.tcl +++ b/scripts/alltools.tcl @@ -23,6 +23,8 @@ # Souperman 05Nov2002: added ordnumber # Tothwolf 27Dec2003: added matchbotattrany, optimized ordnumber, # more minor changes +# CrazyCat 18Oct2022: added achannels +# CrazyCat 31Jan2024: added lintersect and ldiff # ######################################## # @@ -100,6 +102,9 @@ # killdccbut # kill all dcc user connections except for the given idx # +# achannels [flag] +# return channels with flag enabled +# if channels is empty, return channel list # ## ## (moretools): @@ -123,6 +128,11 @@ # if the given number is between 1 and 15, return its text representation # else return the number given # +# lintersect +# returns a list of all elements in list1 that are present in list2 +# +# ldiff +# returns a list of all elements in list1 which are not in list2 # ## ## (other commands): @@ -380,6 +390,16 @@ proc number_to_number {number} { } } +proc lintersect {list1 list2 {option -exact}} { + if {$option ne "-nocase"} { set option -exact } + return [lmap x $list1 {expr {[lsearch $option $list2 $x] >= 0 ? $x : [continue]}}] +} + +proc ldiff {list1 list2 {option -exact}} { + if {$option ne "-nocase"} { set option -exact } + return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}] +} + # # other commands: # @@ -437,3 +457,20 @@ proc ordnumber {string} { } return $string } + +proc achannels {{attr ""}} { + set achans {} + if {$attr eq ""} { + set achans [channels] + } else { + if {[catch {set atype [chansettype $attr]}]} { set atype "unknow" } + if {$atype ne "flag"} { + throw {TCL ATTRUNK "$attr is unknown or not flag attribute"} "$attr is unknown or not flag attribute" + return + } + foreach c [channels] { + if {[channel get $c $attr]} { lappend achans $c } + } + } + return $achans +}