This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (43 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//External dependencies
var Tesseract = require("tesseract.js");
var Discord = require("discord.js");
request = require('request');
var fs = require("fs");
var Jimp = require("jimp");
var bot = new Discord.Client();
bot.on("message", (message)=>{
if((message.content !== undefined) && (message.author.id !== bot.user.id) && message.content.startsWith("/test")){//message issued (and not issued by the bot itself)
for(attachment of message.attachments.values()){
request({
url: attachment.url,
encoding: null
},
function(error, response, body){
Jimp.read(body)
.then(function (image) {
image
.invert()
.greyscale()
.brightness(-0.3)
.contrast(1);
Tesseract.recognize(image.bitmap)
.then(function(result){
message.channel.send(result.text);
image.write("testong2.png");
})
}).catch(function (err) {
// handle an exception
});
});
}
}
});
bot.login("BOT TOKEN HERE")
.then(function(){
console.log("Login successful");
console.log("Logged in as " + bot.user.tag);
bot.user.setGame("@" + bot.user.username + " help");
})
.catch(function(error){
console.error(error);
});