Compare commits

..

No commits in common. "c7e5aca7009e26dac54b36d470e955a8334bb4bf" and "1568439a42cd39914ed1f065409ca448b948866e" have entirely different histories.

2 changed files with 10 additions and 22 deletions

View File

@ -6,7 +6,7 @@ import {
} from "discord.js";
import { defineCommand } from "..";
import { downloadFile } from "../../utils/http";
import { abort } from "../../utils/error";
import { abort, sendErrorAlert } from "../../utils/error";
import { yandexOcr } from "../../utils/yandex";
import sharp from "sharp";
import {
@ -88,7 +88,7 @@ export async function ocrImpl(url: string) {
const result = await lensOcr(compressed)
.catch(err => {
logger.error(err, "Google Lens error, falling back to Yandex");
// sendErrorAlert(err, { mime: type.mime });
sendErrorAlert(err, { mime: type.mime });
return yandexOcr(compressed, type.mime);
})
.catch(() => abort("Failed to OCR the image"));

View File

@ -9,7 +9,6 @@ import {
MessageFlags,
ModalSubmitInteraction,
type ChatInputCommandInteraction,
type MessageSnapshot,
} from "discord.js";
import { abort } from "./error";
@ -95,26 +94,15 @@ export function getImageUrlFromChatInteraction(
}
export function getImageUrlFromMessage(message: Message): string {
function extractImageUrl(message: Message | MessageSnapshot) {
const attachment = message.attachments.first();
const attachment = message.attachments.first();
return (
(attachment?.contentType?.startsWith("image/") && attachment.url) ||
message.embeds[0]?.image?.url ||
message.embeds[0]?.thumbnail?.url ||
findFirstUrl(message.content)
);
}
if (message.messageSnapshots) {
const snapshot = message.messageSnapshots.first();
if (snapshot) {
const url = extractImageUrl(snapshot);
if (url) return url;
}
}
return extractImageUrl(message) || abort("No valid image found!");
return (
(attachment?.contentType?.startsWith("image/") && attachment.url) ||
message.embeds[0]?.image?.url ||
message.embeds[0]?.thumbnail?.url ||
findFirstUrl(message.content) ||
abort("No valid image found!")
);
}
export function languageCodeToName(code: string) {