mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +00:00
Compare commits
No commits in common. "c7e5aca7009e26dac54b36d470e955a8334bb4bf" and "1568439a42cd39914ed1f065409ca448b948866e" have entirely different histories.
c7e5aca700
...
1568439a42
@ -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 } from "../../utils/error";
|
import { abort, sendErrorAlert } 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,7 +9,6 @@ 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";
|
||||||
|
|
||||||
@ -95,28 +94,17 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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