Created
April 24, 2018 15:57
-
-
Save valiafetisov/30f44c052a9be677a8ab2d88335d6051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var login = require('facebook-chat-api') | |
var config = require('./config.json') | |
var request = require('request') | |
var fs = require('fs') | |
var Jimp = require('jimp') | |
var download = function (uri, filename, callback) { | |
request.head(uri, function (err, res, body) { | |
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback) | |
}) | |
} | |
login({email: config.login, password: config.password}, function (err, bot) { | |
if(err) return console.error(err) | |
bot.listen((err, message) => { | |
if (err) return | |
console.log(message) | |
if ( | |
message.attachments == null || | |
message.attachments[0] == null | |
) return | |
const pictureUrl = message.attachments[0].largePreviewUrl | |
const filePath = './pictures/' + message.attachments[0].name + '.jpg' | |
const editedPath = './pictures/' + message.attachments[0].name + '-processed.jpg' | |
download(pictureUrl, filePath, function () { | |
console.log('downloaded', filePath) | |
Jimp.read(filePath, function (err, image) { | |
if (err) return console.error('err', err) | |
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK).then(function (font) { | |
image | |
.print(font, 0, 0, 'HI THERE', image.bitmap.width) | |
.greyscale() | |
.write(editedPath, () => { | |
bot.sendMessage({ | |
attachment: fs.createReadStream(editedPath) | |
}, message.threadID) | |
}) | |
}) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment