-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
125 lines (100 loc) · 3.56 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//#region Imports
import dotenv from 'dotenv'
dotenv.config()
import {
Client,
IntentsBitField,
Collection,
MessageType
} from "discord.js"
import { initializeApp, cert } from 'firebase-admin/app'
import { getFirestore } from 'firebase-admin/firestore'
import {
setClient,
setProduction,
setDatabase
} from "./bot/constants.js"
import type { DJSEvent, ErrorWithCode, ExtendedClient } from "./bot/types.js"
import { readTsFiles } from "./bot/utils/fn.js"
//#endregion
//#region Check production
const prod = process.env.PROD == "true"
setProduction(prod)
console.log(prod ? "Running in production." : "Running in maintenance, live functions disabled.")
//#endregion
//#region Initialize Discord
const Intents = IntentsBitField.Flags
const client: ExtendedClient = new Client({
allowedMentions: { repliedUser: false },
intents: [
Intents.Guilds,
Intents.GuildMessages,
Intents.GuildMembers,
Intents.DirectMessages,
Intents.DirectMessageReactions,
Intents.MessageContent
]
})
client.login(process.env.DISCORD_BOT_TOKEN).then(token => {
client.slashCommands = new Collection()
client.auroraCommands = new Collection()
console.log(`Logged into Discord.\nToken: ${token}`)
}).catch(console.error)
setClient(client)
//#endregion
//#region Firebase Setup
const {
FIREBASE_PROJECT_ID,
FIREBASE_CLIENT_EMAIL,
FIREBASE_PRIVATE_KEY
} = process.env
initializeApp({
credential: cert({
projectId: FIREBASE_PROJECT_ID,
clientEmail: FIREBASE_CLIENT_EMAIL,
privateKey: JSON.parse(JSON.stringify(FIREBASE_PRIVATE_KEY))
})
})
const db = getFirestore()
db.settings({ ignoreUndefinedProperties: true })
setDatabase(db)
//#endregion
//#region Event Handler
const eventFiles = readTsFiles(`bot/events`)
for (const file of eventFiles) {
const eventFile = await import(`./bot/events/${file}`)
const event = eventFile.default as DJSEvent
if (event.once) client.once(event.name, (...args) => event.execute(...args))
else client.on(event.name, (...args) => event.execute(...args))
}
//#endregion
//#region Error Handling
client.on('error', (err: ErrorWithCode) => {
const missingAccess = 50001
const missingPerms = 50013
if (missingPerms || missingAccess) return
console.error(err)
})
process.on('unhandledRejection', (err: ErrorWithCode) => console.error('Unhandled promise rejection: ', err))
process.on('uncaughtException', (err: ErrorWithCode) => {
if (err.code != 50013) console.error('Uncaught Exception!\n', err)
})
//#endregion
//#region ANTI-PING SPAM
const replies = [
"no.", "be fucking patient moron", "I DO NOT CARE", "Do it again, I dare you.",
"^ this guy likes boys", "you have severe brain damage.", "shutup and smd",
"You have been automatically reported to Discord.", "Please hold. Currently doing your mother.",
"imagine being this impatient", "suck. a. dick.", "☝ everyone laugh at this dipshit",
"want something? wait nicely like a good dog", "emc is not that important brother"
]
client.on('messageCreate', async msg => {
const { guild, member, mentions } = msg
if (msg.type == MessageType.Reply) return // Ensure ping and not just replying.
if (guild.id != "966271635894190090") return // Ensure toolkit discord
if (!mentions.has("263377802647175170")) return // Ensure mention is me
if (member.roles.cache.has("966359842417705020")) return // Ensure not editor
await msg.reply(replies[Math.floor(Math.random() * replies.length)])
member.timeout(10 * 60 * 1000)
})
//#endregion