20 lines
589 B
TypeScript
20 lines
589 B
TypeScript
import { $ } from "bun";
|
|
|
|
export interface DiscordPost {
|
|
webhook: string;
|
|
role_id: string;
|
|
}
|
|
|
|
export const publishDiscord = async (discordPost: DiscordPost, message: string) => {
|
|
console.log("Publishing to Discord");
|
|
const ip = await $`dig +noall +short discord.com @1.1.1.1 A | shuf -n 1`.text();
|
|
return fetch(discordPost.webhook.replace("discord.com", ip), {
|
|
headers: {
|
|
Host: "discord.com"
|
|
},
|
|
method: "POST",
|
|
body: JSON.stringify({ message: `<@${discordPost.role_id}>\n${message}` }),
|
|
tls: { rejectUnauthorized: false }
|
|
}).then((r) => r.status);
|
|
};
|