Merge branch 'master' into image-api-logic

This commit is contained in:
Essem 2021-12-02 18:13:49 -06:00
commit 2644ce2d4a
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
9 changed files with 94 additions and 13 deletions

BIN
assets/images/zamn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

View file

@ -5,7 +5,7 @@ class PingCommand extends Command {
const pingMessage = await this.client.createMessage(this.message.channel.id, Object.assign({ const pingMessage = await this.client.createMessage(this.message.channel.id, Object.assign({
content: "🏓 Ping?" content: "🏓 Ping?"
}, this.reference)); }, this.reference));
return pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - this.message.timestamp}ms${this.message.channel.guild ? `\nShard Latency: ${Math.round(this.client.shards.get(this.client.guildShardMap[this.message.channel.guild.id]).latency)}ms` : ""}\n\`\`\``); pingMessage.edit(`🏓 Pong!\n\`\`\`\nLatency: ${pingMessage.timestamp - this.message.timestamp}ms${this.message.channel.guild ? `\nShard Latency: ${Math.round(this.client.shards.get(this.client.guildShardMap[this.message.channel.guild.id]).latency)}ms` : ""}\n\`\`\``);
} }
static description = "Pings Discord's servers"; static description = "Pings Discord's servers";

View file

@ -0,0 +1,10 @@
import ImageCommand from "../../classes/imageCommand.js";
class ZamnCommand extends ImageCommand {
static description = "Adds a \"ZAMN\" reaction to an image";
static noImage = "You need to provide an image to \"ZAMN\" at!";
static command = "zamn";
}
export default ZamnCommand;

View file

@ -148,6 +148,7 @@
"Something big is coming.", "Something big is coming.",
"This image has expired.", "This image has expired.",
"The GIF File Format", "The GIF File Format",
"Scrimblo Bimblo",
"The clock is ticking." "The clock is ticking."
] ]
} }

View file

@ -38,6 +38,7 @@
#include "watermark.h" #include "watermark.h"
#include "wdt.h" #include "wdt.h"
#include "whisper.h" #include "whisper.h"
#include "zamn.h"
Napi::Object Init(Napi::Env env, Napi::Object exports) Napi::Object Init(Napi::Env env, Napi::Object exports)
{ {
@ -79,7 +80,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
exports.Set(Napi::String::New(env, "watermark"), Napi::Function::New(env, Watermark)); exports.Set(Napi::String::New(env, "watermark"), Napi::Function::New(env, Watermark));
exports.Set(Napi::String::New(env, "wdt"), Napi::Function::New(env, Wdt)); exports.Set(Napi::String::New(env, "wdt"), Napi::Function::New(env, Wdt));
exports.Set(Napi::String::New(env, "whisper"), Napi::Function::New(env, Whisper)); exports.Set(Napi::String::New(env, "whisper"), Napi::Function::New(env, Whisper));
exports.Set(Napi::String::New(env, "zamn"), Napi::Function::New(env, Zamn));
return exports; return exports;
} }
NODE_API_MODULE(addon, Init); NODE_API_MODULE(addon, Init);

62
natives/zamn.cc Normal file
View file

@ -0,0 +1,62 @@
#include <Magick++.h>
#include <napi.h>
#include <list>
using namespace std;
using namespace Magick;
Napi::Value Zamn(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
try {
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
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;
readImages(&frames, Blob(data.Data(), data.Length()));
watermark.read("./assets/images/zamn.png");
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
Image watermark_new = watermark;
image.backgroundColor("none");
image.scale(Geometry("303x438!"));
image.extent(Geometry("621x516-310-75"));
watermark_new.composite(image, Magick::CenterGravity,
Magick::OverCompositeOp);
watermark_new.magick(type);
watermark_new.animationDelay(delay == 0 ? image.animationDelay() : delay);
mid.push_back(watermark_new);
}
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());
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
}
}

5
natives/zamn.h Normal file
View file

