4 Commits

Author SHA1 Message Date
melod1n ae431f6258 use apple emoji by default in quote command 2026-02-06 12:33:36 +03:00
melod1n fbbbebaf2e fix emoji naming 2026-02-06 12:20:00 +03:00
melod1n b1dfe93e22 fix regex 2026-02-06 12:05:20 +03:00
melod1n ae428d8415 fix usage of wrong entities if a quote is present 2026-02-06 12:05:11 +03:00
2 changed files with 20 additions and 16 deletions
+19 -15
View File
@@ -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";
@@ -64,7 +64,7 @@ export class Quote extends Command {
const quote = quoteRaw.length ? quoteRaw : "…";
const entities = reply.entities ?? reply.caption_entities ?? [];
const entities = msg.quote ? msg.quote.entities : reply.entities ?? reply.caption_entities ?? [];
const png = await renderQuoteCard(msg, quote, reply, entities);
await bot.sendPhoto({
@@ -85,6 +85,13 @@ const emojiCache = new Map<string, CanvasImage>();
const customEmojiCache = new Map<string, CanvasImage>();
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))
.join("-");
@@ -97,27 +104,24 @@ function twemojiUrl(emoji: string) {
}
async function loadEmoji(emoji: string): Promise<CanvasImage> {
let url = appleEmojiUrl(emoji);
let cached = emojiCache.get(url);
if (cached) return cached;
try {
const downloadAndCache = async (url: string): Promise<Image> => {
const res = await axios.get<ArrayBuffer>(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<CanvasImage> => {
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<ArrayBuffer>(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);
}
+1 -1
View File
@@ -4,7 +4,7 @@ import {logError, oldReplyToMessage, randomValue} from "../util/utils";
import {Environment} from "../common/environment";
export class Test extends Command {
regexp = /^(test|тест|еуые|ntcn|инноке(нтий|ш|нтич))/i;
regexp = /^(test|тест|еуые|ntcn|инноке(нтий|ш|нтич))$/i;
title = "тест";
description = "System functionality check";