feat: bun only channel

This commit is contained in:
Jozef Steinhübl 2023-10-10 10:41:46 +02:00
parent 9af4671f43
commit 7311bc7f61
No known key found for this signature in database
GPG key ID: E944BC293F5FF7E7

View file

@ -7,6 +7,7 @@ import { extname } from "node:path";
import { safeSlice } from "../util.ts"; import { safeSlice } from "../util.ts";
const GITHUB_LINE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?<repo>[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?<path>.+?)#L(?<first_line_number>\d+)[-~]?L?(?<second_line_number>\d*)/i; const GITHUB_LINE_URL_REGEX = /(?:https?:\/\/)?(?:www\.)?(?:github)\.com\/(?<repo>[a-zA-Z0-9-_]+\/[A-Za-z0-9_.-]+)\/blob\/(?<path>.+?)#L(?<first_line_number>\d+)[-~]?L?(?<second_line_number>\d*)/i;
const BUN_ONLY_CHANNEL_ID = "1161157663867027476";
defineListener({ defineListener({
event: Events.MessageCreate, event: Events.MessageCreate,
@ -37,9 +38,23 @@ defineListener({
}); });
function handleOthers(message: Message) { function handleOthers(message: Message) {
if (handleBunOnlyChannel(message)) return;
handleGithubLink(message); handleGithubLink(message);
} }
function handleBunOnlyChannel(message: Message) {
if (message.channel.id !== BUN_ONLY_CHANNEL_ID) return false;
if (message.content !== "bun") {
message.delete();
return true;
}
message.react("🐰");
return true;
}
async function handleGithubLink(message: Message) { async function handleGithubLink(message: Message) {
const match = GITHUB_LINE_URL_REGEX.exec(message.content); const match = GITHUB_LINE_URL_REGEX.exec(message.content);
const groups = match?.groups; const groups = match?.groups;