forked from TheBastionBot/Bastion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
58 lines (47 loc) · 1.51 KB
/
index.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
/*!
* @author TRACTION (iamtraction)
* @copyright 2022
*/
import path from "node:path";
import { Logger, ShardingManager, WebServer } from "@bastion/tesseract";
import DiscordRPC from "discord-rpc";
import dotenv from "dotenv";
import picocolors from "picocolors";
import Settings from "./utils/settings.js";
const settings = new Settings();
// configure dotenv
dotenv.config();
// connect to Discord via IPC
const rpc = new DiscordRPC.Client({ transport: "ipc" });
rpc.login({ clientId: "267035345537728512" }).catch(Logger.ignore);
// Sharding Manager
const Manager = new ShardingManager(path.resolve("dist", "bastion.js"));
// Spawn shards
Manager.spawn().catch(Logger.error);
// Sharding Manager Events
Manager.on("shardCreate", shard => {
Logger.info(`Shard ${shard.id} — Launching ${ picocolors.gray(`[ ${shard.id + 1} of ${ Manager.totalShards } ]`) }`);
});
// Tesseract Web Server
if (settings.auth && settings.port) {
const server = new WebServer(Manager);
server.start(settings.port);
}
// RPC Events
rpc.on("ready", () => {
rpc.setActivity({
details: "bastion.traction.one",
state: "discord.gg/fzx8fkt",
startTimestamp: new Date(),
largeImageKey: "d14ad8a2971e36cd54aa0ddc6be6d29b",
largeImageText: "Bastion",
smallImageKey: "b7b407c827109b547ce91a08e7f9168b",
smallImageText: "by TRACTION",
instance: false,
});
});
process.on("SIGINT", () => {
rpc.destroy()
.then(() => process.exit())
.catch(Logger.ignore);
});