From 682156f9acef1c9f0f8251c7c34567084e6bb281 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sun, 4 Aug 2024 00:06:28 +0100 Subject: [PATCH] better meta management --- irc.tcl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/irc.tcl b/irc.tcl index f7e1c6dac02e52cec5383b9ccc365a6fc8731bad..196b861b4ee03916e3318a194278287b969b8285 100755 --- a/irc.tcl +++ b/irc.tcl @@ -140,31 +140,33 @@ namespace eval ::irc { } } + proc ::irc::int-dictsub args { + if [catch { dict {*}$args } result options] { + return -options options [regsub {dictionary$} $result "channel meta"] + } else { + return -options options $result + } + } + proc ::irc::meta {subcommand chan args} { switch -- $subcommand { exists { - if {[llength $args] != 1} { return -code error "wrong # args: should be \"irc::meta exists chan key\"" } + if ![llength $args] { return -code error "wrong # args: should be \"irc::meta exists chan key\"" } - dict exists [set chan.handlers($chan)] {*}$args + ::irc::int-dictsub exists [set chan.handlers($chan)] {*}$args } remove { - if {[llength $args] != 1} { return -code error "wrong # args: should be \"irc::meta remove chan key\"" } + if ![llength $args] { return -code error "wrong # args: should be \"irc::meta remove chan key\"" } - dict remove chan.handlers($chan) {*}$args + ::irc::int-dictsub remove chan.handlers($chan) {*}$args } get { - if {[llength $args] ni {0 1}} { return -code error "wrong # args: should be \"irc::meta get chan ?key?\"" } - - if [catch { dict get [set chan.handlers($chan)] {*}$args } result options] { - return -options options [regsub {dictionary$} $result "channel meta"] - } else { - return -options options $result - } + ::irc::int-dictsub get [set chan.handlers($chan)] {*}$args } set { - if {[llength $args] != 2} { return -code error "wrong # args: should be \"irc::meta set chan key value\"" } + if {[llength $args] < 2} { return -code error "wrong # args: should be \"irc::meta set chan key ?key ...? value\"" } - dict set chan.handlers($chan) {*}$args + ::irc::int-dictsub set chan.handlers($chan) {*}$args } read { if [llength $args] { return -code error "wrong # args: should be \"irc::meta read chan\"" }