This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
123 lines (93 loc) · 4.73 KB
/
server.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
require('dotenv').config()
const Discord = require('discord.js');
const client = new Discord.Client();
var PREFIX = "$"
client.login(process.env.DISCORDJS_BOT_TOKEN);
client.commands = new Discord.Collection()
// ---------------------------------------------------------------------------------------------------------------------
var api = require('./apiClient.js')
var onReady = require("./commands/onReady.js");
var helpCommand = require("./commands/helpCommand")
var birthday = require("./commands/birthday")
var bdayNotify = require("./commands/bdayNotify")
var roles = require("./commands/roles")
var welcome = require("./commands/welcome")
var dmUser = require("./commands/dmUser")
var profile = require("./commands/profile")
var hacktoberfest = require("./commands/hacktoberfest")
client.commands.set(onReady.name, onReady)
client.commands.set(helpCommand.name, helpCommand)
client.commands.set(birthday.name, birthday)
client.commands.set(bdayNotify.name, bdayNotify)
client.commands.set(roles.name, roles)
client.commands.set(welcome.name, welcome)
client.commands.set(dmUser.name, dmUser)
client.commands.set(profile.name, profile)
client.commands.set(hacktoberfest.name, hacktoberfest)
// ---------------------------------------------------------------------------------------------------------------------
client.once('ready', async () => {
await client.commands.get('/onReady').execute(client)
await client.commands.get('/bdayNotify').execute(client, Discord)
});
client.on('guildMemberAdd', guildMember => {
client.commands.get('/welcome').execute(client, guildMember)
})
client.on('message', (message) => {
if (message.guild && message.content.startsWith('/help')) {
client.commands.get('/helpCommand').execute(message, Discord)
} else if (message.guild === null && !message.author.bot) {
if (message.content.startsWith('/edit-profile')) {
client.commands.get('/profile').execute(message)
} else {
var newEmbed = new Discord.MessageEmbed()
.setColor('#4b9fc3')
.setAuthor(message.author.username, `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}.png`)
.setDescription(message.content)
.setFooter(new Date().toString())
client.channels.cache.get(process.env.TARGET_CHANNEL).send(newEmbed);
}
}
});
client.on('message', async (message) => {
if (message.content.startsWith(PREFIX)) {
if (message.member.roles.cache.find(role => role.id === process.env.PRIORITY_ROLE_01 || role.id === process.env.PRIORITY_ROLE_02)) {
var [CMD_NAME, TARGET_CHANNEL, args] = message.content.trim().substring(PREFIX.length).split(" | ");
TARGET_CHANNEL = TARGET_CHANNEL.replace(/[^0-9\s]/g, '')
if (CMD_NAME === 'bot') {
client.channels.cache.get(TARGET_CHANNEL).send(args);
} else if (CMD_NAME === 'bday') {
await api.getExtUserData(args).then((userData) => {
client.commands.get('/birthday').execute(client, TARGET_CHANNEL, userData)
}).catch((error) => {
console.log(error);
})
} else if (CMD_NAME === 'role') {
client.commands.get('/roles').execute(client, message, TARGET_CHANNEL, args)
} else if (CMD_NAME === 'dm') {
client.commands.get('/dmUser').execute(client, message, TARGET_CHANNEL, args)
} else {
message.reply('\nI think you are using the commands in an invalid format.\nTo check-out the command formats, try: **/help**')
}
} else {
message.reply(`\nYou are not allowed to use this command.\nPlease contact <@&${process.env.PRIORITY_ROLE_01}> for more details.`)
}
}
})
client.on('messageReactionAdd', async (reaction, user) => {
await reaction.fetch();
var { message } = reaction;
await message.fetch();
if (message.channel.id === process.env.HF_CHANNEL && reaction.emoji.name === 'hacktoberfest') {
if (message.guild.member(user).roles.cache.find(role => role.id === process.env.PRIORITY_ROLE_01 || role.id === process.env.PRIORITY_ROLE_02)) {
if (reaction.count === 1) {
client.commands.get('/hacktoberfest').execute(client, message, reaction, user, Discord);
} else {
reaction.users.remove(user.id);
user.send(`This message is already verified by an **X-Men** or the **Server Moderator**.`);
}
} else {
reaction.users.remove(user.id);
user.send(`\nYou are not allowed to use this reaction <#${process.env.HF_CHANNEL}> this channel.`);
}
}
})