Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/features/x-cancel-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ChannelHandlers } from "../types/index.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
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:\n ${alternativeUrl}`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about trimming it down further? 👀

Suggested change
`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})`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Done

);
},
};

export default xCancelGenerator;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/x-cancel-generator.js";
import { CHANNELS, initCachedChannels } from "./constants/channels.js";
import { scheduleTask } from "./helpers/schedule.js";
import { discordToken, isProd } from "./helpers/env.js";
Expand Down Expand Up @@ -202,6 +203,7 @@ addHandler("*", [
autoban,
emojiMod,
tsPlaygroundLinkShortener,
xCancelGenerator,
troll,
]);

Expand Down