@ -0,0 +1,5 @@
#pragma once
#include <napi.h>
Napi::Value Zamn(const Napi::CallbackInfo& info);

21
package-lock.json generated
View file

@ -13,7 +13,7 @@
"cowsay2": "^2.0.4", "cowsay2": "^2.0.4",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"emoji-regex": "^10.0.0", "emoji-regex": "^10.0.0",
"eris": "github:abalabahaha/eris#dev", "eris": "^0.16.1",
"eris-fleet": "github:esmBot/eris-fleet#development", "eris-fleet": "github:esmBot/eris-fleet#development",
"file-type": "^16.1.0", "file-type": "^16.1.0",
"format-duration": "^1.4.0", "format-duration": "^1.4.0",
@ -1138,9 +1138,9 @@
} }
}, },
"node_modules/eris": { "node_modules/eris": {
"version": "0.16.2-dev", "version": "0.16.1",
"resolved": "git+ssh://git@github.com/abalabahaha/eris.git#29a3a635a241a4ab8725c25afa839f29542e1731", "resolved": "https://registry.npmjs.org/eris/-/eris-0.16.1.tgz",
"license": "MIT", "integrity": "sha512-fqjgaddSvUlUjA7s85OvZimLrgCwX58Z6FXOIxdNFJdT6XReJ/LOWZKdew2CaalM8BvN2JKzn98HmKYb3zMhKg==",
"dependencies": { "dependencies": {
"ws": "^8.2.3" "ws": "^8.2.3"
}, },
@ -1153,8 +1153,8 @@
} }
}, },
"node_modules/eris-fleet": { "node_modules/eris-fleet": {
"version": "0.3.9-dev", "version": "0.3.9-dev.0",
"resolved": "git+ssh://git@github.com/esmBot/eris-fleet.git#991e0cf502134d917676ec43c761b584a217878a", "resolved": "git+ssh://git@github.com/esmBot/eris-fleet.git#c9646800a2a6b9259d912f2051d6362860f88098",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"eris": "*" "eris": "*"
@ -4542,8 +4542,9 @@
} }
}, },
"eris": { "eris": {
"version": "git+ssh://git@github.com/abalabahaha/eris.git#29a3a635a241a4ab8725c25afa839f29542e1731", "version": "0.16.1",
"from": "eris@github:abalabahaha/eris#dev", "resolved": "https://registry.npmjs.org/eris/-/eris-0.16.1.tgz",
"integrity": "sha512-fqjgaddSvUlUjA7s85OvZimLrgCwX58Z6FXOIxdNFJdT6XReJ/LOWZKdew2CaalM8BvN2JKzn98HmKYb3zMhKg==",
"requires": { "requires": {
"opusscript": "^0.0.8", "opusscript": "^0.0.8",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
@ -4551,8 +4552,8 @@
} }
}, },
"eris-fleet": { "eris-fleet": {
"version": "git+ssh://git@github.com/esmBot/eris-fleet.git#991e0cf502134d917676ec43c761b584a217878a", "version": "git+ssh://git@github.com/esmBot/eris-fleet.git#c9646800a2a6b9259d912f2051d6362860f88098",
"from": "eris-fleet@github:esmBot/eris-fleet#development", "from": "eris-fleet@esmBot/eris-fleet#development",
"requires": {} "requires": {}
}, },
"erlpack": { "erlpack": {

View file

@ -27,7 +27,7 @@
"cowsay2": "^2.0.4", "cowsay2": "^2.0.4",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"emoji-regex": "^10.0.0", "emoji-regex": "^10.0.0",
"eris": "github:abalabahaha/eris#dev", "eris": "^0.16.1",
"eris-fleet": "github:esmBot/eris-fleet#development", "eris-fleet": "github:esmBot/eris-fleet#development",
"file-type": "^16.1.0", "file-type": "^16.1.0",
"format-duration": "^1.4.0", "format-duration": "^1.4.0",