-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
124 lines (105 loc) · 2.96 KB
/
bot.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import {
Client, Options,
GatewayIntentBits, Partials,
ActivityType,
ThreadChannel,
} from "discord.js";
import { readdirSync } from "node:fs";
import tr from "./localization/index.js";
import importJSON from "./utils/importJSON.function.js";
export const auth = importJSON("auth.json");
import initCommands from "@brylan/djs-commands";
export const client = new Client({
intents: [
GatewayIntentBits.Guilds,
],
partials: [
Partials.Channel, // for DMs
Partials.User, Partials.GuildMember, Partials.ThreadMember, // for performance
],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
UserManager: 0,
GuildMemberManager: 0,
ThreadMemberManager: 0,
StageInstanceManager: 0,
GuildForumThreadManager: 0,
MessageManager: 0,
GuildMessageManager: 0,
GuildEmojiManager: 0,
GuildStickerManager: 0,
}),
presence: { activities: [{
type: ActivityType.Listening, name: "/watch",
}]},
shards: "auto",
});
if(!Object.hasOwn(ThreadChannel.prototype, "nsfw"))
{
Object.defineProperty(ThreadChannel.prototype, "nsfw", {
get: function() { return this.parent?.nsfw; },
});
}
export var master;
export var myself;
import error from "./utils/error.js";
export async function sendToMaster(msg, onError = error)
{
if(!client.readyAt)
client.once("ready", () => client.users.fetch(auth.master)
.then(master => master.send(msg))
.catch(onError));
else
{
if(!master)
master = await client.users.fetch(auth.master);
master.send(msg).catch(onError);
}
}
client.login(auth.token);
client.on("ready", async () => {
console.log(`Running as ${client.user.tag}!`);
myself = client.user;
const { members } = await client.guilds.fetch(auth.adminServer);
master = (await members.fetch(auth.master)).user;
});
client.once("ready", () => {
initCommands(client, {
debug: auth.debug,
ownerServer: auth.adminServer,
makeEnumsGlobal: true,
middleware: tr.applyTranslations,
}).then((cmds) => console.log(cmds.size, "commands loaded"))
.catch(error);
import("./steam_news/watchers.js").then(({checkForNews, checkPrices}) => {
checkForNews();
checkPrices();
});
if(auth.topGG)
import("./topGG.js").then(({setup}) => setup(client, auth.topGG));
const guildCountCheck = setInterval(() => {
const nGuilds = client.guilds.cache.size;
if(nGuilds > 12000)
{
master.send(`Yo I got about ${nGuilds}servers now, get to hybrid sharding\nhttps://www.npmjs.com/package/discord-hybrid-sharding`);
clearInterval(guildCountCheck);
}
}, 3600_000);
});
import __dirname from "./utils/__dirname.js";
for(const file of readdirSync(__dirname(import.meta.url) + "/events"))
{
// synchronous import causes a dependency loop
import(`./events/${file}`)
.then(({default: handler}) => client.on(file.slice(0, -3), handler));
}
client.on("shardReady", id => {
console.log(`Shard ${id} online!`);
});
client.on("shardError", (err, id) => {
err.shardId = id;
error(err);
});
client.on("shardDisconnect", (_, id) => {
console.warn(`Shard ${id} dead.`);
});