-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
110 lines (91 loc) · 2.89 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
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
import { Client, Intents } from "discord.js";
import { config as Dotenv } from "dotenv";
import process from "process";
import {
connect,
Database,
helpers,
} from "temporary-database";
import { validateGuild, validateGuilds } from "./discord/methods/validateGuilds";
import { registerTriggers } from "./discord/triggers";
import "./bot/commands";
import "./bot/flows";
import { initializeLogger, Logger } from "./discord/methods/logger";
import { update } from "./bot/update";
Dotenv();
initializeLogger();
const detectDatabaseFailure = connect()
.then(() => undefined)
.catch((e) => helpers.guaranteeError(e));
const bot = new Client({
partials: ["MESSAGE", "CHANNEL", "REACTION"],
intents: [
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.GUILD_VOICE_STATES,
],
});
bot.on("ready", async (bot) => {
const databaseFailure = await detectDatabaseFailure;
if (databaseFailure) {
console.log("Database connection failed: ", databaseFailure);
}
Logger.info(
`Bot started, id: ${bot.user.id}\nDatabase: ${databaseFailure ?? "Connected"}`
);
await validateGuilds(bot);
await registerTriggers(bot);
// bot.guilds.cache.forEach((guild) => {
// getSystemChannel(guild)?.send(
// `Estoy listo! ${
// databaseFailure ? "No estoy" : "Estoy"
// } conectado a la base de datos! ${
// databaseFailure
// ? `\n\nSe detecto el siguiente problema: ${databaseFailure.message}`
// : ""
// }`
// );
// });
bot.user.setActivity({
type: "LISTENING",
name: "!help"
})
bot.guilds.cache.forEach((guild) => update(guild))
// console.log(
// "Mails rejected: ",
// getFulfilledResults(
// await Promise.allSettled(send(bulkEmails, new TestTemplate()))
// )
// .map((result, index) => ({ ...result, index }))
// .map((result) => ({
// ...result,
// rejected: [...(result.rejected ?? []), ...(result.pending ?? [])],
// index: `${result.index} - ${result.pending?.length ?? "0"}`,
// }))
// .filter((result) => (result.rejected?.length ?? 0) > 0)
// .map((result) => `(${result.index}) ${result.rejected[0]} Reason: ${result.response}`)
// );
// console.log(mailsSent());
// const { users, invites } = await importers.importFromOldData(
// await readFile("../tabla.xlsx")
// );
});
bot.on("guildCreate", (guild) => {
validateGuild(guild);
});
if (!process.env.DISCORD_TOKEN) throw new Error("Discord token not found");
bot.login(process.env.DISCORD_TOKEN);
process.on("beforeExit", () => {
Database.disconnect();
bot.destroy();
});
process.on("SIGTERM", () => {
Database.disconnect();
bot.destroy();
});