fix: allow bun emojis in update

This commit is contained in:
Jozef Steinhübl 2023-12-31 18:40:34 +01:00
parent 90ce3fd156
commit 0549763a3e
No known key found for this signature in database
GPG key ID: E944BC293F5FF7E7
2 changed files with 12 additions and 3 deletions

View file

@ -2,7 +2,7 @@ import { Message, ButtonStyle } from "lilybird";
import { ActionRow, Button } from "@lilybird/jsx";
import { extname, basename } from "node:path";
import { Event } from "@lilybird/handlers";
import { isBunOnlyLikeMessage, safeSlice } from "../util.ts";
import { getRandomBunEmoji, isBunOnlyLikeMessage, 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;
@ -28,6 +28,12 @@ function handleBunOnlyChannel(message: Message): boolean {
return true;
}
// 1% chance to react with a random bun emoji
if (Math.floor(Math.random() * 100) === 0) {
message.react(getRandomBunEmoji().id, true);
return true;
}
message.react("🐰");
return true;
}

View file

@ -1,6 +1,6 @@
import { Event } from "@lilybird/handlers";
import { PartialMessage } from "lilybird";
import { getRandomBunEmoji } from "src/util.ts";
import { getRandomBunEmoji, isBunOnlyLikeMessage } from "src/util.ts";
export default {
event: "messageUpdate",
@ -12,11 +12,14 @@ export default {
function handleBunOnlyChannel(message: PartialMessage): boolean {
if (message.channelId !== process.env.BUN_ONLY_CHANNEL_ID) return false;
if (message.content !== "bun") {
if (!isBunOnlyLikeMessage(message.content)) {
message.delete();
return true;
}
// check if there's reaction from bot
if (message.reactions?.some((reaction) => reaction.me)) return true;
// 1% chance to react with a random bun emoji
if (Math.floor(Math.random() * 100) === 0) {
message.react(getRandomBunEmoji().id, true);