mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 02:11:55 +00:00
support forwarded messages in ocr menus, disable glens fallback error reporting
This commit is contained in:
parent
1568439a42
commit
35a95f651e
@ -6,7 +6,7 @@ import {
|
||||
} from "discord.js";
|
||||
import { defineCommand } from "..";
|
||||
import { downloadFile } from "../../utils/http";
|
||||
import { abort, sendErrorAlert } from "../../utils/error";
|
||||
import { abort } 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"));
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
MessageFlags,
|
||||
ModalSubmitInteraction,
|
||||
type ChatInputCommandInteraction,
|
||||
type MessageSnapshot,
|
||||
} from "discord.js";
|
||||
import { abort } from "./error";
|
||||
|
||||
@ -94,15 +95,28 @@ export function getImageUrlFromChatInteraction(
|
||||
}
|
||||
|
||||
export function getImageUrlFromMessage(message: Message): string {
|
||||
function extractImageUrl(message: Message | MessageSnapshot) {
|
||||
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) ||
|
||||
abort("No valid image found!")
|
||||
findFirstUrl(message.content)
|
||||
);
|
||||
}
|
||||
|
||||
if (message.messageSnapshots) {
|
||||
const snapshot = message.messageSnapshots.first();
|
||||
if (snapshot) {
|
||||
const url = extractImageUrl(snapshot);
|
||||
if (url) return url;
|
||||
}
|
||||
}
|
||||
|
||||
console.log("no reference url xddd");
|
||||
|
||||
return extractImageUrl(message) || abort("No valid image found!");
|
||||
}
|
||||
|
||||
export function languageCodeToName(code: string) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user