-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
88 lines (85 loc) · 2.97 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
const bodyParser = require("body-parser");
const express = require("express");
const app = express();
app.use(bodyParser.text());
app.listen(process.env.PORT);
console.log(`💡 Listening on port ${process.env.PORT}`)
const hookcord = require("hookcord");
const Hook = new hookcord.Hook();
Hook.login("758706320994992149", process.env.SECRET);
app.get("/", (request, response) => {
response.send(`Nothing to see here, move along. <br/>See <code>https://scratchaddons.com/feedback</code>`);
});
app.get("/wake_up", (request, response) => {
if (
request.header("Origin") === "https://scratchaddons.com" ||
request.header("Origin").startsWith("http://localhost")
) {
response.header("Access-Control-Allow-Origin", request.header("Origin"));
response.send('Alive')
} else response.status(403).send("403 \nnot allowed");
});
app.post("/send", async (request, response) => {
if (
request.header("Origin") === "https://scratchaddons.com" ||
request.header("Origin").startsWith("http://localhost")
) {
const body = JSON.parse(request.body); //
console.log(body);
Hook.setPayload({
embeds: [
{
title: "<:scratchaddons:757962176572162158> New feedback!",
fields: [
{
name: "Scratch Addons version",
value: body.version || "Unknown",
inline: true,
},
{
name: "Language",
value: body.language || "unknown",
inline: true,
},
{
name: "Username",
value: body.username || "unknown",
inline: true,
},
{
name:
"User agent" +
(body.userAgent.includes("Chrome")
? ` <:chrome:758455448751570984> ${
Number(
body.userAgent.substring(
body.userAgent.indexOf("Chrome/") + 7,
body.userAgent.indexOf("Chrome/") + 9
)
) || ""
}`
: body.userAgent.includes("Firefox")
? ` <:firefox:758455448688001065> ${
Number(
body.userAgent.substring(
body.userAgent.indexOf("Firefox/") + 8,
body.userAgent.indexOf("Firefox/") + 10
)
) || ""
}`
: ""),
value: body.userAgent,
},
],
description:
"```" + body.content.replace(/```/g, "[3 backticks]") + "```",
timestamp: new Date().toISOString(),
color: 16743206,
},
],
});
Hook.fire().catch((err) => console.log(err));
response.header("Access-Control-Allow-Origin", request.header("Origin"));
response.send("sent!");
} else response.status(403).send("403 \nnot allowed");
});