From e1f0c285e0a7a4d80513ea5ea4151320d7d086a5 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sat, 3 Aug 2024 23:44:51 +0100 Subject: [PATCH] meta management --- irc.tcl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/irc.tcl b/irc.tcl index 170f1217cb39ae04d9ebefa65617e1899687afe2..6704c319d267cb77bd9ce8d1a910f5e8892b9eb1 100755 --- a/irc.tcl +++ b/irc.tcl @@ -140,6 +140,41 @@ namespace eval ::irc { } } + 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\"" } + + dict exists [set chan.handlers($chan)] {*}$args + } + remove { + if {[llength $args] != 1} { return -code error "wrong # args: should be \"irc::meta remove chan key\"" } + + dict 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 + } + } + set { + if {[llength $args] != 2} { return -code error "wrong # args: should be \"irc::meta set chan key value\"" } + + dict 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" } + } + } + # nodoc proc ::irc::int-setaliases {interp} { $interp alias irc::is @@ -178,6 +213,7 @@ namespace eval ::irc { params $params \ meta [set chan.meta($chan)]] + set matchedany false foreach handler [set chan.handlers($chan)] { set rest [lassign $handler patlist type id] @@ -199,6 +235,7 @@ namespace eval ::irc { } if !$matched { continue } + set matchedany true switch -- $type { chan { lassign $rest writer interp @@ -225,6 +262,9 @@ namespace eval ::irc { } } } + if !$matchedany { + puts stderr "irc warning: unmatched command on channel \"$chan\": $msg" + } } # documented @@ -647,10 +687,17 @@ namespace eval ::irc { } } -set chan [irc::connect localhost 8000 0] +set chan [irc::connect irc.libera.chat 6697 1] puts $chan irc::listen on $chan -lassign [chan pipe] ichan ochan -irc::extern add $chan * $ochan $ichan +#lassign [chan pipe] ichan ochan +irc::extern add $chan * stdout stdin + +#fileevent stdin readable { set input [gets stdin] } -vwait foo +set input "" + +while 1 { + vwait input + eval $input +}