@@ 140,38 140,40 @@ 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 ?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\"" }
+ unset {
+ if ![llength $args] { return -code error "wrong # args: should be \"irc::meta unset chan key ?key ...?\"" }
- dict remove chan.handlers($chan) {*}$args
+ ::irc::int-dictsub unset 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\"" }
set chan.handlers($chan)
}
- default { return -code error "unknown subcommand \"$subcommand\": must be exists, get, remove, or set" }
+ default { return -code error "unknown subcommand \"$subcommand\": must be exists, get, set, or unset" }
}
}