mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +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";
|
} from "discord.js";
|
||||||
import { defineCommand } from "..";
|
import { defineCommand } from "..";
|
||||||
import { downloadFile } from "../../utils/http";
|
import { downloadFile } from "../../utils/http";
|
||||||
import { abort, sendErrorAlert } from "../../utils/error";
|
import { abort } from "../../utils/error";
|
||||||
import { yandexOcr } from "../../utils/yandex";
|
import { yandexOcr } from "../../utils/yandex";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import {
|
import {
|
||||||
@ -88,7 +88,7 @@ export async function ocrImpl(url: string) {
|
|||||||
const result = await lensOcr(compressed)
|
const result = await lensOcr(compressed)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error(err, "Google Lens error, falling back to Yandex");
|
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);
|
return yandexOcr(compressed, type.mime);
|
||||||
})
|
})
|
||||||
.catch(() => abort("Failed to OCR the image"));
|
.catch(() => abort("Failed to OCR the image"));
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
MessageFlags,
|
MessageFlags,
|
||||||
ModalSubmitInteraction,
|
ModalSubmitInteraction,
|
||||||
type ChatInputCommandInteraction,
|
type ChatInputCommandInteraction,
|
||||||
|
type MessageSnapshot,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { abort } from "./error";
|
import { abort } from "./error";
|
||||||
|
|
||||||
@ -94,17 +95,30 @@ export function getImageUrlFromChatInteraction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getImageUrlFromMessage(message: Message): string {
|
export function getImageUrlFromMessage(message: Message): string {
|
||||||
|
function extractImageUrl(message: Message | MessageSnapshot) {
|
||||||
const attachment = message.attachments.first();
|
const attachment = message.attachments.first();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(attachment?.contentType?.startsWith("image/") && attachment.url) ||
|
(attachment?.contentType?.startsWith("image/") && attachment.url) ||
|
||||||
message.embeds[0]?.image?.url ||
|
message.embeds[0]?.image?.url ||
|
||||||
message.embeds[0]?.thumbnail?.url ||
|
message.embeds[0]?.thumbnail?.url ||
|
||||||
findFirstUrl(message.content) ||
|
findFirstUrl(message.content)
|
||||||
abort("No valid image found!")
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
export function languageCodeToName(code: string) {
|
||||||
try {
|
try {
|
||||||
return languageNames.of(code);
|
return languageNames.of(code);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user