Repository navigation
Expand file tree
/
Copy pathbot.js
More file actions
101 lines (81 loc) · 3.28 KB
/
Copy pathbot.js
File metadata and controls
101 lines (81 loc) · 3.28 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
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
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const Discord = require("discord.js");
const { Intents, Client } = Discord;
export const { DMChannel, Message, DiscordAPIError, MessageEmbed, version } = Discord;
import process, { env } from "process";
import config from "../config.js";
import { initGuilds, addGuild, removeMessageWithReplyId, removeGuild, closeDb } from "./sqlite3.js";
import { messageHandler } from "./messageHandler.js";
import { updateCountdowns } from "./updateManager.js";
const activities = [
{ type: "PLAYING", name: "with time" },
{ type: "PLAYING", name: "with 100 seconds" },
{ type: "WATCHING", name: "for !help" },
{ type: "WATCHING", name: "times change" },
{ type: "WATCHING", name: "the time fly by" },
{ type: "WATCHING", name: "https://bit.ly/live-bot" },
{ type: "LISTENING", name: "the clock tick" },
];
const activity = activities[Math.floor(Math.random() * activities.length)];
const presence =
env.NODE_ENV === "debug"
? { activity: { name: "maintenance", type: "WATCHING" }, status: "dnd" }
: { activity, status: "online" };
const requiredIntents = new Intents(["DIRECT_MESSAGES", "GUILDS", "GUILD_MESSAGES"]);
const client = new Client({
messageCacheMaxSize: 0,
// partials: ["MESSAGE"],
presence,
ws: { intents: requiredIntents },
});
export const clientId = Math.round(Math.random() * 1e9);
const { token } = config;
const log = console.log;
client.once("ready", () => {
log(`Initialized client ${clientId} (${client.shard.ids.join()}).`);
initGuilds(client.guilds.cache, clientId);
updateCountdowns(client, clientId);
});
client.on("message", async message => {
await messageHandler(message);
// if (message.author?.id !== client.user?.id && !message[Symbol.for("messageReply")])
// message.channel.messages.cache.delete(message.id);
});
// client.on("messageUpdate", (_, message) => {
// if (message.partial || message.author.bot) return;
// const messageReply = message[Symbol.for("messageReply")];
// if (messageReply && !messageReply.deleted) messageHandler(message, messageReply);
// });
// client.on("messageDelete", message => {
// const { guild, client, author } = message;
// if (message.partial || author.id !== client.user.id || !guild.available) return;
// removeMessageWithReplyId(message.id);
// });
client.on("guildCreate", guild => {
addGuild(guild.id, clientId);
if (guild.systemChannel && guild.me?.permissionsIn(guild.systemChannel.id).has("SEND_MESSAGES"))
guild.systemChannel.send(
"**Glad to be a part of your server** :heart:\nYou're probably looking for `!help`"
);
log(`Added to ${guild.name} (${guild.id})`);
});
client.on("guildDelete", guild => {
log(`Removed from ${guild.name} (${guild.id})`);
removeGuild(guild.id);
});
client.on("rateLimit", rateLimitInfo => {
log(rateLimitInfo);
});
// Start client
client.login(token);
if (env.NODE_ENV === "debug") client.on("debug", console.info);
process.on("unhandledRejection", log);
process.on("SIGHUP", () => process.exit(128 + 1));
process.on("SIGINT", () => process.exit(128 + 2));
process.on("SIGTERM", () => process.exit(128 + 15));
process.on("exit", code => {
console.log(`Destroying client ${clientId} (${client.shard.ids.join()}). Code ${code}.`);
client.destroy();
closeDb();
});