-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
126 lines (111 loc) · 4.32 KB
/
app.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
const Discord = require('discord.js');
global.Discord = Discord;
const client = new Discord.Client();
global.clie = client;
const http = require("http");
global.http = http;
const https = require("https");
global.https = https;
const fs = require("fs");
global.fs = fs;
const verifyJS = require("./jsfiles/verify.js");
global.verifyJS = verifyJS;
const express = require("express");
global.express = express;
const path = require("path");
global.path = path;
var app = express();
global.app = app;
const downloadImageJS = require("./imageLoader/downloadImage.js");
global.downloadImageJS = downloadImageJS;
const cors = require("cors");
const cookieParser = require("cookie-parser");
const corsOptions = {
origin: JSON.parse(process.env.JSON_ORIGIN),
optionSuccessStatus: 200,
}
app.use(cors(corsOptions));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cookieParser());
var server = app.listen(process.env.PORT || 5000);
var currentVerifying = []
var commandList = []; // in the format of {commandName:___, details:{}}
global.middleware = [];
client.on('ready', () => {
console.log(`Logged in...`);
});
client.on('message', msg => {
for (let middleware of global.middleware) {
msg = middleware(msg, client);
//console.log(msg);
}
if (msg.channel.name == process.env.VERIFY_CHANNEL) {
if (msg.content = "!verify") {
var linkId = verifyJS.verify(msg, client);
app.get(linkId.link, function(req, res) {
res.sendFile("./jsfiles/verify.html", { root: __dirname });
});
app.post(linkId.link, function(req, res) {
console.log("we dun");
var verifiedRole = linkId.msg.member.guild.roles.cache.find(role => role.name === "verified");
linkId.msg.member.roles.add(verifiedRole);
client.channels.cache.get(process.env.GENERAL_CHANNEL_KEY).send(linkId.msg.author.username + " just got verified! welcome!");
});
currentVerifying.push(linkId);
}
} else {
var command = msg.content.split(" ")[0]; //first word
for (var i = 0; i < commandList.length; i++) {
if (command == commandList[i].commandName) {
// check if person has role
var hasPerms = [];
for (var j = 0; j < commandList[i].details.requiredPerms.length; j++) {
if (msg.member.roles.cache.some(role => role.name === commandList[i].details.requiredPerms[j])) {
hasPerms.push(true);
} else {
hasPerms.push(false);
}
}
var canCommand = false;
if (commandList[i].details.requireAllPermsListed == true) {
// all bools in hasPerms must be true
canCommand = hasPerms.every((e) => {
return e == true;
});
} else {
// just need 1 perm
canCommand = hasPerms.some((e) => {
return e == true;
});
}
if (canCommand) {
var params = null;
if (commandList[i].details.paramType === "infi-size") {
params = msg.content.substr(msg.content.indexOf(" ") + 1);
// params now does not have the poll
params = params.split(commandList[i].details.splittingUnit);
}
commandList[i].details.callFunc(params, msg, client);
}
break; // no other commands will match
}
}
}
});
client.login(process.env.BOT_TOKEN);
/*
ADD COMMANDS UNDERNEATH
*/
function loadCommands() {
commandList = commandList.concat(require("./jsfiles/polls.js")());
require("./intercon/intercon.js")(app, client);
commandList = commandList.concat(require("./intercon/intercon-allows.js")());
app.use("/chess", require("./chess/serverSide/chess.js"));
app.use("/game", require("./EGudLogin/EGudMain.js"));
commandList = commandList.concat(require("./dumbMark/dumbMark.js")());
}
loadCommands();
app.get("/", async(req, res) => {
res.send("Welcome to the root directory! there's nothing here :)")
});