|
|
@ -1,13 +1,13 @@ |
|
|
|
import {adminId, SubcommandData} from "../types.js" |
|
|
|
import {adminId, SubcommandData} from "../types" |
|
|
|
import { |
|
|
|
import { |
|
|
|
ActivityType, |
|
|
|
ActivityType, |
|
|
|
ApplicationCommandOptionType, |
|
|
|
ApplicationCommandOptionType, |
|
|
|
ApplicationCommandSubCommandData, |
|
|
|
ApplicationCommandSubCommandData, |
|
|
|
ChatInputCommandInteraction, |
|
|
|
ChatInputCommandInteraction, |
|
|
|
} from "discord.js" |
|
|
|
} from "discord.js" |
|
|
|
import {wrappedRestart} from "../../ipc/restart.js" |
|
|
|
import {wrappedRestart} from "../../ipc/restart" |
|
|
|
import {spawn} from "child_process" |
|
|
|
import {fork} from "child_process" |
|
|
|
import {defaultPresence} from "../../defaultPresence.js" |
|
|
|
import {defaultPresence} from "../../defaultPresence" |
|
|
|
import {resolve as resolvePath} from "path" |
|
|
|
import {resolve as resolvePath} from "path" |
|
|
|
|
|
|
|
|
|
|
|
class RebuildCommand extends SubcommandData { |
|
|
|
class RebuildCommand extends SubcommandData { |
|
|
@ -20,8 +20,56 @@ class RebuildCommand extends SubcommandData { |
|
|
|
async execute(b: ChatInputCommandInteraction): Promise<void> { |
|
|
|
async execute(b: ChatInputCommandInteraction): Promise<void> { |
|
|
|
const user = b.user || b.member |
|
|
|
const user = b.user || b.member |
|
|
|
if (!!user && user.id === adminId) { |
|
|
|
if (!!user && user.id === adminId) { |
|
|
|
await b.reply("Mmm... let's see... this goes here...") |
|
|
|
await b.reply({ |
|
|
|
|
|
|
|
content: "I dunno... Let's check if this will work...", |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
}) |
|
|
|
const self = b.client.user |
|
|
|
const self = b.client.user |
|
|
|
|
|
|
|
self.setPresence({ |
|
|
|
|
|
|
|
status: "online", |
|
|
|
|
|
|
|
afk: false, |
|
|
|
|
|
|
|
activities: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
type: ActivityType.Playing, |
|
|
|
|
|
|
|
name: "A Test of Your Codes", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
|
|
|
|
const result = fork(resolvePath("./node_modules/jest-cli/bin/jest"), { |
|
|
|
|
|
|
|
execPath: process.execPath, |
|
|
|
|
|
|
|
execArgv: process.execArgv, |
|
|
|
|
|
|
|
cwd: process.cwd(), |
|
|
|
|
|
|
|
stdio: "inherit", |
|
|
|
|
|
|
|
detached: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
result.disconnect() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.on("error", (ex) => { |
|
|
|
|
|
|
|
reject(ex) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
result.on("exit", (code) => { |
|
|
|
|
|
|
|
if (code !== 0) { |
|
|
|
|
|
|
|
reject(`Bad exit code ${code}`) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resolve() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} catch (ex) { |
|
|
|
|
|
|
|
console.log(ex) |
|
|
|
|
|
|
|
self.setPresence(defaultPresence) |
|
|
|
|
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
content: "Oh no... It's not working... Oh well...", |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
content: "Mmm... let's see... this goes here...", |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
}) |
|
|
|
self.setPresence({ |
|
|
|
self.setPresence({ |
|
|
|
status: "online", |
|
|
|
status: "online", |
|
|
|
afk: false, |
|
|
|
afk: false, |
|
|
@ -34,12 +82,49 @@ class RebuildCommand extends SubcommandData { |
|
|
|
}) |
|
|
|
}) |
|
|
|
try { |
|
|
|
try { |
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
const result = spawn(resolvePath("./node_modules/.bin/tsc"), { |
|
|
|
const result = fork(resolvePath("./node_modules/typescript/bin/tsc"), { |
|
|
|
|
|
|
|
execPath: process.execPath, |
|
|
|
|
|
|
|
execArgv: process.execArgv, |
|
|
|
cwd: process.cwd(), |
|
|
|
cwd: process.cwd(), |
|
|
|
stdio: "inherit", |
|
|
|
stdio: "inherit", |
|
|
|
detached: true, |
|
|
|
detached: true, |
|
|
|
shell: true, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
result.disconnect() |
|
|
|
|
|
|
|
result.on("error", (ex) => { |
|
|
|
|
|
|
|
reject(ex) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
result.on("exit", (code) => { |
|
|
|
|
|
|
|
if (code !== 0) { |
|
|
|
|
|
|
|
reject(`Bad exit code ${code}`) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
resolve() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} catch (ex) { |
|
|
|
|
|
|
|
console.log(ex) |
|
|
|
|
|
|
|
self.setPresence(defaultPresence) |
|
|
|
|
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
content: "I dunno... how to fit these together....", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
content: "Hmm hmm~ Annnd some gluuue...", |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await new Promise<void>((resolve, reject) => { |
|
|
|
|
|
|
|
const result = fork(resolvePath("./node_modules/@babel/cli/bin/babel"), |
|
|
|
|
|
|
|
["src", "--out-dir", "build", "--extensions", ".ts"], { |
|
|
|
|
|
|
|
execPath: process.execPath, |
|
|
|
|
|
|
|
execArgv: process.execArgv, |
|
|
|
|
|
|
|
cwd: process.cwd(), |
|
|
|
|
|
|
|
stdio: "inherit", |
|
|
|
|
|
|
|
detached: true, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
result.disconnect() |
|
|
|
result.on("error", (ex) => { |
|
|
|
result.on("error", (ex) => { |
|
|
|
reject(ex) |
|
|
|
reject(ex) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -54,7 +139,10 @@ class RebuildCommand extends SubcommandData { |
|
|
|
} catch (ex) { |
|
|
|
} catch (ex) { |
|
|
|
console.log(ex) |
|
|
|
console.log(ex) |
|
|
|
self.setPresence(defaultPresence) |
|
|
|
self.setPresence(defaultPresence) |
|
|
|
await b.followUp("Oops... I think it's broke...") |
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
content: "Oops... I think it's broken... Sowwy...", |
|
|
|
|
|
|
|
}) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
self.setPresence({ |
|
|
|
self.setPresence({ |
|
|
@ -67,10 +155,16 @@ class RebuildCommand extends SubcommandData { |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
|
}) |
|
|
|
}) |
|
|
|
await b.followUp("Phewwww... now I'll just... take a quick nap after all that hard work...") |
|
|
|
await b.followUp({ |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
content: "Phewwww... now I'll just... take a quick nap after all that hard work...", |
|
|
|
|
|
|
|
}) |
|
|
|
await wrappedRestart(b) |
|
|
|
await wrappedRestart(b) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
await b.reply("Heeey... I don't gotta do what you say...") |
|
|
|
await b.reply({ |
|
|
|
|
|
|
|
ephemeral: true, |
|
|
|
|
|
|
|
content: "Heeey... I don't gotta do what you say...", |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|