~aleteoryx/tclircc

9b25c0a5e86e7d434832c275c121fb730b96bb0e — Aleteoryx 4 months ago 6f6e566
meta management
1 files changed, 53 insertions(+), 6 deletions(-)

M irc.tcl
M irc.tcl => irc.tcl +53 -6
@@ 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


@@ 152,6 187,7 @@ namespace eval ::irc {
    $interp alias irc::src
    $interp alias irc::tags
    $interp alias irc::patlist
    $interp alias irc::meta
  }

  # nodoc


@@ 175,9 211,9 @@ namespace eval ::irc {
                              srctype $srctype \
                              srcparts $srcparts \
                              cmd $cmd \
                              params $params \
                              meta [set chan.meta($chan)]]
                              params $params]

    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
}