Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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(
`[Converted to \`xcancel.com\` for members with no \`x\` account](${alternativeUrl})`,
);
},
};

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