Minty U

Implementation of ocr in 3 languages

1 const Tesseract = require("tesseract.js"); 1 const Tesseract = require("tesseract.js");
2 +const Discord = require("discord.js");
2 exports.run = async (client, msg, args, prefix) => { 3 exports.run = async (client, msg, args, prefix) => {
3 - // msg.channel.send(`${client.user.username}의 핑은 ${client.ws.ping}ms 입니다!`); 4 +
4 if (msg.attachments.size > 0) { 5 if (msg.attachments.size > 0) {
6 + if (args[0] == "한국어" || args[0] == "kor") {
7 + msg.reply("인식중 ...");
8 + msg.attachments.forEach(attachment => {
9 + var ImgURL = attachment.proxyURL;
10 + Tesseract.recognize(
11 + ImgURL,
12 + "kor",
13 + { logger: (m) => console.log(m) }
14 + ).then(({ data: { text } }) => {
15 + // Replying with the extracted test
16 + console.log(text);
17 + let Commands = new Discord.MessageEmbed()
18 + .setTitle("한국어로 문자를 인식한 결과입니다.")
19 + .setColor("81ECEC")
20 + .setDescription(text);
21 +
22 + msg.reply({ embeds: [Commands] });
23 +
24 + });
25 + });
26 + }
27 + else if (args[0] == "영어" || args[0] == "eng" || !args[0]) {
28 + msg.reply("인식중 ...");
5 msg.attachments.forEach(attachment => { 29 msg.attachments.forEach(attachment => {
6 var ImgURL = attachment.proxyURL; 30 var ImgURL = attachment.proxyURL;
7 Tesseract.recognize( 31 Tesseract.recognize(
...@@ -11,13 +35,50 @@ exports.run = async (client, msg, args, prefix) => { ...@@ -11,13 +35,50 @@ exports.run = async (client, msg, args, prefix) => {
11 ).then(({ data: { text } }) => { 35 ).then(({ data: { text } }) => {
12 // Replying with the extracted test 36 // Replying with the extracted test
13 console.log(text); 37 console.log(text);
14 - msg.reply(text); 38 + let Commands = new Discord.MessageEmbed()
39 + .setTitle("영어로 문자를 인식한 결과입니다.")
40 + .setColor("81ECEC")
41 + .setDescription(text);
42 +
43 + msg.reply({ embeds: [Commands] });
15 }); 44 });
45 + });
46 + }
47 + else if (args[0] == "일본어" || args[0] == "jpn") {
48 + msg.reply("인식중 ...");
49 + msg.attachments.forEach(attachment => {
50 + var ImgURL = attachment.proxyURL;
51 + Tesseract.recognize(
52 + ImgURL,
53 + "jpn",
54 + { logger: (m) => console.log(m) }
55 + ).then(({ data: { text } }) => {
56 + // Replying with the extracted test
57 + console.log(text);
58 + let Commands = new Discord.MessageEmbed()
59 + .setTitle("일본어로 문자를 인식한 결과입니다.")
60 + .setColor("81ECEC")
61 + .setDescription(text);
16 62
63 + msg.reply({ embeds: [Commands] });
17 }); 64 });
65 + });
66 + }
67 +
68 + else {
69 + msg.reply("언어가 제대로 입력되지 않았습니다.");
70 + }
71 +
72 +
73 + } else {
74 + msg.reply("이미지가 인식되지 않았습니다. 이미지를 첨부해주세요!");
18 } 75 }
19 }; 76 };
20 77
78 +function kor(attachment) {
79 +
80 +}
81 +
21 exports.config = { 82 exports.config = {
22 name: 'ocr', 83 name: 'ocr',
23 aliases: ['ㅐㅊㄱ'], 84 aliases: ['ㅐㅊㄱ'],
......
This file is too large to display.
This file is too large to display.