-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
459 lines (459 loc) · 20.3 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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const discord_js_1 = __importStar(require("discord.js"));
const dotenv_1 = __importDefault(require("dotenv"));
const wokcommands_1 = __importDefault(require("wokcommands"));
const path_1 = __importDefault(require("path"));
const noblox_js_1 = __importDefault(require("noblox.js"));
const mongoose_1 = __importDefault(require("mongoose"));
const merits_1 = __importDefault(require("./models/merits"));
const express_1 = __importDefault(require("express"));
const bad_words_1 = __importDefault(require("bad-words"));
const body_parser_1 = __importDefault(require("body-parser"));
const applications_1 = __importDefault(require("./models/applications"));
let port = 5075;
let app = (0, express_1.default)();
let filter = new bad_words_1.default();
const talkedRecently = new Set();
dotenv_1.default.config();
app.use(body_parser_1.default.urlencoded({
extended: true
}));
app.use(body_parser_1.default.json());
//Authentication
app.use((req, res, next) => {
const auth = { login: 'zutureadmin', password: 'Zu7u4eVbXm8o0' };
const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':');
if (login && password && login === auth.login && password === auth.password) {
return next();
}
// Access denied
res.set('WWW-Authenticate', 'Basic realm="401"'); // change this if you want to be a
res.status(401).send('Authentication required.'); // custom message
});
const client = new discord_js_1.default.Client({
intents: [
discord_js_1.Intents.FLAGS.GUILDS,
discord_js_1.Intents.FLAGS.GUILD_MESSAGES,
discord_js_1.Intents.FLAGS.GUILD_PRESENCES,
discord_js_1.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});
client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
(_a = client.user) === null || _a === void 0 ? void 0 : _a.setPresence({ activities: [{ name: 'to Vista Academy', type: "LISTENING" }], status: 'online' });
console.log('The bot is online.');
let primaryGuild = client.guilds.cache.get('973253184137076806');
let errorChannel = primaryGuild.channels.cache.get('973555709537042452');
errorChannel.send({
embeds: [new discord_js_1.MessageEmbed()
.setTitle('Notification')
.setDescription('The bot had just been restarted.')
.setColor('GOLD')
.setTimestamp()
]
});
//const currentUser = await noblox.setCookie(`${process.env["robloxcookie"]}`)
//console.log(`Logged in as ${currentUser.UserName} [${currentUser.UserID}]`)
const wok = new wokcommands_1.default(client, {
// The name of the local folder for your command files
commandsDir: path_1.default.join(__dirname, 'commands'),
testServers: ['973253184137076806'],
// Pass in the new dbOptions
// Pass in your own mongo connection URI
// mongoUri: "mongodb+srv://Vista Academydiscord:Vista Academy314@cluster0.1gt3c.mongodb.net/test"
mongoUri: process.env["dbLink"]
});
}));
var db = mongoose_1.default.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", function () {
console.log("Connection To MongoDB Atlas Successful!");
});
app.get("/", (request, response) => {
var ResponseTable = { status: "Success", app: "Online" };
let primaryGuild = client.guilds.cache.get('973253184137076806');
let errorChannel = primaryGuild.channels.cache.get('973555709537042452');
errorChannel.send({
embeds: [new discord_js_1.MessageEmbed()
.setTitle('Notification')
.setDescription('This is a test message triggered by my API.')
.setColor('AQUA')
.setTimestamp()
]
});
response.status(200).json(ResponseTable);
});
// Admin Log
app.post("/log", (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let actions = request.body.actionLogs;
console.log('Log request received');
for (const action of actions) {
let moderator = action.Moderator;
let actionTaken = action.Action;
let logType = action.Type;
if (logType == 'Moderation') {
let reason = action.Reason;
let target = action.Target;
let primaryGuild = client.guilds.cache.get('973253184137076806');
let logChannel = primaryGuild.channels.cache.get('975429627935866951');
logChannel.send({
embeds: [
new discord_js_1.MessageEmbed()
.setTitle(`Moderation Log`)
.setDescription(`\n Action: ${actionTaken}\nModerator: ${moderator} \nTarget: ${target} \n Reason: ${reason}`)
.setColor('PURPLE')
.setFooter({ text: 'Vista System | Developed by Damien' })
]
});
}
else {
let primaryGuild = client.guilds.cache.get('973253184137076806');
let aMessage = action.Message;
let logChannel = primaryGuild.channels.cache.get('975429627935866951');
logChannel.send({
embeds: [
new discord_js_1.MessageEmbed()
.setTitle(`Action Log`)
.setDescription(`\nAction: ${actionTaken} \nModerator: ${moderator}\nMessage: ${aMessage}`)
.setColor('PURPLE')
.setFooter({ text: 'Vista Academy | Developed by Damien' })
]
});
}
response.status(200).json({ status: 'Success' });
}
}));
const gamebans_1 = __importDefault(require("./models/gamebans"));
// Admin Initialization
app.get('/profile/get/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
let id = Number(req.params.id);
let warnings, usermerits, bans;
let MeritData = yield merits_1.default.findOne({ RobloxUserID: id });
if (MeritData) {
usermerits = MeritData.Merits;
}
else {
yield merits_1.default.create({
RobloxUserID: id,
Merits: 0
});
usermerits = 0;
}
let bandata = yield gamebans_1.default.findOne({ RobloxUserID: id });
if (bandata) {
bans = { reason: bandata.Reason, moderator: yield noblox_js_1.default.getUsernameFromId(bandata.ModeratorUserID) };
}
else {
bans = 'NO_BANS';
}
res.status(200).json({ status: 'Success', merits: usermerits, bans: bans });
}));
app.post('/profile/update/:id', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
let id = Number(req.params.id);
let newmerits = Number(req.body.merits);
let banstate = req.body.banstatus;
let meritCheck = yield merits_1.default.findOne({ RobloxUserID: id });
if (!meritCheck) {
yield merits_1.default.create({
RobloxUserID: id,
Merits: newmerits
});
}
else {
yield merits_1.default.findOneAndUpdate({ RobloxUserID: id }, { Merits: newmerits });
}
if (banstate == true) {
let banTable = req.body.bandata;
let banReason = banTable.reason;
let banModerator = Number(banTable.Moderator);
yield gamebans_1.default.create({
RobloxUserID: id,
Reason: banReason,
ModeratorUserID: banModerator
});
}
res.status(200).json({ status: "success" });
}));
// Applications
app.get('/application/group/:groupid', (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let groupID = request.params.groupid;
let data = yield applications_1.default.findOne({ GroupID: groupID });
if (data) {
if (data.Status == 'Processing' || data.Status == 'Accepted') {
response.status(200).json({ status: 'Not eligible' });
}
else {
response.status(200).json({ status: 'Eligible' });
}
}
else {
response.status(200).json({ status: 'Eligible' });
}
}));
app.get('/application/delete/:appID', (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let appID = request.params.appID;
let data = yield applications_1.default.findById(appID);
if (data) {
if (data.Status == 'Processing') {
response.status(200).json({ status: 'Success!' });
}
else {
yield applications_1.default.findByIdAndDelete(appID);
response.status(200).json({ status: 'Deleted' });
}
}
else {
response.status(200).json({ status: 'Failed' });
}
}));
app.get('/application/user/:userid', (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let UserID = request.params.userid;
let data = yield applications_1.default.find({ RobloxUserID: `${UserID}` });
if (data) {
if (data.length >= 3) {
response.status(200).json({ status: 'Not eligible' });
}
else {
response.status(200).json({ status: 'Eligible' });
}
}
else {
response.status(200).json({ status: 'Eligible' });
}
}));
app.get('/application/get/:UserID', (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let userID = request.params.UserID;
let apps = yield applications_1.default.find({ RobloxUserID: `${userID}` });
if (apps) {
let key = 0;
let appsTable = {};
for (const app of apps) {
let groupData = yield noblox_js_1.default.getGroup(app.GroupID);
let groupName = groupData.name;
appsTable[key] = { id: `${app._id}`, name: groupName, status: app.Status, date: app.Date };
key = key + 1;
if (key == 4) {
break;
}
}
response.status(200).json({ status: 'Applications', table: appsTable });
}
else {
response.status(200).json({ status: 'No application' });
}
}));
app.post("/createApplication", (request, response) => __awaiter(void 0, void 0, void 0, function* () {
let primaryGuild = client.guilds.cache.get('973253184137076806');
let applicationChannel = primaryGuild.channels.cache.get('987397799228370974');
let applicationtype = request.body.Type;
let GroupID = request.body.GroupID;
let discordInvite = request.body.Code;
let answer1 = request.body.Answer1;
let answer2 = request.body.Answer2;
let answer3 = request.body.Answer3;
let answer4 = request.body.Answer4;
let dateString = request.body.Date;
let userID = request.body.UserID;
if (applicationtype == 'Partner') {
if (GroupID == 6034265) {
response.status(200).json({ status: 'Success' });
return;
}
console.log('received application');
console.log(GroupID);
let groupdata = yield noblox_js_1.default.getGroup(GroupID);
if (groupdata) {
let applicationData = yield applications_1.default.create({
Type: 'Partner',
RobloxUserID: `${userID}`,
GroupID: `${GroupID}`,
Status: 'Processing',
Date: `${dateString}`
});
let appicationID = applicationData.id;
let groupName = groupdata.name;
let membercount = groupdata.memberCount;
let description = `\n**Group Link: ** https://www.roblox.com/groups/${GroupID}\n**Group Name: ** ${groupName} \n**Group Member: ${membercount}** \n**Discord Code: https://discord.gg/${discordInvite}** \n**Applicant Username: ** ${yield noblox_js_1.default.getUsernameFromId(userID)}`;
let question1 = '\n \n**Why would you like to form an alliance with Vista Academy?**';
let question2 = '\n**How can this alliance benefit both groups as a whole?**';
let question3 = '\n**What makes your group stand out individually?**';
let question4 = '\n**Who will be representing on behalf of your group?**';
description += question1;
description += `\n${answer1}\n`;
description += question2;
description += `\n${answer2}\n`;
description += question3;
description += `\n${answer3}\n`;
description += question4;
description += `\n${answer4}\n`;
if (filter.isProfane(description)) {
let apptoreject = yield applications_1.default.findById(appicationID);
if (apptoreject) {
yield applications_1.default.findByIdAndUpdate(appicationID, { Status: 'Denied' });
yield applicationChannel.send({
embeds: [
new discord_js_1.MessageEmbed()
.setTitle(`New Application: ${appicationID}`)
.setDescription(description + `\n **THIS APPLICATION IS AUTOMATICALLY REJECTED BY PROFANITY FILTER**`)
.setFooter({ text: 'Vista Academy | Developed by Damien' })
.setColor('RED')
]
});
response.status(200).json({ status: 'Success' });
return;
}
}
else if (answer1.length < 5 || answer2.length < 5 || answer3.length < 5 || answer4.length < 5 || answer1 == answer2 || answer2 == answer3 || answer3 == answer4) {
let apptoreject = yield applications_1.default.findById(appicationID);
if (apptoreject) {
yield applications_1.default.findByIdAndUpdate(appicationID, { Status: 'Denied' });
yield applicationChannel.send({
embeds: [
new discord_js_1.MessageEmbed()
.setTitle(`New Application: ${appicationID}`)
.setDescription(description + `\n **THIS APPLICATION IS AUTOMATICALLY REJECTED BY THE SYSTEM - TROLL APPLICATION**`)
.setFooter({ text: 'Vista Academy | Developed by Damien' })
.setColor('RED')
]
});
response.status(200).json({ status: 'Success' });
return;
}
}
else {
yield applicationChannel.send({
embeds: [
new discord_js_1.MessageEmbed()
.setTitle(`New Application: ${appicationID}`)
.setDescription(description)
.setFooter({ text: 'Vista Academy | Developed by Damien' })
.setColor('AQUA')
]
});
}
}
}
response.status(200).json({ status: 'Success' });
}));
client.on('error', error => {
let primaryGuild = client.guilds.cache.get('973253184137076806');
let errorChannel = primaryGuild.channels.cache.get('973555709537042452');
errorChannel.send({
embeds: [new discord_js_1.MessageEmbed()
.setTitle(error.message)
.setDescription(`${error}`)
.setColor('RED')
.setFooter({ text: 'Vista Academy | Developed by Damien' })
]
});
console.log('Error: ' + error);
throw (error);
});
client.on('messageCreate', (message) => __awaiter(void 0, void 0, void 0, function* () {
if (message.content.length > 5) {
if (message.member) {
if (message.member.user.bot) {
console.log('Member is bot');
}
else {
if (talkedRecently.has(message.author.id)) {
console.log("On cool down");
}
else {
talkedRecently.add(message.author.id);
var RobloxUsername = message.member.displayName;
var RobloxID = yield noblox_js_1.default.getIdFromUsername(RobloxUsername);
if (RobloxID) {
let data = yield merits_1.default.findOne({ RobloxUserID: RobloxID });
if (data) {
yield merits_1.default.findOneAndUpdate({ RobloxUserID: RobloxID }, { Merits: parseInt(data.Merits) + 1 });
}
else {
yield merits_1.default.create({
RobloxUserID: RobloxID,
Merits: 1
});
}
}
setTimeout(() => {
talkedRecently.delete(message.author.id);
console.log("Deleted cooldown");
}, 240000);
}
}
}
}
let msg = message.content;
if (filter.isProfane(msg)) {
let primaryGuild = client.guilds.cache.get('973253184137076806');
yield message.delete();
let errorChannel = primaryGuild.channels.cache.get('973555709537042452');
errorChannel.send({
embeds: [new discord_js_1.MessageEmbed()
.setTitle('Auto-mod')
.setDescription(`Profanity is detected and the message was deleted. \n Message: ${msg}`)
.setColor('BLURPLE')
.setFooter({ text: 'Vista Academy | Developed by Damien' })
.setTimestamp()
]
});
}
}));
client.on('messageDelete', message => {
var _a, _b, _c, _d;
console.log(`A message by ${(_a = message.member) === null || _a === void 0 ? void 0 : _a.user.username} was deleted, but we don't know by who yet.`);
let primaryGuild = client.guilds.cache.get('973253184137076806');
let channel = message.channel;
let channelName = channel.name;
let errorChannel = primaryGuild.channels.cache.get('973555709537042452');
errorChannel.send({
embeds: [new discord_js_1.MessageEmbed()
.setTitle('Message Deleted')
.setDescription(`A message by ${(_b = message.member) === null || _b === void 0 ? void 0 : _b.user.username} also known as ${(_c = message.member) === null || _c === void 0 ? void 0 : _c.displayName} (<@${(_d = message.member) === null || _d === void 0 ? void 0 : _d.id}>) was deleted in ${channelName} (<#${channel.id}>). \n\n ** Message Content: ** ${message.content}`)
.setColor('RED')
.setFooter({ text: 'Vista Academy | Developed by Damien' })
.setTimestamp()
]
});
});
app.listen(port, () => {
console.log('App is online');
});
client.login(process.env.TOKEN);