Ported homebrew, fixed explode
This commit is contained in:
parent
264bcf5425
commit
bf19e24063
5 changed files with 64 additions and 7 deletions
|
@ -5,7 +5,7 @@ exports.run = async (message) => {
|
||||||
message.channel.sendTyping();
|
message.channel.sendTyping();
|
||||||
const image = await require("../utils/imagedetect.js")(message);
|
const image = await require("../utils/imagedetect.js")(message);
|
||||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to explode!`;
|
if (image === undefined) return `${message.author.mention}, you need to provide an image to explode!`;
|
||||||
const buffer = await promisify(magick.explode)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
const buffer = await promisify(magick.explode)(image.path, -1, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
|
||||||
return {
|
return {
|
||||||
file: buffer,
|
file: buffer,
|
||||||
name: `explode.${image.type}`
|
name: `explode.${image.type}`
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
const gm = require("gm").subClass({
|
const magick = require("../build/Release/image.node");
|
||||||
imageMagick: true
|
const { promisify } = require("util");
|
||||||
});
|
|
||||||
|
|
||||||
exports.run = async (message, args) => {
|
exports.run = async (message, args) => {
|
||||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Homebrew Channel edit!`;
|
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Homebrew Channel edit!`;
|
||||||
message.channel.sendTyping();
|
message.channel.sendTyping();
|
||||||
const template = "./assets/images/hbc.png";
|
//const buffer = await gm(template).gravity("Center").font("./assets/hbc.ttf").out("-kerning", "-5").fill("white").pointSize(96).drawText(0, 0, cleanedMessage).bufferPromise("png");
|
||||||
const cleanedMessage = args.join(" ").toLowerCase().replace(/\n/g, " ");
|
const buffer = await promisify(magick.homebrew)(args.join(" ").toLowerCase().replace(/\n/g, " "));
|
||||||
const buffer = await gm(template).gravity("Center").font("./assets/hbc.ttf").out("-kerning", "-5").fill("white").pointSize(96).drawText(0, 0, cleanedMessage).bufferPromise("png");
|
|
||||||
return {
|
return {
|
||||||
file: buffer,
|
file: buffer,
|
||||||
name: "homebrew.png"
|
name: "homebrew.png"
|
||||||
|
|
49
natives/homebrew.cc
Normal file
49
natives/homebrew.cc
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include <napi.h>
|
||||||
|
#include <list>
|
||||||
|
#include <iostream>
|
||||||
|
#include <Magick++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Magick;
|
||||||
|
|
||||||
|
class HomebrewWorker : public Napi::AsyncWorker {
|
||||||
|
public:
|
||||||
|
HomebrewWorker(Napi::Function& callback, string text)
|
||||||
|
: Napi::AsyncWorker(callback), text(text) {}
|
||||||
|
~HomebrewWorker() {}
|
||||||
|
|
||||||
|
void Execute() {
|
||||||
|
Image image;
|
||||||
|
image.read("./assets/images/hbc.png");
|
||||||
|
image.textGravity(Magick::CenterGravity);
|
||||||
|
image.font("./assets/hbc.ttf");
|
||||||
|
image.textKerning(-5);
|
||||||
|
image.fillColor("white");
|
||||||
|
image.fontPointsize(96);
|
||||||
|
image.draw(DrawableText(0, 0, text));
|
||||||
|
image.magick("PNG");
|
||||||
|
image.write(&blob);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnOK() {
|
||||||
|
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string text, type;
|
||||||
|
int delay, wordlength, i, n;
|
||||||
|
size_t bytes, type_size;
|
||||||
|
Blob blob;
|
||||||
|
};
|
||||||
|
|
||||||
|
Napi::Value Homebrew(const Napi::CallbackInfo &info)
|
||||||
|
{
|
||||||
|
Napi::Env env = info.Env();
|
||||||
|
|
||||||
|
string text = info[0].As<Napi::String>().Utf8Value();
|
||||||
|
Napi::Function cb = info[1].As<Napi::Function>();
|
||||||
|
|
||||||
|
HomebrewWorker* explodeWorker = new HomebrewWorker(cb, text);
|
||||||
|
explodeWorker->Queue();
|
||||||
|
return env.Undefined();
|
||||||
|
}
|
8
natives/homebrew.h
Normal file
8
natives/homebrew.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef ESMBOT_NATIVES_HOMEBREW_H_
|
||||||
|
#define ESMBOT_NATIVES_HOMEBREW_H_
|
||||||
|
|
||||||
|
#include <napi.h>
|
||||||
|
|
||||||
|
Napi::Value Homebrew(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
|
#endif
|
|
@ -11,6 +11,7 @@
|
||||||
#include "freeze.h"
|
#include "freeze.h"
|
||||||
#include "gamexplain.h"
|
#include "gamexplain.h"
|
||||||
#include "globe.h"
|
#include "globe.h"
|
||||||
|
#include "homebrew.h"
|
||||||
#include "invert.h"
|
#include "invert.h"
|
||||||
#include "jpeg.h"
|
#include "jpeg.h"
|
||||||
#include "leak.h"
|
#include "leak.h"
|
||||||
|
@ -33,6 +34,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
||||||
exports.Set(Napi::String::New(env, "freeze"), Napi::Function::New(env, Freeze));
|
exports.Set(Napi::String::New(env, "freeze"), Napi::Function::New(env, Freeze));
|
||||||
exports.Set(Napi::String::New(env, "gamexplain"), Napi::Function::New(env, Gamexplain));
|
exports.Set(Napi::String::New(env, "gamexplain"), Napi::Function::New(env, Gamexplain));
|
||||||
exports.Set(Napi::String::New(env, "globe"), Napi::Function::New(env, Globe));
|
exports.Set(Napi::String::New(env, "globe"), Napi::Function::New(env, Globe));
|
||||||
|
exports.Set(Napi::String::New(env, "homebrew"), Napi::Function::New(env, Homebrew));
|
||||||
exports.Set(Napi::String::New(env, "invert"), Napi::Function::New(env, Invert));
|
exports.Set(Napi::String::New(env, "invert"), Napi::Function::New(env, Invert));
|
||||||
exports.Set(Napi::String::New(env, "jpeg"), Napi::Function::New(env, Jpeg));
|
exports.Set(Napi::String::New(env, "jpeg"), Napi::Function::New(env, Jpeg));
|
||||||
exports.Set(Napi::String::New(env, "leak"), Napi::Function::New(env, Leak));
|
exports.Set(Napi::String::New(env, "leak"), Napi::Function::New(env, Leak));
|
||||||
|
|
Loading…
Reference in a new issue