mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +00:00
27 lines
869 B
TypeScript
27 lines
869 B
TypeScript
import { ApplicationCommandType, ContextMenuCommandBuilder } from "discord.js";
|
|
import { defineCommand } from "..";
|
|
import { buildOcrPayload, ocrImpl } from "./ocr";
|
|
import { getImageFromAttachmentOrString } from "../../utils/functions";
|
|
|
|
export default defineCommand({
|
|
data: new ContextMenuCommandBuilder()
|
|
.setName("OCR")
|
|
.setType(ApplicationCommandType.Message),
|
|
|
|
async execute(interaction) {
|
|
if (!interaction.isMessageContextMenuCommand()) return;
|
|
|
|
const attachment = interaction.targetMessage.attachments.first();
|
|
const imageUrl = getImageFromAttachmentOrString(
|
|
attachment,
|
|
interaction.targetMessage.content
|
|
);
|
|
|
|
await interaction.deferReply();
|
|
|
|
const { text, language, model } = await ocrImpl(imageUrl);
|
|
const payload = buildOcrPayload(text, language, model);
|
|
await interaction.editReply(payload);
|
|
},
|
|
});
|