added http server for navrhy notifications

This commit is contained in:
Histmy 2021-09-25 15:04:26 +02:00
parent b7740e498f
commit 0ed3dca2c3

View File

@ -46,5 +46,31 @@ module.exports = {
}
return true;
}
},
on_ready: () => {
createServer((req, res) => {
res.statusCode = 400;
if (req.socket.remoteAddress != "::1") return res.end("di doprdele dyk ne more");
const sp = new URL(req.url!, `http://${req.headers.host}`).searchParams;
const { userID, content } = Object.fromEntries(sp.entries());
if (!userID || !content) return res.end("gde mas userID a content????");
const client: Client = module.exports.client;
const user = client.users.cache.get(userID);
if (!user) return res.end("takovyho kkta neznam");
user.createDM().then(async dm => {
await dm.send(content);
res.statusCode = 200;
res.end("OK");
}).catch((e: Error) => {
if (e.message.search("2000 or fewer")) return res.end("content je moc dlouhej");
console.log("error pri posilani upozorneni", e);
res.statusCode = 500;
res.end("neco se posralo");
});
}).listen(1298);
}
};