mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-12-21 11:51:05 +01:00
fix: allow bun sticker (#40)
closes https://github.com/xhyrom/bun-discord-bot/issues/39
This commit is contained in:
parent
24451c1fc3
commit
cc50af7396
4 changed files with 24 additions and 9 deletions
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
28
src/util.ts
28
src/util.ts
|
@ -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;
|
||||
|
@ -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}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue