2024-02-28 19:40:13 +13:00
|
|
|
const express = require("express")
|
|
|
|
const { Client } = require("discord.js-selfbot-v13");
|
|
|
|
const { readFileSync } = require("node:fs");
|
|
|
|
const cfg = require("./config.json");
|
2024-02-28 19:15:37 +13:00
|
|
|
|
2024-02-28 19:40:13 +13:00
|
|
|
const client = new Client();
|
|
|
|
const app = express();
|
2024-02-28 19:15:37 +13:00
|
|
|
|
|
|
|
let resStream;
|
|
|
|
let channel;
|
|
|
|
|
|
|
|
app.use(express.static("assets"));
|
|
|
|
|
2024-02-28 22:44:05 +13:00
|
|
|
app.get("/send", async (req, res) => {
|
|
|
|
res.redirect(req.headers.referer);
|
|
|
|
channel.send(req.query.content);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get("/channels/:channel", async (req, res) => {
|
2024-02-29 17:05:40 +13:00
|
|
|
channel = await client.channels.fetch(req.params.channel);
|
|
|
|
resStream = res;
|
|
|
|
|
|
|
|
resStream.writeHead(200, {
|
|
|
|
"Content-Type": "text/html",
|
|
|
|
});
|
|
|
|
|
|
|
|
resStream.write(readFileSync("pages/index.html"));
|
2024-02-28 22:44:05 +13:00
|
|
|
(await channel.messages.search()).messages.reverse().each(msg => {
|
|
|
|
resStream.write(constructMessage(msg));
|
|
|
|
});
|
2024-02-28 19:15:37 +13:00
|
|
|
});
|
|
|
|
|
2024-03-02 16:29:42 +13:00
|
|
|
function sanitize(text) {
|
|
|
|
return text.replaceAll("<", "<").replaceAll(">", ">");
|
|
|
|
}
|
|
|
|
|
2024-02-28 19:15:37 +13:00
|
|
|
function constructMessage(msg) {
|
2024-02-29 17:05:40 +13:00
|
|
|
return `<div>
|
2024-03-02 16:29:42 +13:00
|
|
|
<span>${sanitize(msg.author.username)}</span>: ${sanitize(msg.content)}
|
2024-02-29 17:05:40 +13:00
|
|
|
</div>`;
|
2024-02-28 19:15:37 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
client.on("messageCreate", (msg) => {
|
2024-02-29 17:05:40 +13:00
|
|
|
if(!resStream || !channel || msg.channel.id !== channel.id) return;
|
|
|
|
resStream.write(constructMessage(msg));
|
2024-02-28 19:15:37 +13:00
|
|
|
});
|
|
|
|
|
|
|
|
app.listen(cfg.port);
|
|
|
|
client.login(cfg.token);
|