From d60cb1a07f7514acac6ea90455bc832ff31a64cd Mon Sep 17 00:00:00 2001 From: AnoBug Date: Tue, 18 Oct 2022 12:46:58 +0200 Subject: [PATCH 1/3] Addition of achannels Allows to list channels with a particular flag enabled --- scripts/alltools.tcl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scripts/alltools.tcl b/scripts/alltools.tcl index 78b901fe9..8e3a1e8ed 100644 --- a/scripts/alltools.tcl +++ b/scripts/alltools.tcl @@ -23,6 +23,7 @@ # Souperman 05Nov2002: added ordnumber # Tothwolf 27Dec2003: added matchbotattrany, optimized ordnumber, # more minor changes +# CrazyCat 18Oct2022: added achannels # ######################################## # @@ -100,6 +101,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): @@ -437,3 +441,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 unknow or not flag attribute"} "$attr is unknow or not flag attribute" + return + } + foreach c [channels] { + if {[channel get $c $attr]} { lappend achans $c } + } + } + return $achans +} \ No newline at end of file From 23affedf31b17edb45ed244246555bc9c68993e5 Mon Sep 17 00:00:00 2001 From: AnoBug Date: Wed, 31 Jan 2024 18:47:52 +0100 Subject: [PATCH 2/3] Added list utilities (diff, intersect) in alltools --- scripts/alltools.tcl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/alltools.tcl b/scripts/alltools.tcl index 8e3a1e8ed..2eee787d8 100644 --- a/scripts/alltools.tcl +++ b/scripts/alltools.tcl @@ -24,6 +24,7 @@ # Tothwolf 27Dec2003: added matchbotattrany, optimized ordnumber, # more minor changes # CrazyCat 18Oct2022: added achannels +# CrazyCat 31Jan2024: added lintersect and ldiff # ######################################## # @@ -127,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): @@ -384,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: # From b9afcfd96bac03791764245b9376c8196d340398 Mon Sep 17 00:00:00 2001 From: crazycatdevs <44431938+crazycatdevs@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:35:22 +0200 Subject: [PATCH 3/3] Small typo Corrected "unknow" to "unknown" --- scripts/alltools.tcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/alltools.tcl b/scripts/alltools.tcl index 2eee787d8..58b50bdce 100644 --- a/scripts/alltools.tcl +++ b/scripts/alltools.tcl @@ -465,7 +465,7 @@ proc achannels {{attr ""}} { } else { if {[catch {set atype [chansettype $attr]}]} { set atype "unknow" } if {$atype ne "flag"} { - throw {TCL ATTRUNK "$attr is unknow or not flag attribute"} "$attr is unknow or not flag attribute" + throw {TCL ATTRUNK "$attr is unknown or not flag attribute"} "$attr is unknown or not flag attribute" return } foreach c [channels] { @@ -473,4 +473,4 @@ proc achannels {{attr ""}} { } } return $achans -} \ No newline at end of file +}