-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
115 lines (94 loc) · 4.68 KB
/
server.js
File metadata and controls
115 lines (94 loc) · 4.68 KB
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
const Discord = require("discord.js")
const fs = require("fs")
const client = new Discord.Client()
const prefix = 'g!'
const {restrictedCmds, verifiedRoles, cooldownCmds, nonSkycommCmds, adEmbed} = require("./constants.js")
const globalFunctions = require("./globalfunctions.js")
const {dbClient} = require("./mongodb.js")
client.commands = new Discord.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.name, command)
}
const cooldowns = new Discord.Collection()
client.once('ready', () => {
client.user.setActivity("g!help", {type: "WATCHING"})
})
client.on('message', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) if (!message.content.startsWith(prefix.toUpperCase())) return;
//weeds out messages that don't start with the prefix and the author of the message is a bot.
let serverInfo = dbClient.db("skyblockGuide").collection("Settings")
let findServer = await serverInfo.find({"serverID": message.guild.id}).toArray()
let server = findServer[0]
if (server != undefined) {
let rightChannel = false
server.botChannelID.split(",").map(val => {
if (message.channel.id == val) rightChannel = true
})
if (!rightChannel) {
let rightChannels = server.botChannelID.split(",").map(val => val = "<#" + val + "> ").join(",")
message.delete({timeout: 15000})
return message.reply("Wrong channel. Please use " + rightChannels).then(msg => msg.delete({ timeout: globalFunctions.timeToMS("15s")}))
}
}
//wrong channel prevention when server is configured
if (message.member.roles.cache.find(role => role.name == "Guide Locked")) return message.channel.send("You have been locked from suggesting anything.")
//weeds out messages that are sent by users who have been locked for moderation purposes.
var args = message.content.slice(prefix.length).trim().split(/ +/)
var command = args.shift().toLowerCase()
if (command.includes("\n")) {
let splitCmd = command.split("\n")[1]
command = command.split("\n")[0]
args = [splitCmd, ...args]
}
//edge case when a user includes a new line when they enter a cmd
//ex. g!sbsuggest\nMy New suggestion!
if (!cooldowns.has("sbsuggest")) cooldowns.set("sbsuggest", new Discord.Collection())
if (!cooldowns.has("dsuggest")) cooldowns.set("dsuggest", new Discord.Collection())
if (!cooldowns.has("start")) cooldowns.set("start", new Discord.Collection())
const now = Date.now()
try {
let userCmd = client.commands.get(command) || client.commands.find(cmd => cmd.alises && cmd.alises.includes(command))
if (message.guild.id != "587765474297905158" && message.guild.id != "807319824752443472") {
//Remove command restriction on Skycomm (home server) and Test Server (private test server)
if (globalFunctions.checkAliases(nonSkycommCmds, userCmd.name)) {
userCmd.execute(message, args)
} else {
message.channel.send({embed: adEmbed})
//sends message advertising Skycomm.
}
return undefined
}
//protocol when a server is not Skycomm.
if (globalFunctions.checkAliases(cooldownCmds, userCmd.name)) {
const timestamp = cooldowns.get(userCmd.name)
var cooldown = 0
if (message.member.roles.cache.find(role => role.name == "Discord Staff" || role.name == "Discord Management" || role.name == "Contributor")) cooldown = 0
else if (message.member.roles.cache.find(role => globalFunctions.checkAliases(verifiedRoles, role.name))) cooldown = globalFunctions.timeToMS("1m")
else cooldown = globalFunctions.timeToMS("3m")
if (timestamp.has(message.author.id)) {
const expiration = timestamp.get(message.author.id) + cooldown
if (now < expiration) {
let timeLeft = (expiration - now) / 1000
return message.reply("you are still on cooldown for " + timeLeft.toFixed(1) + " seconds.")
}
} else {
timestamp.set(message.author.id, now)
setTimeout(() => timestamp.delete(message.author.id), cooldown)
}
}
//establishes cooldowns
if (globalFunctions.checkAliases(restrictedCmds, userCmd.name)) {
if (message.member.roles.cache.find(role => role.name == "Discord Staff" || role.name == "Discord Management" || role.name == "Contributor")) userCmd.execute(client, message, args)
else message.channel.send("You do not have permission to run this command!")
} else {
userCmd.execute(message, args)
}
//checking roles to allow users with certain roles (Contributor or Discord Staff) to access restrictive commands
} catch (error) {
message.channel.send("There was an error in executing that command. Run `g!help` to see a list of possible commands.")
console.log(error)
}
})
client.login(process.env.botToken)