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