forked from hrishike-sh/Carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
332 lines (297 loc) · 9.7 KB
/
index.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
const { Collection, Intents, Client, MessageEmbed } = require('discord.js')
const fs = require('fs')
const shell = require('shelljs')
const mongoose = require('mongoose')
const config = require('./config.json')
require('dotenv').config()
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
let dbURL = process.env.mongopath
mongoose.connect(dbURL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})
client.c = {
commands: new Collection(),
cooldowns: new Collection(),
disabledCommands: [],
slashCommands: new Collection(),
}
client.snipes = {
snipes: new Collection(),
esnipes: new Collection(),
}
client.db = {
afks: [],
afkIgnore: [],
disabledDrops: [],
fighthub: null,
reminders: [],
ars: [],
messages: new Collection(),
censors: [],
}
const skripts = require('./scripts')
client.functions = {
parseAmount: skripts.parseAmount,
dmUser: skripts.dmUser,
getRandom: skripts.getRandom,
sleep: skripts.sleep,
formatTime: skripts.formatTime,
randomHash: skripts.getRandomHash,
}
client.switches = {
commands: true,
slashCommands: true,
}
client.config = config
client.options.allowedMentions = {
roles: [],
parse: ['users'],
}
shell.exec('node deploy.js')
const { cooldowns } = client.c
let commandsRan = 0
const commandFolders = fs.readdirSync('./commands')
const eventFiles = fs
.readdirSync('./events')
.filter((file) => file.endsWith('.js'))
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./commands/${folder}`)
.filter((file) => file.endsWith('.js'))
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`)
client.c.commands.set(command.name, command)
}
}
for (const file of eventFiles) {
const event = require(`./events/${file}`)
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client))
} else {
client.on(event.name, (...args) => event.execute(...args, client))
}
}
const commandFiles = fs
.readdirSync('./slashcommands')
.filter((file) => file.endsWith('.js'))
for (const file of commandFiles) {
const command = require(`./slashcommands/${file}`)
client.c.slashCommands.set(command.data.name, command)
}
process.on('uncaughtException', (err) => {
console.log(err)
})
process.on('unhandledRejection', (err) => {
console.log(err)
})
client.on('ready', async () => {
console.log('Logged in.')
client.emit('tick')
client.user.setActivity({
name: 'banning users',
type: 'dnd',
})
client.db.fighthub = client.guilds.cache.get(config.guildId)
// LOGS
const restartEmbed = new MessageEmbed({
description: `Bot restarted <t:${(new Date() / 1000).toFixed(0)}:R>`,
})
client.channels.cache.get(config.logs.restartLog)?.send({
embeds: [restartEmbed],
})
//LOGS
//AFKS
const afks = require('./database/models/user')
const serverIgnores = require('./database/models/settingsSchema')
let peopleWhoAreAFK = await afks.find({})
peopleWhoAreAFK = peopleWhoAreAFK.filter((u) => u.afk.afk === true)
let channelIgnores = await serverIgnores.find({})
channelIgnores = channelIgnores.filter(
(s) => s.afkIgnore && s.afkIgnore.length > 0
)
for (const channel of channelIgnores) {
client.db.afkIgnore = [...client.db.afkIgnore, ...channel.afkIgnore]
}
for (const afk of peopleWhoAreAFK) {
client.db.afks.push(afk.userId)
}
//AFKS
client.db.disabledDrops = (
await serverIgnores.findOne({ guildID: client.db.fighthub.id })
).disabledDrop
// Reminders
const reminders = require('./database/models/remind')
client.db.reminders = await reminders.find({})
// Reminders
// ARS
const ars = require('./database/models/ar')
client.db.ars = await ars.find({})
// ARS
// CENSORS
let cens = require('./database/models/settingsSchema')
cens = (await cens.findOne({ guildID: client.db.fighthub.id })).censors
.censors
client.db.censors = cens
// CENSORS
// Disabled Commands
let dcommands = (await require('./database/models/command').find()).filter(
(a) => a.disabled
)
dcommands.forEach((val) => {
client.c.disabledCommands.push(val.name)
})
// Disabled Commands
})
client.on('messageCreate', async (message) => {
if (message.channel.id !== '924850662410453042') {
return null
}
await message.react('962407474059694200');
await client.functions.sleep(1250);
await message.react('962407492300705834');
return null;
})
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return
const { commandName } = interaction
const command = client.c.slashCommands.get(commandName)
if (!command) return
if (
!client.switches.slashCommands &&
!client.config.trustedAccess.includes(interaction.user.id)
) {
return interaction.reply({
content: 'Slash Commands are disabled temporarily.',
})
}
if (command.permissions) {
if (!interaction.member.permissions.has(command.permissions)) {
return interaction.reply({
content: `You need the \`${command.permissions.toUpperCase()}\` permission to run this command.`,
ephemeral: true,
})
}
}
try {
await command.execute(interaction, client)
const commandbed = new MessageEmbed()
.setAuthor({
name: interaction.user.tag,
iconURL: interaction.user.displayAvatarURL(),
})
.setTitle(command.data.name)
.setDescription(`**This was a slash command**`)
.addField('Total commands ran', commandsRan.toString(), true)
.addField(
'Server | Channel',
`${interaction.guild.name} | ${interaction.channel} (${interaction.channel.name})`
)
.setTimestamp()
await client.channels.cache.get(config.logs.cmdLogging)?.send({
embeds: [commandbed],
})
commandsRan++
} catch (e) {
console.error(e)
await interaction.reply({
content:
'There was an error executing this command, the devs are notified',
ephemeral: true,
})
}
})
client.on('messageCreate', async (message) => {
if (!message.content.toLowerCase().startsWith(config.prefix)) return
if (message.author.bot) return
const args = message.content.slice(config.prefix.length).trim().split(/ +/g)
const commandName = args.shift().toLowerCase()
const command =
client.c.commands.get(commandName) ||
client.c.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(commandName)
)
if (!command) return
if (client.c.disabledCommands.includes(command.name)) {
return message.reply('This command is temporarily disabled.')
}
if (message.guild && message.guild.id !== config.guildId && command.fhOnly)
return message.reply(
`This command can only be run in FightHub temporarily.`
)
if (
command.disabledChannels &&
command.disabledChannels.includes(message.channel.id)
) {
message.react('❌')
return
}
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Collection())
}
const now = Date.now()
const timestamps = cooldowns.get(command.name)
const cooldownAmount = (command.cooldown || 0) * 1000
if (timestamps.has(message.author.id)) {
const expirationTime =
timestamps.get(message.author.id) + cooldownAmount
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000
return message.reply({
embed: new MessageEmbed()
.setDescription(
`:x: You have to wait for **${Math.ceil(
timeLeft
)} seconds** before running this command again!`
)
.setColor('RED'),
})
}
}
timestamps.set(message.author.id, now)
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount)
if (command.args && !args.length) {
let reply = 'You did not provide any arguments!'
if (command.usage) {
reply += `\nThe proper usage would be: \`${config.prefix}${command.name} ${command.usage}\``
}
return message.reply({
content: reply,
})
}
try {
command.execute(message, args, client)
commandsRan++
const commandbed = new MessageEmbed()
.setAuthor({
name: message.author.tag,
iconURL: message.author.displayAvatarURL(),
})
.setTitle(command.name)
.setDescription(`**Message:** \`${message.content}\``)
.addField('Total commands ran', commandsRan.toString(), true)
.addField(
'Server | Channel',
`${message.guild.name} | ${message.channel} (${message.channel.name})`
)
.setTimestamp()
await client.channels.cache.get(config.logs.cmdLogging)?.send({
embeds: [commandbed],
})
} catch (error) {
console.log(error)
message.reply('An error occured while running this command.')
}
})
client.on('error', (error) => {
console.log(error)
})
client.login(process.env.token)