-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (40 loc) · 1.39 KB
/
index.js
File metadata and controls
49 lines (40 loc) · 1.39 KB
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
import { execSync } from "node:child_process";
import { existsSync, rmSync } from "node:fs";
import nodePath from "node:path";
import process from "node:process";
import prism from "prism-media";
import { downloadExecutable } from "./src/utils/yt-dlp/index.js";
const ensureEnv = (arr) => arr.every((x) => process.env[x] !== undefined);
const isGitHub = ensureEnv([
"GITHUB_ENV",
"GITHUB_REPOSITORY_OWNER",
"GITHUB_HEAD_REF",
"GITHUB_API_URL",
"GITHUB_REPOSITORY",
"GITHUB_SERVER_URL",
]);
function npmInstall(deleteDir = false, forceInstall = false, additionalArgs = []) {
if (deleteDir) {
const modulesPath = nodePath.resolve(process.cwd(), "node_modules");
if (existsSync(modulesPath)) {
rmSync(modulesPath, {
recursive: true,
force: true,
});
}
}
execSync(`pnpm install${forceInstall ? " --force" : ""} ${additionalArgs.join(" ")}`);
}
if (isGitHub) {
console.warn("[WARN] Running this bot using GitHub is not recommended.");
}
try {
prism.FFmpeg.getInfo(true);
} catch {
console.info("[INFO] Couldn't find FFmpeg/avconv, trying to install ffmpeg-static...");
npmInstall(false, false, ["--no-save", "ffmpeg-static"]);
console.info("[INFO] ffmpeg-static has been installed.");
}
await downloadExecutable();
console.info("[INFO] Starting the bot...");
import("./dist/index.js");