This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
100 lines (82 loc) · 3.47 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
const express = require('express');
const Discord = require('discord.js');
const fs = require('then-fs');
const client = new Discord.Client();
const app = express();
require('dotenv').config();
const token = process.env.token;
const prefix = process.env.prefix;
client.embedMaker = function embedMaker(author, title, description) {
let embed = new Discord.MessageEmbed();
embed.setColor(process.env.embedColor);
embed.setAuthor(author.tag, author.displayAvatarURL());
embed.setTitle(title);
embed.setDescription(description);
embed.setFooter('Command created by zachariapopcorn#8105 - https://discord.gg/XGGpf3q');
return embed;
}
const commandList = [];
app.get('/', async (request, response) => {
response.sendStatus(200);
});
app.get(`/get-request`, async (request, response) => {
response.status(200).send(client.request);
});
app.post(`/verify-request`, async (request, response) => {
let commandRequest = client.request;
if(commandRequest === "No request") return response.sendStatus(200);
let successStatus = request.headers.success;
let message = request.headers.message;
let channel = client.channels.cache.get(commandRequest.channelID);
if(!channel) {
return response.sendStatus(200);
}
if(successStatus == "true") {
if("moderator" in request.headers) {
channel.send(`<@${commandRequest.authorID}>`);
let embed = client.embedMaker(client.users.cache.get(commandRequest.authorID), "Success", message)
embed.addField("Ban Information", `**Moderator**: ${request.headers.moderator}\n**Reason**: ${request.headers.reason}`);
channel.send(embed);
} else {
channel.send(`<@${commandRequest.authorID}>`);
channel.send(client.embedMaker(client.users.cache.get(commandRequest.authorID), "Success", message));
}
} else {
channel.send(`<@${commandRequest.authorID}>`);
channel.send(client.embedMaker(client.users.cache.get(commandRequest.authorID), "Failure", message));
}
client.request = "No request";
return response.sendStatus(200);
});
let listener = app.listen(process.env.PORT, () => {
console.log(`Your app is currently listening on port: ${listener.address().port}`);
});
async function readCommandFiles() {
let files = await fs.readdir(`./commands`);
for(var i = 0; i < files.length; i++) {
let file = files[i];
if(!file.endsWith(".js")) throw new Error(`Invalid file detected in commands folder, please remove this file for the bot to work: ${file}`);
let coreFile = require(`./commands/${file}`);
commandList.push({
file: coreFile,
name: file.split('.')[0]
});
}
}
client.on('ready', async() => {
console.log(`Logged into the Discord account - ${client.user.tag}`);
await readCommandFiles();
client.request = "No request";
client.commandList = commandList;
});
client.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type == "dm") return;
if(!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).split(" ");
let command = args.shift().toLowerCase();
let index = commandList.findIndex(cmd => cmd.name === command);
if (index == -1) return;
commandList[index].file.run(message, client, args);
});
client.login(token);