From 74aad02ea9077237c0adbda3e26ef8c76cc43144 Mon Sep 17 00:00:00 2001 From: Asbed B Date: Thu, 26 Feb 2026 22:06:12 +1100 Subject: [PATCH 1/4] feature implementation --- src/features/xsplay.ts | 30 ++++++++++++++++++++++++++++++ src/index.ts | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 src/features/xsplay.ts diff --git a/src/features/xsplay.ts b/src/features/xsplay.ts new file mode 100644 index 00000000..6e167fbc --- /dev/null +++ b/src/features/xsplay.ts @@ -0,0 +1,30 @@ +import type { ChannelHandlers } from "../types/index.js"; +import { EMBED_COLOR } from "./commands.js"; + +export const TWITTER_REGEX = + /https?:\/\/(?:www\.)?(?:x|twitter)\.com\/\w+\/status\/\d+/i; + +const xCancelGenerator: ChannelHandlers = { + handleMessage: async ({ msg }) => { + const match = TWITTER_REGEX.exec(msg.content); + if (!match || msg.author.bot) return; // Ignore bots to prevent loops + + const [url] = match; + const alternativeUrl = url.replace(/(x|twitter)\.com/i, "xcancel.com"); + await msg.channel.send( + "This `x.com` link has been converted to `xcancel.com` so that server members won't require an account to view content and threads:", + ); + await msg.channel.send({ + embeds: [ + { + title: "View on xCancel", + url: alternativeUrl, + description: `[Original Link](${url})`, + color: EMBED_COLOR, + }, + ], + }); + }, +}; + +export default xCancelGenerator; diff --git a/src/index.ts b/src/index.ts index 4899d6da..4cd760c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,7 @@ import voiceActivity from "./features/voice-activity.js"; import type { ChannelHandlers } from "./types/index.js"; import { scheduleMessages } from "./features/scheduled-messages.js"; import tsPlaygroundLinkShortener from "./features/tsplay.js"; +import xCancelGenerator from "./features/xsplay.js"; import { CHANNELS, initCachedChannels } from "./constants/channels.js"; import { scheduleTask } from "./helpers/schedule.js"; import { discordToken, isProd } from "./helpers/env.js"; @@ -202,6 +203,7 @@ addHandler("*", [ autoban, emojiMod, tsPlaygroundLinkShortener, + xCancelGenerator, troll, ]); From 777666e573340b0b5a1d4ce6407c7bfb55a99cd5 Mon Sep 17 00:00:00 2001 From: Asbed B Date: Thu, 26 Feb 2026 22:49:29 +1100 Subject: [PATCH 2/4] updated file name --- src/features/{xsplay.ts => x-cancel-generator.ts} | 0 src/index.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/features/{xsplay.ts => x-cancel-generator.ts} (100%) diff --git a/src/features/xsplay.ts b/src/features/x-cancel-generator.ts similarity index 100% rename from src/features/xsplay.ts rename to src/features/x-cancel-generator.ts diff --git a/src/index.ts b/src/index.ts index 4cd760c7..74f39ddc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,7 +27,7 @@ import voiceActivity from "./features/voice-activity.js"; import type { ChannelHandlers } from "./types/index.js"; import { scheduleMessages } from "./features/scheduled-messages.js"; import tsPlaygroundLinkShortener from "./features/tsplay.js"; -import xCancelGenerator from "./features/xsplay.js"; +import xCancelGenerator from "./features/x-cancel-generator.js"; import { CHANNELS, initCachedChannels } from "./constants/channels.js"; import { scheduleTask } from "./helpers/schedule.js"; import { discordToken, isProd } from "./helpers/env.js"; From 8c652eaeb7c3ed4ec11453982e82f623d3861c7a Mon Sep 17 00:00:00 2001 From: Asbed B Date: Fri, 27 Feb 2026 09:03:37 +1100 Subject: [PATCH 3/4] supressed original message embed, moved converted link to a standard unfurled link --- src/features/x-cancel-generator.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/features/x-cancel-generator.ts b/src/features/x-cancel-generator.ts index 6e167fbc..c7445a01 100644 --- a/src/features/x-cancel-generator.ts +++ b/src/features/x-cancel-generator.ts @@ -1,5 +1,4 @@ import type { ChannelHandlers } from "../types/index.js"; -import { EMBED_COLOR } from "./commands.js"; export const TWITTER_REGEX = /https?:\/\/(?:www\.)?(?:x|twitter)\.com\/\w+\/status\/\d+/i; @@ -8,22 +7,12 @@ const xCancelGenerator: ChannelHandlers = { handleMessage: async ({ msg }) => { const match = TWITTER_REGEX.exec(msg.content); if (!match || msg.author.bot) return; // Ignore bots to prevent loops - + msg.suppressEmbeds(true); const [url] = match; const alternativeUrl = url.replace(/(x|twitter)\.com/i, "xcancel.com"); await msg.channel.send( - "This `x.com` link has been converted to `xcancel.com` so that server members won't require an account to view content and threads:", + `This \`x.com\` link has been converted to \`xcancel.com\` so that server members won't require an account to view content and threads:\n ${alternativeUrl}`, ); - await msg.channel.send({ - embeds: [ - { - title: "View on xCancel", - url: alternativeUrl, - description: `[Original Link](${url})`, - color: EMBED_COLOR, - }, - ], - }); }, }; From 2dd8aa38031e01a338ed10516592e4e5a3080f33 Mon Sep 17 00:00:00 2001 From: Asbed B Date: Fri, 27 Feb 2026 09:47:35 +1100 Subject: [PATCH 4/4] Updated message to be a md link with simple language. --- src/features/x-cancel-generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/x-cancel-generator.ts b/src/features/x-cancel-generator.ts index c7445a01..f5a069a7 100644 --- a/src/features/x-cancel-generator.ts +++ b/src/features/x-cancel-generator.ts @@ -11,7 +11,7 @@ const xCancelGenerator: ChannelHandlers = { const [url] = match; const alternativeUrl = url.replace(/(x|twitter)\.com/i, "xcancel.com"); await msg.channel.send( - `This \`x.com\` link has been converted to \`xcancel.com\` so that server members won't require an account to view content and threads:\n ${alternativeUrl}`, + `[Converted to \`xcancel.com\` for members with no \`x\` account](${alternativeUrl})`, ); }, };