import { createRequire } from 'module'; import { Client } from "stoat.js"; const require = createRequire(import.meta.url); let config = {}; try { config = require('./config.json'); } catch { if (process.env.TOKEN && process.env.TOKEN != "TOKEN_HERE") { config.token = process.env.TOKEN; } else { console.error("FATAL: Stoat token required. Either pass it as an environment variable \"TOKEN\", or fill out config.json.default."); process.exit(1); } } const client = new Client(); client.on("error", (err) => { console.error("Client error:", err?.data?.type || err?.type || err); }); function convertURL(url, regex, domain) { const match = url.match(regex); if (match) { console.log(`Converting ${url} to ${domain}`); return `https://${domain}/${match[1]}/status/${match[2]}`; } } client.on("ready", async () => { console.log(`Stoat: Connected as ${client.user?.username}`); if (config.status) { await client.user?.edit({ status: { text: config.status, presence: "Online" } }); } }); client.on("messageCreate", async (message) => { // ignore our own messages if (message.authorId === client.user?.id) return; // if we smell a twitter link, girlcock it! const twitterRegex = /https?:\/\/x\.com\/(.*?)\/status\/(\d+)/; const regexProfile = message.content.match(twitterRegex); if (regexProfile) { const cocklink = convertURL(regexProfile[0], twitterRegex, "girlcockx.com"); try { // send the converted link, crediting the sender (silent to avoid pinging) await message.channel?.sendMessage({ content: `<@${message.authorId}> sent: ${cocklink}`, flags: 1, // silent / suppress notifications }); // delete the original message to prevent embed await message.delete(); } catch (err) { console.error("Link replacement failed: " + (err.stack?.split('\n')[0] || err.message || String(err).split('\n')[0])); } } }); client.loginBot(config.token);