From f5a0fa5f7c5df31a5896b25ccf0b35965bbe67f8 Mon Sep 17 00:00:00 2001 From: Essem Date: Sat, 23 Oct 2021 13:58:19 -0500 Subject: [PATCH] Catch image load warnings, set message limit to 50, don't crash the bot if .git is missing --- app.js | 3 ++- events/messageCreate.js | 2 -- natives/blur.cc | 9 ++++++++- natives/blurple.cc | 9 ++++++++- natives/caption.cc | 14 ++++++++++++-- natives/caption2.cc | 9 ++++++++- natives/circle.cc | 9 ++++++++- natives/crop.cc | 9 ++++++++- natives/deepfry.cc | 10 ++++++++-- natives/explode.cc | 9 ++++++++- natives/flag.cc | 9 ++++++++- natives/flip.cc | 9 ++++++++- natives/freeze.cc | 9 ++++++++- natives/gamexplain.cc | 9 ++++++++- natives/globe.cc | 9 ++++++++- natives/invert.cc | 9 ++++++++- natives/jpeg.cc | 9 ++++++++- natives/leak.cc | 9 ++++++++- natives/magik.cc | 9 ++++++++- natives/meme.cc | 17 ++++++++++++++--- natives/mirror.cc | 9 ++++++++- natives/motivate.cc | 9 ++++++++- natives/reddit.cc | 9 ++++++++- natives/resize.cc | 9 ++++++++- natives/reverse.cc | 9 ++++++++- natives/scott.cc | 9 ++++++++- natives/snapchat.cc | 15 +++++++++++---- natives/speed.cc | 17 +++++++++++++++-- natives/spin.cc | 9 ++++++++- natives/swirl.cc | 9 ++++++++- natives/tile.cc | 9 ++++++++- natives/trump.cc | 9 ++++++++- natives/uncaption.cc | 9 ++++++++- natives/wall.cc | 9 ++++++++- natives/watermark.cc | 8 +++++++- natives/wdt.cc | 9 ++++++++- natives/whisper.cc | 9 ++++++++- utils/pagination/awaitinteractions.js | 6 +++--- utils/pagination/pagination.js | 2 +- 39 files changed, 305 insertions(+), 50 deletions(-) diff --git a/app.js b/app.js index 49b906a..b80c020 100644 --- a/app.js +++ b/app.js @@ -45,7 +45,7 @@ k {})).stdout.substring(0, 7)}), powered by eris-fleet ${erisFleetVersion} `); } @@ -89,6 +89,7 @@ const Admiral = new Fleet({ repliedUser: true }, guildSubscriptions: false, + messageLimit: 50, intents: [ "guilds", "guildVoiceStates", diff --git a/events/messageCreate.js b/events/messageCreate.js index a0a355d..a065de0 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -122,8 +122,6 @@ export default async (client, cluster, worker, ipc, message) => { case 3: fileSize = 104856616; break; - default: - break; } } if (result.file.length > fileSize) { diff --git a/natives/blur.cc b/natives/blur.cc index 6601a89..4d97e88 100644 --- a/natives/blur.cc +++ b/natives/blur.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Blur(const Napi::CallbackInfo &info) { list frames; list coalesced; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); if (sharp) { diff --git a/natives/blurple.cc b/natives/blurple.cc index 8d91eae..4faab58 100644 --- a/natives/blurple.cc +++ b/natives/blurple.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Blurple(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurpled; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/caption.cc b/natives/caption.cc index 89ed133..c81b1ef 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Caption(const Napi::CallbackInfo &info) { list frames; list coalesced; list captioned; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } size_t width = frames.front().baseColumns(); string query(to_string(width - ((width / 25) * 2)) + "x"); @@ -32,7 +39,10 @@ Napi::Value Caption(const Napi::CallbackInfo &info) { caption_image.alpha(true); caption_image.fontPointsize(width / 13); caption_image.textGravity(Magick::CenterGravity); - caption_image.read("pango:" + caption + ""); + caption_image.read("pango:" + caption + ""); caption_image.extent(Geometry(width, caption_image.rows() + (width / 13)), Magick::CenterGravity); diff --git a/natives/caption2.cc b/natives/caption2.cc index ac3f9a3..8ac2bf5 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -24,7 +25,13 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) { list coalesced; list captioned; Blob caption_blob; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } size_t width = frames.front().baseColumns(); string query(to_string(width - ((width / 25) * 2)) + "x"); diff --git a/natives/circle.cc b/natives/circle.cc index ba51da0..9c4ed34 100644 --- a/natives/circle.cc +++ b/natives/circle.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Circle(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/crop.cc b/natives/crop.cc index 46d6128..fc502b8 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Crop(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/deepfry.cc b/natives/deepfry.cc index 8755f0a..845cc4f 100644 --- a/natives/deepfry.cc +++ b/natives/deepfry.cc @@ -1,8 +1,8 @@ #include #include -#include #include +#include using namespace std; using namespace Magick; @@ -22,7 +22,13 @@ Napi::Value Deepfry(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/explode.cc b/natives/explode.cc index 0d7bf82..3a0323f 100644 --- a/natives/explode.cc +++ b/natives/explode.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Explode(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/flag.cc b/natives/flag.cc index a9c63d0..6b444dd 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Flag(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read(overlay); watermark.alphaChannel(Magick::SetAlphaChannel); watermark.evaluate(Magick::AlphaChannel, Magick::MultiplyEvaluateOperator, diff --git a/natives/flip.cc b/natives/flip.cc index 6d416cd..85117c0 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Flip(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/freeze.cc b/natives/freeze.cc index a22bb9a..731f7a1 100644 --- a/natives/freeze.cc +++ b/natives/freeze.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -56,7 +57,13 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) { Blob blob; list frames; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } size_t frameSize = frames.size(); int framePos = clamp(frame, 0, (int)frameSize); frames.resize(framePos + 1); diff --git a/natives/gamexplain.cc b/natives/gamexplain.cc index 55265e0..4524400 100644 --- a/natives/gamexplain.cc +++ b/natives/gamexplain.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/gamexplain.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/globe.cc b/natives/globe.cc index 645be19..1da0c2b 100644 --- a/natives/globe.cc +++ b/natives/globe.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Globe(const Napi::CallbackInfo &info) { list mid; Image distort; Image overlay; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } distort.read("./assets/images/spheremap.png"); overlay.read("./assets/images/sphere_overlay.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/invert.cc b/natives/invert.cc index c3f453f..7b06a6f 100644 --- a/natives/invert.cc +++ b/natives/invert.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Invert(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for_each(coalesced.begin(), coalesced.end(), negateImage()); diff --git a/natives/jpeg.cc b/natives/jpeg.cc index 23616ca..5194c00 100644 --- a/natives/jpeg.cc +++ b/natives/jpeg.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -24,7 +25,13 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) { list frames; list coalesced; list jpeged; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/leak.cc b/natives/leak.cc index 7590a26..f08c009 100644 --- a/natives/leak.cc +++ b/natives/leak.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Leak(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/leak.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/magik.cc b/natives/magik.cc index dc2f4fd..4fc1f28 100644 --- a/natives/magik.cc +++ b/natives/magik.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Magik(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/meme.cc b/natives/meme.cc index 537aa18..f5d5dc9 100644 --- a/natives/meme.cc +++ b/natives/meme.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -25,7 +26,13 @@ Napi::Value Meme(const Napi::CallbackInfo &info) { list mid; Image top_text; Image bottom_text; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); int width = coalesced.front().columns(); @@ -42,7 +49,9 @@ Napi::Value Meme(const Napi::CallbackInfo &info) { top_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon"); top_text_fill.backgroundColor("black"); top_text_fill.alphaChannel(Magick::ShapeAlphaChannel); - if (dividedWidth > 1) top_text_fill.morphology(Magick::DilateMorphology, "Octagon", dividedWidth); + if (dividedWidth > 1) + top_text_fill.morphology(Magick::DilateMorphology, "Octagon", + dividedWidth); top_text.composite(top_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); @@ -58,7 +67,9 @@ Napi::Value Meme(const Napi::CallbackInfo &info) { bottom_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon"); bottom_text_fill.backgroundColor("black"); bottom_text_fill.alphaChannel(Magick::ShapeAlphaChannel); - if (dividedWidth > 1) bottom_text_fill.morphology(Magick::DilateMorphology, "Octagon", dividedWidth); + if (dividedWidth > 1) + bottom_text_fill.morphology(Magick::DilateMorphology, "Octagon", + dividedWidth); bottom_text.composite(bottom_text_fill, Magick::CenterGravity, Magick::DstOverCompositeOp); } diff --git a/natives/mirror.cc b/natives/mirror.cc index ec1b120..6e2e541 100644 --- a/natives/mirror.cc +++ b/natives/mirror.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -27,7 +28,13 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) { list coalesced; list mid; MagickCore::GravityType gravity; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); if (vertical && first) { diff --git a/natives/motivate.cc b/natives/motivate.cc index aac1bbe..f81804f 100644 --- a/natives/motivate.cc +++ b/natives/motivate.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -25,7 +26,13 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) { list mid; Image top; Image bottom; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); top.size(Geometry("600")); diff --git a/natives/reddit.cc b/natives/reddit.cc index 2e04125..d36a761 100644 --- a/natives/reddit.cc +++ b/natives/reddit.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) { list mid; Image watermark; Image text_image; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/reddit.png"); text_image.textGravity(Magick::WestGravity); diff --git a/natives/resize.cc b/natives/resize.cc index 4f38b2f..4e3f9a5 100644 --- a/natives/resize.cc +++ b/natives/resize.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -26,7 +27,13 @@ Napi::Value Resize(const Napi::CallbackInfo &info) { list frames; list coalesced; list blurred; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/reverse.cc b/natives/reverse.cc index 4f4dc26..bde68f1 100644 --- a/natives/reverse.cc +++ b/natives/reverse.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) { list frames; list coalesced; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); if (soos) { diff --git a/natives/scott.cc b/natives/scott.cc index dba063a..1983ce8 100644 --- a/natives/scott.cc +++ b/natives/scott.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Scott(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/scott.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/snapchat.cc b/natives/snapchat.cc index 925a0a4..a32fdf0 100644 --- a/natives/snapchat.cc +++ b/natives/snapchat.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -13,7 +14,8 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) { Napi::Object obj = info[0].As(); Napi::Buffer data = obj.Get("data").As>(); string caption = obj.Get("caption").As().Utf8Value(); - float pos = obj.Has("pos") ? obj.Get("pos").As().FloatValue() : 0.5; + float pos = + obj.Has("pos") ? obj.Get("pos").As().FloatValue() : 0.5; string type = obj.Get("type").As().Utf8Value(); int delay = obj.Has("delay") ? obj.Get("delay").As().Int32Value() : 0; @@ -24,7 +26,13 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) { list coalesced; list captioned; Blob caption_blob; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } size_t width = frames.front().baseColumns(); size_t height = frames.front().baseRows(); @@ -44,8 +52,7 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) { for (Image &image : coalesced) { list images; - image.composite(caption_image, 0, height * pos, - Magick::OverCompositeOp); + image.composite(caption_image, 0, height * pos, Magick::OverCompositeOp); image.magick(type); image.animationDelay(delay == 0 ? image.animationDelay() : delay); captioned.push_back(image); diff --git a/natives/speed.cc b/natives/speed.cc index bb1ef5e..3e614b7 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -83,7 +84,13 @@ Napi::Value Speed(const Napi::CallbackInfo &info) { Blob blob; list frames; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } for (list::iterator i = frames.begin(); i != frames.end(); ++i) { int index = distance(frames.begin(), i); @@ -126,7 +133,13 @@ Napi::Value Speed(const Napi::CallbackInfo &info) { Blob blob; list frames; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } for (int i = 0; i < speed - 1; ++i) { frames.remove_if([counter = 0](const auto x) mutable { diff --git a/natives/spin.cc b/natives/spin.cc index c3ee8a0..b1d763b 100644 --- a/natives/spin.cc +++ b/natives/spin.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Spin(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); if (type != "gif") { diff --git a/natives/swirl.cc b/natives/swirl.cc index 6fbac67..e1fc555 100644 --- a/natives/swirl.cc +++ b/natives/swirl.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Swirl(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/tile.cc b/natives/tile.cc index 1005cf8..3d45a80 100644 --- a/natives/tile.cc +++ b/natives/tile.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Tile(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/trump.cc b/natives/trump.cc index f0750ab..8ba517f 100644 --- a/natives/trump.cc +++ b/natives/trump.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Trump(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/trump.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 0d6949a..4a30b90 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); Image firstImage = coalesced.front(); diff --git a/natives/wall.cc b/natives/wall.cc index 0edbab5..ae693cd 100644 --- a/natives/wall.cc +++ b/natives/wall.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -21,7 +22,13 @@ Napi::Value Wall(const Napi::CallbackInfo &info) { list frames; list coalesced; list mid; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } coalesceImages(&coalesced, frames.begin(), frames.end()); for (Image &image : coalesced) { diff --git a/natives/watermark.cc b/natives/watermark.cc index 3ecfd40..4b91f69 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -32,7 +32,13 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read(water); if (resize && append) { string query(to_string(frames.front().baseColumns()) + "x"); diff --git a/natives/wdt.cc b/natives/wdt.cc index 9e06d35..5b18317 100644 --- a/natives/wdt.cc +++ b/natives/wdt.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -22,7 +23,13 @@ Napi::Value Wdt(const Napi::CallbackInfo &info) { list coalesced; list mid; Image watermark; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } watermark.read("./assets/images/whodidthis.png"); coalesceImages(&coalesced, frames.begin(), frames.end()); diff --git a/natives/whisper.cc b/natives/whisper.cc index b5f08ca..eb6ca04 100644 --- a/natives/whisper.cc +++ b/natives/whisper.cc @@ -1,6 +1,7 @@ #include #include +#include #include using namespace std; @@ -23,7 +24,13 @@ Napi::Value Whisper(const Napi::CallbackInfo &info) { list coalesced; list captioned; Blob caption_blob; - readImages(&frames, Blob(data.Data(), data.Length())); + try { + readImages(&frames, Blob(data.Data(), data.Length())); + } catch (Magick::WarningCoder &warning) { + cerr << "Coder Warning: " << warning.what() << endl; + } catch (Magick::Warning &warning) { + cerr << "Warning: " << warning.what() << endl; + } size_t width = frames.front().baseColumns(); size_t height = frames.front().baseRows(); diff --git a/utils/pagination/awaitinteractions.js b/utils/pagination/awaitinteractions.js index 1fb1c28..3373a9e 100644 --- a/utils/pagination/awaitinteractions.js +++ b/utils/pagination/awaitinteractions.js @@ -2,10 +2,10 @@ import { EventEmitter } from "events"; class InteractionCollector extends EventEmitter { - constructor(client, message, options = {}) { + constructor(client, message, timeout = 120000) { super(); this.message = message; - this.options = options; + //this.time = timeout; this.ended = false; this.bot = client; this.listener = async (packet) => { @@ -13,7 +13,7 @@ class InteractionCollector extends EventEmitter { await this.verify(packet.d.message, packet.d.data.custom_id, packet.d.id, packet.d.token, packet.d.member ? packet.d.member.user.id : packet.d.user.id); }; this.bot.on("rawWS", this.listener); - if (options.time) setTimeout(() => this.stop("time"), options.time); + setTimeout(() => this.stop("time"), timeout); } async verify(message, interaction, id, token, member) { diff --git a/utils/pagination/pagination.js b/utils/pagination/pagination.js index 77b027e..aebdbec 100644 --- a/utils/pagination/pagination.js +++ b/utils/pagination/pagination.js @@ -72,7 +72,7 @@ export default async (client, message, pages, timeout = 120000) => { }; let currentPage = await client.createMessage(message.channel.id, Object.assign(pages[page], options, pages.length > 1 ? components : {})); if (pages.length > 1) { - const interactionCollector = new InteractionCollector(client, currentPage, { time: timeout }); + const interactionCollector = new InteractionCollector(client, currentPage, timeout); interactionCollector.on("interaction", async (interaction, id, token, member) => { if (member === message.author.id) { switch (interaction) {