This repository was archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
179 lines (149 loc) · 5.27 KB
/
server.js
File metadata and controls
179 lines (149 loc) · 5.27 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
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
const fs = require("fs");
const Discord = require("discord.js");
const express = require("express");
const app = express();
const DBL = require("dblapi.js");
const client = new Discord.Client({ disableMentions: 'everyone' });
const dbl = new DBL(process.env.BOTGG, client);
const { prefix, status, version } = require("./core/config.json");
const cooldowns = new Discord.Collection();
const util = require("./utils/functions.js");
client.commands = new Discord.Collection();
Object.assign(client, util);
client.util = util;
// useless thing, just for debug
const today = new Date();
const time =
today
.getHours()
.toString()
.padStart(2, "0") +
":" +
today
.getMinutes()
.toString()
.padStart(2, "0") +
":" +
today
.getSeconds()
.toString()
.padStart(2, "0");
const commandCategories = fs.readdirSync("./commands");
for (const category of commandCategories) {
const commands = fs
.readdirSync(`./commands/${category}`)
.filter(file => file.endsWith(".js"));
for (const commandName of commands) {
const command = require(`./commands/${category}/${commandName}`);
command.category = category;
client.commands.set(command.name, command);
}
}
client.on("ready", () => {
console.log("Updated! " + time);
client.user.setPresence({
status: "idle",
activity: {
name: "#HaveFun | Party 4.3",
type: "PLAYING"
}})
});
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.get(mention);
}
}
function getUserFromMentionRegEx(mention) {
const matches = mention.match(/^<@!?(\d+)>$/);
const id = matches[1];
return client.users.get(id);
}
client.on("message", async message => {
if (!message.content.toLowerCase().startsWith(prefix) || message.author.bot)
return;
const withoutPrefix = message.content.slice(2);
const split = withoutPrefix.split(/ +/);
const args = message.content.slice(prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(
cmd => cmd.aliases && cmd.aliases.includes(commandName)
);
if (!command) return;
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 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.channel
.send(
":x: Hey **" +
message.author.username +
",** " +
`Slow Down! You need to wait ${Math.round(
timeLeft
)} more second(s) before reusing the \`${command.name}\` command!`
)
.then(msg => {
msg.delete({timeout: 5000});
});
}
}
timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
try {
if (command.guildOnly && message.channel.type !== "text") {
return message.reply(":x: I can't execute that command here!");
}
if (command.nsfwOnly && !message.channel.nsfw){
return message.reply("<a:p_no:655807081240330245> This command will be shown only on NSFW channels!\nplease mark the channel as NSFW before using it. #BeCompliant")
}
if (command.developerOnly && !["305771483865546752", "391984806638125066"].includes(message.author.id)) {
message.delete();
return message.reply("<a:p_no:655807081240330245> This command is only for developers!")
}
if (command.votersOnly){
if (!(await dbl.hasVoted(message.author.id))){
const lockEmbed = new Discord.MessageEmbed()
.setColor("0xfeb637")
.setTitle("🔒 This command is locked!")
.setDescription("You can **unlock** this command by [voting!](https://top.gg/bot/527625435128004628/vote)")
.setFooter("Party! | can't vote? try p!vote", "https://i.imgur.com/B6QKBgC.png")
.setThumbnail("https://cdn.glitch.com/76b98dfe-b6a5-425a-bd10-be07af6b4014%2Ffinal%20final%20final%20final.gif?v=1601223987756")
return message.reply(lockEmbed)
}
}
command.execute(message, args);
} catch (error) {
const errorEmbed = new Discord.MessageEmbed()
.setColor("#ff0000")
.setTitle(":x: Uh Oh! there was an error!")
.addField(
"please contact the developer",
"Join the support server [Here](https://discord.gg/7Wx3jVD)"
)
.setDescription(error)
.setFooter("Party!", "https://i.imgur.com/B6QKBgC.png");
message.reply(errorEmbed);
}
});
client.login(process.env.DISCORD_BOT_TOKEN)
.then(console.log("Successfully logged in!"));
app.get("/api/stats", function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.json({"guilds": client.guilds.cache.size, });
});
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});