This repository has been archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
101 lines (80 loc) · 2.26 KB
/
server.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
const express = require("express")
//const { db, userdb } = require("./index")
//const JSONdb = require('simple-json-db');
//const db = new JSONdb('/is-a-dev/storage.json');
//const userdb = new JSONdb('/is-a-dev/storageuser.json');
//const dbemail = new JSONdb('/is-a-dev/storageemail.json');
const { db, userdb, dbemail, pairdb } = require("./database")
const fs = require("fs");
var AES = require("crypto-js/aes");
const multer = require('multer');
const { EmbedBuilder, WebhookClient } = require('discord.js');
const upload = multer();
function readAndServe(path, res) {
fs.readFile(path, function (err, data) {
res.end(data);
})
}
const server = express()
server.use(express.static("public"))
server.all("/", (req, res) => {
res.send("Bot is running!")
})
server.get('/api/user', (req, res) => {
var user = req.query.id;
if (user == undefined) {
res.send("undefined")
}
if (db.has(user)) {
res.send("exists")
}
if (!db.has(user)) {
res.send("available")
}
})
server.get('/login/api', async (req, res) => {
//get params from url
//console.log(req.query);
var id = req.query.user;
var username = req.query.username;
var token = req.query.token;
var user = req.query.user;
var email = req.query.email;
db.set(user, username);
userdb.set(user, token);
dbemail.set(user, email);
})
server.post ('/api/email', upload.none(), (req, res) => {
const body = req.body;
console.log(`From: ${body.from}`);
console.log(`To: ${body.to}`);
console.log(`Subject: ${body.subject}`);
console.log(`Text: ${body.text}`);
// send to discord webhook
const webhookClient = new WebhookClient({ url: process.env.webhook });
const embed = {
"type": "rich",
"title": `Email from: ${body.from}`,
"description": `Subject: ${body.subject}`,
"color": 0x00FFFF,
"fields": [
{
"name": `Message`,
"value": `${body.text}`
}
]
}
webhookClient.send({
content: 'NEW EMAIL',
username: 'IS-A-DEV-TECH-SUPPORT',
avatarURL: 'https://raw.githubusercontent.com/is-a-dev/register/main/media/logo.png',
embeds: [embed],
});
return res.status(200).send();
});
function keepAlive() {
server.listen(3000, () => {
console.log("Server is ready.")
})
}
module.exports = keepAlive