-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
terminal.native.ts
77 lines (69 loc) · 1.74 KB
/
terminal.native.ts
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
70
71
72
73
74
75
76
77
// native file, if you want edit it, remove the "native" suffix from the filename
import cp from "child_process"
import * as app from "#app"
export default new app.Command({
name: "terminal",
description: "Run shell command from Discord",
aliases: ["term", "cmd", "command", "exec", ">", "process", "shell"],
channelType: "all",
botOwnerOnly: true,
cooldown: {
duration: 5000,
type: app.CooldownType.Global,
},
rest: {
all: true,
name: "cmd",
description: "The cmd to run",
required: true,
},
async run(message) {
message.triggerCooldown()
const toEdit = await message.channel.send(
await app.getSystemMessage(
"loading",
{
header: "The process is running...",
body: message.rest,
},
{
code: "bash",
},
),
)
let systemMessage: app.SystemMessage
try {
const output = cp.execSync(message.rest, {
cwd: process.cwd(),
encoding: "utf-8",
})
systemMessage = await app.getSystemMessage(
"success",
{
header: "The process is done",
body:
output
.split("")
.reverse()
.slice(0, 2000)
.reverse()
.join("")
.trim() || "void",
},
{ code: "js" },
)
} catch (error: any) {
systemMessage = await app.getSystemMessage(
"error",
{
header: "The process is errored",
body: error,
},
{ stack: true },
)
}
toEdit.edit(systemMessage).catch(() => {
message.channel.send(systemMessage).catch()
})
},
})