mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +00:00
add charinfo
This commit is contained in:
parent
4f5b2e54a7
commit
a65c324426
@ -59,7 +59,9 @@ export async function translateImpl(
|
||||
files: [
|
||||
{
|
||||
name: `${displaySource}-${displayTarget}.txt`,
|
||||
attachment: `--- From ${displaySource} to ${displayTarget} ---\n${translatedText}`,
|
||||
attachment: Buffer.from(
|
||||
`--- From ${displaySource} to ${displayTarget} ---\n${translatedText}`
|
||||
),
|
||||
},
|
||||
...(attachment ? [attachment] : []),
|
||||
],
|
||||
|
||||
@ -30,7 +30,7 @@ export function buildOcrPayload(
|
||||
files: [
|
||||
{
|
||||
name: "ocr.txt",
|
||||
attachment: text,
|
||||
attachment: Buffer.from(text),
|
||||
},
|
||||
...(attachment ? [attachment] : []),
|
||||
],
|
||||
|
||||
70
src/commands/utility/charinfo.ts
Normal file
70
src/commands/utility/charinfo.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { bold, hyperlink, inlineCode, SlashCommandBuilder } from "discord.js";
|
||||
import { defineCommand } from "..";
|
||||
import { pluralize, shell } from "../../utils/functions";
|
||||
import { abort } from "../../utils/error";
|
||||
|
||||
export default defineCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("charinfo")
|
||||
.setDescription("Unicode character info for given text")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName("text")
|
||||
.setDescription("The text to get info for")
|
||||
.setRequired(true)
|
||||
),
|
||||
|
||||
async execute(interaction) {
|
||||
const text = interaction.options.getString("text", true);
|
||||
const footer = pluralize(text.length, "character");
|
||||
|
||||
const namesResult = await shell({
|
||||
input: text,
|
||||
})`python3 src/scripts/charinfo.py`;
|
||||
if (namesResult.failed) {
|
||||
abort("Failed to get character names");
|
||||
}
|
||||
|
||||
const names = JSON.parse(namesResult.stdout) as string[];
|
||||
|
||||
const description = text
|
||||
.split("")
|
||||
.map((char, i) => {
|
||||
const code = char.codePointAt(0)!.toString(16).toUpperCase();
|
||||
return `${inlineCode(char)} - ${inlineCode(
|
||||
"U+" + code.padStart(4, "0")
|
||||
)} - ${bold(
|
||||
hyperlink(
|
||||
names[i],
|
||||
`http://www.fileformat.info/info/unicode/char/${code}`
|
||||
)
|
||||
)}`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
if (description.length > 4096) {
|
||||
await interaction.reply({
|
||||
files: [
|
||||
{
|
||||
name: "charinfo.md",
|
||||
attachment: Buffer.from(`${description}\n\n${footer}`),
|
||||
},
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
{
|
||||
title: "Character Info",
|
||||
description,
|
||||
color: 0xfefefe,
|
||||
footer: {
|
||||
text: footer,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
14
src/scripts/charinfo.py
Normal file
14
src/scripts/charinfo.py
Normal file
@ -0,0 +1,14 @@
|
||||
import json
|
||||
import sys
|
||||
import unicodedata
|
||||
|
||||
|
||||
text = sys.stdin.read()
|
||||
|
||||
names = []
|
||||
for char in text:
|
||||
names.append(unicodedata.name(char, "Name not found."))
|
||||
|
||||
names = json.dumps(names)
|
||||
|
||||
print(names)
|
||||
Loading…
x
Reference in New Issue
Block a user