forked from reactiflux/reactibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx-cancel-generator.ts
More file actions
30 lines (27 loc) · 977 Bytes
/
Copy pathx-cancel-generator.ts
File metadata and controls
30 lines (27 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { CHANNELS } from "../constants/channels.js";
import type { ChannelHandlers } from "../types/index.js";
export const TWITTER_REGEX =
/https?:\/\/(?:www\.)?(?:x|twitter)\.com\/\w+\/status\/\d+/i;
const THREAD_CHANNELS = [
CHANNELS.events,
CHANNELS.iBuiltThis,
CHANNELS.iWroteThis,
CHANNELS.techReadsAndNews,
CHANNELS.twitterFeed,
];
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 isThreadChannel = THREAD_CHANNELS.includes(msg.channel.id);
if (!isThreadChannel) {
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;