-
-
Save khobbits/c87dfffd5ad7dcc476d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc khtcl {nick host hand chan arg} { | |
set khtclctx [getctx] | |
if { [getbncuser $khtclctx tag tclbot] != "1" } { return } | |
set lines 4 | |
set first [lindex [split $arg " "] 0] | |
set skipempty 1 | |
if {$first == "-v"} { | |
set arg [string range $arg 3 end] | |
set lines -1 | |
} elseif {$first == "-vv"} { | |
set arg [string range $arg 4 end] | |
set lines -1 | |
set skipempty 0 | |
} | |
set khtclreturn [catch {eval $arg} khtclresult khtclerr] | |
if {$khtclreturn == 1} { | |
if {$lines == -1 && [dict exists $khtclerr -errorinfo]} { | |
set khtclresult [dict get $khtclerr -errorinfo] | |
} | |
set khtclresult "Error: $khtclresult" | |
} | |
setctx $khtclctx | |
if {[string length $arg] > 50} { | |
set prefix "[string range $arg 0 50]..." | |
} else { | |
set prefix $arg | |
} | |
if {$khtclresult == ""} { set khtclresult "<null>" } | |
set printed 0 | |
set skipped 0 | |
set skippedLine "" | |
foreach sline [split $khtclresult \n] { | |
if {[string trim $sline] != "" || $skipempty == 0} { | |
if {$lines == -1 || $printed < $lines} { | |
putserv "PRIVMSG $chan :BNC ( $prefix ) = $sline" | |
incr printed | |
} else { | |
incr skipped | |
set skippedLine $sline | |
} | |
} | |
} | |
if {$skipped > 0} { | |
if {$skipped != 1} { | |
set skippedLine "...$skipped additional line(s) skipped." | |
} | |
putserv "PRIVMSG $chan :BNC ( $prefix ) = $skippedLine" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment