-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcl.tcl
69 lines (58 loc) · 2.19 KB
/
tcl.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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"