Skip to content

Commit ca53165

Browse files
authored
feat: Provide users an alternative link to view x threads (#514)
* feature implementation * updated file name * supressed original message embed, moved converted link to a standard unfurled link * Updated message to be a md link with simple language.
1 parent 6bc10c4 commit ca53165

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/features/x-cancel-generator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { ChannelHandlers } from "../types/index.js";
2+
3+
export const TWITTER_REGEX =
4+
/https?:\/\/(?:www\.)?(?:x|twitter)\.com\/\w+\/status\/\d+/i;
5+
6+
const xCancelGenerator: ChannelHandlers = {
7+
handleMessage: async ({ msg }) => {
8+
const match = TWITTER_REGEX.exec(msg.content);
9+
if (!match || msg.author.bot) return; // Ignore bots to prevent loops
10+
msg.suppressEmbeds(true);
11+
const [url] = match;
12+
const alternativeUrl = url.replace(/(x|twitter)\.com/i, "xcancel.com");
13+
await msg.channel.send(
14+
`[Converted to \`xcancel.com\` for members with no \`x\` account](${alternativeUrl})`,
15+
);
16+
},
17+
};
18+
19+
export default xCancelGenerator;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import voiceActivity from "./features/voice-activity.js";
2727
import type { ChannelHandlers } from "./types/index.js";
2828
import { scheduleMessages } from "./features/scheduled-messages.js";
2929
import tsPlaygroundLinkShortener from "./features/tsplay.js";
30+
import xCancelGenerator from "./features/x-cancel-generator.js";
3031
import { CHANNELS, initCachedChannels } from "./constants/channels.js";
3132
import { scheduleTask } from "./helpers/schedule.js";
3233
import { discordToken, isProd } from "./helpers/env.js";
@@ -202,6 +203,7 @@ addHandler("*", [
202203
autoban,
203204
emojiMod,
204205
tsPlaygroundLinkShortener,
206+
xCancelGenerator,
205207
troll,
206208
]);
207209

0 commit comments

Comments
 (0)