From ae431f625858c8a5ad61488c3fc834dc4fc84987 Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Fri, 6 Feb 2026 12:33:36 +0300 Subject: [PATCH] use apple emoji by default in quote command --- src/commands/quote.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/commands/quote.ts b/src/commands/quote.ts index ba4beca..5f5d91b 100644 --- a/src/commands/quote.ts +++ b/src/commands/quote.ts @@ -2,7 +2,7 @@ import axios from "axios"; import sharp from "sharp"; import emojiRegex from "emoji-regex"; -import {createCanvas, GlobalFonts, type Image as CanvasImage, loadImage, SKRSContext2D} from "@napi-rs/canvas"; +import {createCanvas, GlobalFonts, Image, type Image as CanvasImage, loadImage, SKRSContext2D} from "@napi-rs/canvas"; import {Message, MessageEntity, PhotoSize} from "typescript-telegram-bot-api"; import {Command} from "../base/command"; import {bot, botUser} from "../index"; @@ -84,6 +84,13 @@ export class Quote extends Command { const emojiCache = new Map(); const customEmojiCache = new Map(); +function appleEmojiUrl(emoji: string): string { + const codePoints = [...emoji] + .map(char => char.codePointAt(0)!.toString(16)) + .join("-"); + return `https://cdn.jsdelivr.net/npm/emoji-datasource-apple@15.0.0/img/apple/64/${codePoints}.png`; +} + function githubEmojiUrl(emoji: string): string { const codePoints = [...emoji] .map(char => char.codePointAt(0)!.toString(16)) @@ -97,27 +104,24 @@ function twemojiUrl(emoji: string) { } async function loadEmoji(emoji: string): Promise { - let url = githubEmojiUrl(emoji); - let cached = emojiCache.get(url); - if (cached) return cached; - - try { + const downloadAndCache = async (url: string): Promise => { const res = await axios.get(url, {responseType: "arraybuffer"}); const img = await loadImage(Buffer.from(res.data)); emojiCache.set(url, img); return img; - } catch (e) { - logError(e); + }; - url = twemojiUrl(emoji); - cached = emojiCache.get(url); + const checkIfCached = async (emoji: string, emojiToUrl: (emoji: string) => string): Promise => { + const url = emojiToUrl(emoji); + const cached = emojiCache.get(url); if (cached) return cached; + return await downloadAndCache(emojiToUrl(emoji)); + }; + const sources = [appleEmojiUrl, githubEmojiUrl, twemojiUrl]; + for (const source of sources) { try { - const res = await axios.get(url, {responseType: "arraybuffer"}); - const img = await loadImage(Buffer.from(res.data)); - emojiCache.set(url, img); - return img; + return await checkIfCached(emoji, source); } catch (e) { logError(e); }