simplify and dedup url convert logic

This commit is contained in:
2025-12-20 06:55:32 -05:00
parent fd349e20fc
commit c36807e2aa

View File

@@ -26,24 +26,23 @@ const swapRow = new ActionRowBuilder()
.setStyle(ButtonStyle.Secondary),
);
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]}`;
}
}
function swapify(url) {
const girlcockRegex = /https?:\/\/girlcockx\.com\/(.*?)\/status\/(\d+)/;
const fxtwitterRegex = /https?:\/\/fxtwitter\.com\/(.*?)\/status\/(\d+)/;
let link = '';
if (url.match(girlcockRegex)) {
const original = url.match(girlcockRegex)[0];
const profile = url.match(girlcockRegex)[1];
const stub = url.match(girlcockRegex)[2];
console.log(`Button: Asked to swap ${url}, fxtwittering it`);
link = `https://fxtwitter.com/${profile}/status/${stub}`;
} else if (url.match(fxtwitterRegex)) {
const original = url.match(fxtwitterRegex)[0];
const profile = url.match(fxtwitterRegex)[1];
const stub = url.match(fxtwitterRegex)[2];
console.log(`Button: Asked to swap ${url}, cocking it again`);
link = `https://girlcockx.com/${profile}/status/${stub}`;
}
return link;
if (url.match(girlcockRegex)) return convertURL(url, girlcockRegex, "fxtwitter.com");
if (url.match(fxtwitterRegex)) return convertURL(url, fxtwitterRegex, "girlcockx.com");
// if we got this far, somethings not right but we'll try twitter before giving up
const twitterRegex = /https?:\/\/x\.com\/(.*?)\/status\/(\d+)/;
if (url.match(twitterRegex)) return convertURL(url, twitterRegex, "girlcockx.com");
return url; // give up, we'll just return the original URL
}
client.on(Events.InteractionCreate, async interaction => {
@@ -69,18 +68,14 @@ client.login(config.token);
client.on(Events.MessageCreate, message => {
// if we smell a twitter link, girlcock it!
const regexProfile = /https?:\/\/x\.com\/(.*?)\/status\/(\d+)/;
if (message.content.match(regexProfile)) {
const original = message.content.match(regexProfile)[0]
const profile = message.content.match(regexProfile)[1]
const stub = message.content.match(regexProfile)[2]
console.log(`Chat: Detected ${original}, girlcocking it!`);
const cocklink = `https://girlcockx.com/${profile}/status/${stub}`
console.log(`Girlcock: Converted to ${cocklink}`)
const twitterRegex = /https?:\/\/x\.com\/(.*?)\/status\/(\d+)/;
const regexProfile = message.content.match(twitterRegex);
if (regexProfile) {
const cocklink = convertURL(regexProfile[0], twitterRegex, "girlcockx.com")
message.channel.send({ content: cocklink, flags: MessageFlags.SuppressNotifications, components: [swapRow] })
message.suppressEmbeds().catch(err =>
// this next bit just cuts down the error to the important part, which will usually end up being "no permissions"
console.error(err.stack?.split('\n')[0] || err.message || String(err).split('\n')[0])
console.error("Removing original embed failed: " + err.stack?.split('\n')[0] || err.message || String(err).split('\n')[0])
)
}