-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
136 lines (121 loc) · 3.55 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
require('dotenv').config()
const fs = require('fs')
const { Client, Collection, Intents, MessageEmbed } = require('discord.js')
const cron = require('node-cron')
const pendingReview = require('./util/pending-review')
const logAnalytics = require('./util/log-analytics')
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS],
partials: ['MESSAGE']
})
client.commands = new Collection()
const commandFiles = fs
.readdirSync('./commands')
.filter(file => file.endsWith('.js'))
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
client.commands.set(command.data.name, command)
}
client.on('ready', () => {
console.log(`${client.user.tag} is ready!`)
client.channels.cache
.get(process.env.TESTING_CHANNEL_ID)
.send(`${client.user.tag} is ready!`)
client.user.setActivity('discord.genicsblog.com')
cron.schedule(
'0 16 * * *',
() => {
pendingReview(client, false)
},
{
timezone: 'America/Los_Angeles'
}
)
cron.schedule(
'5 0 * * *',
() => {
logAnalytics(client)
},
{
timezone: 'Asia/Colombo'
}
)
})
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return
const command = client.commands.get(interaction.commandName)
if (!command) return
try {
await command.execute(interaction, client)
} catch (error) {
console.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
})
}
})
client.on('messageDelete', async message => {
if (
message.author === undefined ||
message.author === null ||
message.author.bot === true
)
return
const embed = new MessageEmbed()
.setTitle('Message Deleted')
.setColor(randomColor())
.setDescription(
`Message by <@${message.author.id}> deleted in <#${message.channel.id}>`
)
.setTimestamp()
if (message.partial) {
message
.fetch()
.then(fullMessage => {
let content =
fullMessage.content == '' ? 'No content' : fullMessage.content
content += '\n\n'
fullMessage.attachments.forEach(attachment => {
content += attachment.url + '\n'
})
embed.addField('Content', content)
client.channels.cache
.get(process.env.TESTING_CHANNEL_ID)
.send({ embeds: [embed] })
})
.catch(error => {
client.channels.cache
.get(process.env.TESTING_CHANNEL_ID)
.send(`Something went wrong when fetching the message: ${error}`)
})
} else {
let content = message.content == '' ? 'No content' : message.content
content += '\n\n'
message.attachments.forEach(attachment => {
content += attachment.url + '\n'
})
embed.addField('Content', content)
client.channels.cache
.get(process.env.TESTING_CHANNEL_ID)
.send({ embeds: [embed] })
}
})
client.on('guildMemberAdd', member => {
setTimeout(() => {
client.channels.cache
.get(process.env.WELCOME_CHANNEL_ID)
.messages.fetch({ limit: 1 })
.then(messages => {
let message = messages.first()
message.react('🎉')
client.channels.cache
.get(process.env.WELCOME_CHANNEL_ID)
.send(
`Welcome to Genics Blog's Community <@${member.id}>! Please go through <#920200530700169276> to get full access to the server and do introduce yourself in <#912221055244963860> :)`
)
})
.catch(console.error)
}, 500)
})
client.login(process.env.BOT_TOKEN)