Skip to content

Commit

Permalink
fix: allow bun sticker
Browse files Browse the repository at this point in the history
closes #39
  • Loading branch information
xhyrom committed Nov 8, 2024
1 parent 24451c1 commit e165cb8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const BUN_EMOJIS = [
{ name: "bunpet", id: "1172808445737574591", animated: true },
{ name: "bunsegfault", id: "1175208306533486632", animated: true },
];
export const BUN_STICKER = "994093337080516698";

export const MDN_API = "https://developer.mozilla.org";
export const MDN_DISCORD_EMOJI = "mdn:1236028636826566758";
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/message_create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function handleOthers(message: Message): void {
function handleBunOnlyChannel(message: Message): boolean {
if (message.channelId !== process.env.BUN_ONLY_CHANNEL_ID) return false;

if (!isBunOnlyLikeMessage(message.content)) {
if (!isBunOnlyLikeMessage(message)) {
message.delete();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/message_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $listener({
function handleBunOnlyChannel(message: PartialMessage): boolean {
if (message.channelId !== process.env.BUN_ONLY_CHANNEL_ID) return false;

if (!isBunOnlyLikeMessage(message.content)) {
if (!isBunOnlyLikeMessage(message)) {
message.delete();
return true;
}
Expand Down
28 changes: 21 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GuildMember } from "@lilybird/transformers";
import { BUN_EMOJIS, wolframApiClient } from "./constants.ts";
import { GuildMember, PartialMessage } from "@lilybird/transformers";
import { BUN_EMOJIS, BUN_STICKER, wolframApiClient } from "./constants.ts";
import { parseAndRemap, formatMarkdown } from "bun-tracestrings";

const URL_REGEX = /\(\s*(https?:\/\/[^\s\[\]]+)\s*\)/gi;
Expand Down Expand Up @@ -31,14 +31,28 @@ export async function moderateNick(member: GuildMember) {
);
}

export function isBunOnlyLikeMessage(content?: string) {
if (!content) return false;
if (content === "bun") return true;
export function isBunOnlyLikeMessage(message: PartialMessage) {
// No content or stickers
if (!message.content && message.stickerItems?.length == 0) return false;
// Has attachments
if (message.hasAttachments()) return false;
// Has more than one sticker or a sticker that isn't the bun sticker
if (
message.stickerItems &&
((message.stickerItems.length == 1 &&
message.stickerItems[0].id !== BUN_STICKER) ||
message.stickerItems.length > 1)
)
return false;

// has valid sticker
if (message.stickerItems) return true;
if (message.content === "bun") return true;

return BUN_EMOJIS.some((emoji) =>
emoji.animated
? content.replace(/<a:|>/g, "") == `${emoji.name}:${emoji.id}`
: content.replace(/<:|>/g, "") == `${emoji.name}:${emoji.id}`,
? message.content!.replace(/<a:|>/g, "") == `${emoji.name}:${emoji.id}`
: message.content!.replace(/<:|>/g, "") == `${emoji.name}:${emoji.id}`,
);
}

Expand Down

0 comments on commit e165cb8

Please sign in to comment.