-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
103 lines (91 loc) · 2.72 KB
/
main.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
import * as ngrok from "ngrok";
import dotenv from "dotenv";
import express from "express";
import fetch from "node-fetch";
import { trackPackages } from "./src/tracker.js";
dotenv.config();
const app = express();
app.use(express.json());
async function patchDiscordMessageById(channelId, messageId, newMessage) {
let url = `https://discord.com/api/v10/channels/${channelId}/messages/${messageId}`;
fetch(url, {
method: "PATCH",
headers: {
Authorization: `Bot ${process.env.DISCORD_AUTHTOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ content: newMessage }),
})
.then(console.log("Message Patched"))
.catch((error) => console.error("Error:", error));
}
async function sendDiscordMessage(channelId, message) {
let url = `https://discord.com/api/v10/channels/${channelId}/messages`;
await fetch(url, {
method: "POST",
headers: {
Authorization: `Bot ${process.env.DISCORD_AUTHTOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ content: message }),
})
.then((response) => response.json())
.then((data) => console.log(data));
}
async function patchDiscordMessage(app_id, token, newMessage) {
let url = `https://discord.com/api/webhooks/${app_id}/${token}/messages/@original`;
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: newMessage }),
})
.then(console.log("Message Patched"))
.catch((error) => console.error("Error:", error));
}
async function interact(options) {
console.log(options);
switch (options.command) {
case "bye":
patchDiscordMessage(options.appid, options.token, "You are my friend now");
}
}
app.get("/mini-ryza", (req, res) => {
res.status(200).send("Hello");
console.log("Someone Connected");
const parameters = req.query;
interact(parameters);
});
let options = {
proto: "http",
addr: process.env.NGROK_PORT,
authtoken: process.env.NGROK_TOKEN,
region: "eu",
onStatusChange: (status) => {
//Add Logic
},
onLogEvent: (data) => {
//console.log(data);
},
};
const url = await ngrok.connect(options);
console.log(url);
app.listen(process.env.NGROK_PORT, () => {
console.log(`Server is running on port ${process.env.NGROK_PORT}`);
const postData = {};
postData[process.env.BIN_SECRET] = url;
const headers = {
"Content-Type": "application/json",
"X-Master-Key": process.env.BIN_KEY,
};
fetch(process.env.BIN_URL, {
method: "PUT",
headers: headers,
body: JSON.stringify(postData),
})
.then((response) => response.json())
.then((data) => console.log("Records updated"))
.catch((error) => console.error("Error:", error));
trackPackages();
});