From 985dcb2901d2527b79976df787035425294200b9 Mon Sep 17 00:00:00 2001 From: fireonlive Date: Fri, 9 Aug 2024 19:04:10 +0000 Subject: init --- tcl.tcl | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tcl.tcl (limited to 'tcl.tcl') diff --git a/tcl.tcl b/tcl.tcl new file mode 100644 index 0000000..abc310b --- /dev/null +++ b/tcl.tcl @@ -0,0 +1,69 @@ +# tcl.tcl - evaluate TCL statements in channels right from your eggdrop! +# use at your own risk lmfao, i accept no liability + +# who has access to this command? (ideally you'd bind n|, but this doesn't support services accounts yet) +set TCLNickServAccount "steering" + +bind pub * ,tcl tclchancmd +bind pub * ,, tclchancmd + +proc msgSplit {chan msg} { + set max_length 410 + set constructedMsg "PRIVMSG $chan :$msg" + # Check if the message is already within the allowed length + if {[string length $constructedMsg] <= $max_length} { + putquick "PRIVMSG $chan :$msg" + } else { + # Split the message into chunks of maximum length + set num_chunks [expr {([string length $msg] + $max_length - 1) / $max_length}] + for {set i 0} {$i < $num_chunks} {incr i} { + set chunk [string range $msg [expr {$i * $max_length}] [expr {($i + 1) * $max_length - 1}]] + putquick "PRIVMSG $chan :$chunk ([expr {$i + 1}]/$num_chunks)" + } + } +} + +proc tclchancmd {nick user hand chan text} { + global TCLNickServAccount + set acct [getaccount $nick] + set accthand [finduser -account $acct] + if {$accthand != $TCLNickServAccount} { + putserv "PRIVMSG $chan :no." + return 1 + } + + set startTime [clock clicks -milliseconds] + + set result [catch {uplevel #0 $text} resultText] + + set endTime [clock clicks -milliseconds] + set timeTaken [expr $endTime - $startTime] + + set lines [split $resultText "\n"] + set numLines [llength $lines] + + if {[string trim $resultText] == ""} { + set resultText "(no output)" + } + + if {$numLines <= 1} { + if {$result != 0} { + msgSplit $chan "error $result: $resultText -${timeTaken}ms-" + } else { + msgSplit $chan "ok: $resultText -${timeTaken}ms-" + } + } else { + if {$result != 0} { + putquick "PRIVMSG $chan :error $result: ($numLines lines) -${timeTaken}ms-" + } else { + putquick "PRIVMSG $chan :ok: ($numLines lines) -${timeTaken}ms-" + } + set outputtedLines 1 + foreach line $lines { + msgSplit $chan "${outputtedLines}/${numLines}: $line" + incr outputtedLines + } + } +} + +putlog "sourced tcl.tcl" -- cgit v1.3.1-10-gc9f91