Added reddit, catch any errors in native functions

This commit is contained in:
TheEssem 2021-04-26 09:47:03 -05:00
parent 6cecd4b9d6
commit b7fe04c82b
41 changed files with 1630 additions and 1386 deletions

View File

@ -46,6 +46,7 @@ WORKDIR /home/esmBot/.internal
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
COPY ./assets/reddit.ttf /usr/share/fonts/reddit.ttf
RUN fc-cache -fv
COPY --chown=node:node ./package.json package.json

View File

@ -46,6 +46,7 @@ WORKDIR /home/esmBot/.internal
COPY ./assets/caption.otf /usr/share/fonts/caption.otf
COPY ./assets/caption2.ttf /usr/share/fonts/caption2.ttf
COPY ./assets/hbc.ttf /usr/share/fonts/hbc.ttf
COPY ./assets/reddit.ttf /usr/share/fonts/reddit.ttf
RUN fc-cache -fv
COPY --chown=node:node ./package.json package.json

BIN
assets/images/reddit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
assets/reddit.ttf Normal file

Binary file not shown.

View File

@ -0,0 +1,19 @@
const ImageCommand = require("../../classes/imageCommand.js");
const { random } = require("../../utils/misc.js");
const names = ["esmBot", "me_irl", "dankmemes", "hmmm", "gaming", "wholesome", "chonkers", "memes", "funny", "pcmasterrace", "bellybros"];
class RedditCommand extends ImageCommand {
params(args) {
return {
caption: args.length === 0 ? random(names) : args.join(" ").replaceAll("\n", "").replaceAll(" ", "")
};
}
static description = "Adds a Reddit watermark to an image";
static arguments = ["{text}"];
static noText = "you need to provide some text to add a Reddit watermark!";
static command = "reddit";
}
module.exports = RedditCommand;

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Blur(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool sharp = obj.Get("sharp").As<Napi::Boolean>().Value();
@ -44,8 +45,11 @@ Napi::Value Blur(const Napi::CallbackInfo &info) {
writeImages(coalesced.begin(), coalesced.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Blurple(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -43,8 +44,11 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) {
writeImages(blurpled.begin(), blurpled.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Caption(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
@ -63,8 +64,11 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
writeImages(captioned.begin(), captioned.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
@ -61,8 +62,11 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
writeImages(captioned.begin(), captioned.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Circle(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -42,8 +43,11 @@ Napi::Value Circle(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Crop(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -50,8 +51,11 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Explode(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
int amount = obj.Get("amount").As<Napi::Number>().Int32Value();
@ -43,8 +44,11 @@ Napi::Value Explode(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Flag(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string overlay = obj.Get("overlay").As<Napi::String>().Utf8Value();
@ -51,8 +52,11 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Flip(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool flop =
@ -44,8 +45,11 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Freeze(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool loop =
@ -16,8 +17,9 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
int frame =
obj.Has("frame") ? obj.Get("frame").As<Napi::Number>().Int32Value() : -1;
int frame = obj.Has("frame")
? obj.Get("frame").As<Napi::Number>().Int32Value()
: -1;
Blob blob;
@ -38,8 +40,11 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
writeImages(frames.begin(), frames.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -47,8 +48,11 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Globe(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -42,7 +43,8 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
image.roll(Geometry("+" + to_string(width * i / coalesced.size())));
image.composite(overlay, Magick::CenterGravity,
Magick::HardLightCompositeOp);
image.composite(distort, Magick::CenterGravity, Magick::DistortCompositeOp);
image.composite(distort, Magick::CenterGravity,
Magick::DistortCompositeOp);
image.magick("GIF");
mid.push_back(image);
i++;
@ -63,8 +65,11 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
@ -26,8 +27,11 @@ Napi::Value Homebrew(const Napi::CallbackInfo &info) {
image.write(&blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "png");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -21,6 +21,7 @@
#include "mirror.h"
#include "swirl.h"
#include "motivate.h"
#include "reddit.h"
#include "resize.h"
#include "retro.h"
#include "reverse.h"
@ -56,6 +57,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
exports.Set(Napi::String::New(env, "meme"), Napi::Function::New(env, Meme));
exports.Set(Napi::String::New(env, "mirror"), Napi::Function::New(env, Mirror));
exports.Set(Napi::String::New(env, "motivate"), Napi::Function::New(env, Motivate));
exports.Set(Napi::String::New(env, "reddit"), Napi::Function::New(env, Reddit));
exports.Set(Napi::String::New(env, "resize"), Napi::Function::New(env, Resize));
exports.Set(Napi::String::New(env, "retro"), Napi::Function::New(env, Retro));
exports.Set(Napi::String::New(env, "reverse"), Napi::Function::New(env, Reverse));

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Invert(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -44,8 +45,11 @@ Napi::Value Invert(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Jpeg(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
@ -21,8 +22,11 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
image.write(&blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "jpg");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Leak(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -48,8 +49,11 @@ Napi::Value Leak(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Magik(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -44,8 +45,11 @@ Napi::Value Magik(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Meme(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string top = obj.Get("top").As<Napi::String>().Utf8Value();
@ -26,7 +27,8 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
Image bottom_text;
readImages(&frames, path);
coalesceImages(&coalesced, frames.begin(), frames.end());
for_each(coalesced.begin(), coalesced.end(), scaleImage(Geometry(600, 600)));
for_each(coalesced.begin(), coalesced.end(),
scaleImage(Geometry(600, 600)));
top_text.size(Geometry(to_string(coalesced.front().columns())));
top_text.backgroundColor("none");
@ -80,8 +82,11 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Mirror(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool vertical = obj.Has("vertical")
@ -42,11 +43,11 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
for (Image &image : coalesced) {
list<Image> mirrored;
Image final;
image.extent(
Geometry(to_string(vertical ? image.baseColumns()
image.extent(Geometry(to_string(vertical ? image.baseColumns()
: image.baseColumns() / 2) +
"x" +
to_string(vertical ? image.baseRows() / 2 : image.baseRows())),
to_string(vertical ? image.baseRows() / 2
: image.baseRows())),
gravity);
mirrored.push_back(image);
Image mirror = image;
@ -79,8 +80,11 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Motivate(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string top_text = obj.Get("top").As<Napi::String>().Utf8Value();
@ -84,8 +85,11 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

74
natives/reddit.cc Normal file
View File

@ -0,0 +1,74 @@
#include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std;
using namespace Magick;
Napi::Value Reddit(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string text = obj.Get("caption").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
Image watermark;
Image text_image;
readImages(&frames, path);
watermark.read("./assets/images/reddit.png");
text_image.textGravity(Magick::WestGravity);
text_image.font("Roboto");
text_image.fontPointsize(47);
text_image.backgroundColor("none");
text_image.read("pango:<span foreground='white'>" + text + "</span>");
watermark.composite(text_image, Geometry("+375+46"),
Magick::OverCompositeOp);
string query(to_string(frames.front().baseColumns()) + "x");
watermark.scale(Geometry(query));
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image final;
list<Image> to_append;
to_append.push_back(image);
to_append.push_back(watermark);
appendImages(&final, to_append.begin(), to_append.end(), true);
final.repage();
image.magick(type);
final.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(final);
}
optimizeTransparency(mid.begin(), mid.end());
if (type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

8
natives/reddit.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef ESMBOT_NATIVES_REDDIT_H_
#define ESMBOT_NATIVES_REDDIT_H_
#include <napi.h>
Napi::Value Reddit(const Napi::CallbackInfo& info);
#endif

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Resize(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool stretch = obj.Has("stretch")
@ -55,8 +56,11 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Retro(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string line1 = obj.Get("line1").As<Napi::String>().Utf8Value();
string line2 = obj.Get("line2").As<Napi::String>().Utf8Value();
@ -77,8 +78,11 @@ Napi::Value Retro(const Napi::CallbackInfo &info) {
image.write(&blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "png");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Reverse(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool soos =
@ -44,8 +45,11 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
writeImages(coalesced.begin(), coalesced.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "gif");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Scott(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -53,8 +54,11 @@ Napi::Value Scott(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Sonic(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string text = obj.Get("text").As<Napi::String>().Utf8Value();
@ -29,8 +30,11 @@ Napi::Value Sonic(const Napi::CallbackInfo &info) {
image.write(&blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "png");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Speed(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
bool slow =
@ -50,16 +51,18 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
}
for (int i = 0; i < speed - 1; ++i) {
frames.remove_if(
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
frames.remove_if([counter = 0](const auto x) mutable {
return ++counter % 2 == 0;
});
}
}
} else {
int new_delay = slow ? delay * speed : delay / speed;
if (!slow && new_delay <= 1) {
for (int i = 0; i < speed - 1; ++i) {
frames.remove_if(
[counter = 0](const auto x) mutable { return ++counter % 2 == 0; });
frames.remove_if([counter = 0](const auto x) mutable {
return ++counter % 2 == 0;
});
}
} else {
for_each(frames.begin(), frames.end(), animationDelayImage(new_delay));
@ -71,8 +74,11 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
writeImages(frames.begin(), frames.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Spin(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -60,8 +61,11 @@ Napi::Value Spin(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", "gif");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Swirl(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -42,8 +43,11 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Tile(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -56,8 +57,11 @@ Napi::Value Tile(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Trump(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -53,8 +54,11 @@ Napi::Value Trump(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Wall(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -50,8 +51,11 @@ Napi::Value Wall(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -10,14 +10,17 @@ using namespace Magick;
Napi::Value Watermark(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string water = obj.Get("water").As<Napi::String>().Utf8Value();
int gravity = obj.Get("gravity").As<Napi::Number>().Int32Value();
bool resize =
obj.Has("resize") ? obj.Get("resize").As<Napi::Boolean>().Value() : false;
bool append =
obj.Has("append") ? obj.Get("append").As<Napi::Boolean>().Value() : false;
bool resize = obj.Has("resize")
? obj.Get("resize").As<Napi::Boolean>().Value()
: false;
bool append = obj.Has("append")
? obj.Get("append").As<Napi::Boolean>().Value()
: false;
bool mc = obj.Has("mc") ? obj.Get("mc").As<Napi::Boolean>().Value() : false;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
int delay =
@ -76,8 +79,11 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}

View File

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Wdt(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
string path = obj.Get("path").As<Napi::String>().Utf8Value();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
@ -47,8 +48,11 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data",
Napi::Buffer<char>::Copy(env, (char *)blob.data(), blob.length()));
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
}
}