diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8617eba..eb8fc66 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,24 +2,34 @@ cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)
project(image)
-include_directories(${CMAKE_JS_INC})
+
file(GLOB SOURCE_FILES "natives/*.cc" "natives/*.h")
-add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
-set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
-target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
-target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
-if(MSVC) # todo: change flags for more parity with GCC/clang, I don't know much about MSVC so pull requests are open
-set(CMAKE_CXX_FLAGS "/Wall /EHsc /GS")
-set(CMAKE_CXX_FLAGS_DEBUG "/Zi")
-set(CMAKE_CXX_FLAGS_RELEASE "/Ox")
-set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
-set(BUILD_SHARED_LIBS TRUE)
+
+if (CMAKE_JS_VERSION)
+ include_directories(${CMAKE_JS_INC})
+ add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC} natives/node/image.cc)
+ set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
+ target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
else()
-set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror=format-security -Wno-cast-function-type -fexceptions -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -pedantic -D_GLIBCXX_USE_CXX11_ABI=1")
-set(CMAKE_CXX_FLAGS_DEBUG "-g")
-set(CMAKE_CXX_FLAGS_RELEASE "-O3")
+ add_executable(${PROJECT_NAME} ${SOURCE_FILES} natives/cli/image.cc)
endif()
+target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
+
+if(MSVC) # todo: change flags for more parity with GCC/clang, I don't know much about MSVC so pull requests are open
+ set(CMAKE_CXX_FLAGS "/Wall /EHsc /GS")
+ set(CMAKE_CXX_FLAGS_DEBUG "/Zi")
+ set(CMAKE_CXX_FLAGS_RELEASE "/Ox")
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+ set(BUILD_SHARED_LIBS TRUE)
+else()
+ set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror=format-security -Wno-cast-function-type -fexceptions -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -pedantic -D_GLIBCXX_USE_CXX11_ABI=1")
+ set(CMAKE_CXX_FLAGS_DEBUG "-g")
+ set(CMAKE_CXX_FLAGS_RELEASE "-O2")
+endif()
+
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+
find_package(ImageMagick REQUIRED COMPONENTS Magick++ MagickCore)
add_definitions(-DMAGICKCORE_QUANTUM_DEPTH=16)
add_definitions(-DMAGICKCORE_HDRI_ENABLE=0)
@@ -31,7 +41,7 @@ include_directories(${VIPS_INCLUDE_DIRS})
link_directories(${VIPS_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${VIPS_LDFLAGS})
-if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
+if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET AND CMAKE_JS_VERSION)
# Generate node.lib
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
diff --git a/application.yml b/application.yml
index 744b708..96c4464 100644
--- a/application.yml
+++ b/application.yml
@@ -28,7 +28,7 @@ lavalink:
plugins:
- dependency: "com.github.esmBot:lava-xm-plugin:v0.2.1"
repository: "https://jitpack.io"
- - dependency: "com.github.TopiSenpai.LavaSrc:lavasrc-plugin:3.1.7"
+ - dependency: "com.github.TopiSenpai.LavaSrc:lavasrc-plugin:3.2.0"
repository: "https://jitpack.io"
plugins:
diff --git a/assets/images/scottmap.png b/assets/images/scottmap.png
new file mode 100644
index 0000000..f57e04e
Binary files /dev/null and b/assets/images/scottmap.png differ
diff --git a/classes/imageCommand.js b/classes/imageCommand.js
index a9ba426..554a17b 100644
--- a/classes/imageCommand.js
+++ b/classes/imageCommand.js
@@ -25,7 +25,9 @@ class ImageCommand extends Command {
const imageParams = {
cmd: this.constructor.command,
- params: {},
+ params: {
+ togif: !!this.options.togif
+ },
id: (this.interaction ?? this.message).id
};
@@ -129,6 +131,11 @@ class ImageCommand extends Command {
description: "An image/GIF URL"
});
}
+ this.flags.push({
+ name: "togif",
+ type: 5,
+ description: "Force GIF output"
+ });
return this;
}
diff --git a/commands/general/eval.js b/commands/general/eval.js
index 64e3bea..62b0e1f 100644
--- a/commands/general/eval.js
+++ b/commands/general/eval.js
@@ -17,9 +17,11 @@ class EvalCommand extends Command {
const sendString = `\`\`\`js\n${cleaned}\n\`\`\``;
if (sendString.length >= 2000) {
return {
- text: "The result was too large, so here it is as a file:",
- file: cleaned,
- name: "result.txt"
+ content: "The result was too large, so here it is as a file:",
+ files: [{
+ contents: cleaned,
+ name: "result.txt"
+ }]
};
} else {
return sendString;
diff --git a/commands/general/restart.js b/commands/general/restart.js
index 5f4c496..a39cf2a 100644
--- a/commands/general/restart.js
+++ b/commands/general/restart.js
@@ -7,7 +7,7 @@ class RestartCommand extends Command {
this.success = false;
return "Only the bot owner can restart me!";
}
- await this.message.channel.createMessage(Object.assign({
+ await this.channel.createMessage(Object.assign({
content: "esmBot is restarting."
}, this.reference));
process.exit(1);
diff --git a/commands/image-editing/explode.js b/commands/image-editing/explode.js
index a03bda2..63168f4 100644
--- a/commands/image-editing/explode.js
+++ b/commands/image-editing/explode.js
@@ -1,10 +1,6 @@
import ImageCommand from "../../classes/imageCommand.js";
class ExplodeCommand extends ImageCommand {
- params = {
- amount: -1
- };
-
static description = "Explodes an image";
static aliases = ["exp"];
diff --git a/commands/image-editing/implode.js b/commands/image-editing/implode.js
index 60f9909..1f05b2e 100644
--- a/commands/image-editing/implode.js
+++ b/commands/image-editing/implode.js
@@ -2,7 +2,7 @@ import ImageCommand from "../../classes/imageCommand.js";
class ImplodeCommand extends ImageCommand {
params = {
- amount: 1
+ implode: true
};
static description = "Implodes an image";
diff --git a/config/messages.json b/config/messages.json
index d6d5d25..4c6f16f 100644
--- a/config/messages.json
+++ b/config/messages.json
@@ -128,7 +128,6 @@
"$19 Fortnite Card",
"Wild Woody",
"RDI Halcyon",
- "cry about it",
"KFC",
"Cave Story",
"YouTube ads",
@@ -159,7 +158,6 @@
"Item Asylum",
"TIC-80",
"Ghetto Smosh",
- "brought to you by the DFS project",
"Splatoon 3",
"changed",
"Chutes and Ladders",
@@ -196,6 +194,9 @@
"ANTONBLAST",
"[object Object]",
"Xonotic",
+ "Lario",
+ "Hi-Fi Rush",
+ "Calckey",
"The clock is ticking."
]
}
diff --git a/docs/custom-commands.md b/docs/custom-commands.md
index 1b8b1e7..2cce3e9 100644
--- a/docs/custom-commands.md
+++ b/docs/custom-commands.md
@@ -22,7 +22,7 @@ As you can see, each command is grouped into categories, which are represented b
!!! tip
The `message` category is special; commands in here act as right-click context menu message commands instead of "classic" or slash commands.
-## Commnand Structure
+## Command Structure
It's recommended to use the `Command` class located in `classes/command.js` to create a new command in most cases. This class provides various parameters and fields that will likely be useful when creating a command. Here is a simple example of a working command file:
```js
import Command from "../../classes/command.js";
diff --git a/events/guildCreate.js b/events/guildCreate.js
new file mode 100644
index 0000000..f63ca10
--- /dev/null
+++ b/events/guildCreate.js
@@ -0,0 +1,6 @@
+import { log } from "../utils/logger.js";
+
+// run when the bot is added to a guild
+export default async (client, guild) => {
+ log(`[GUILD JOIN] ${guild.name} (${guild.id}) added the bot.`);
+};
diff --git a/events/voiceChannelLeave.js b/events/voiceChannelLeave.js
index 137b21b..00e8fdf 100644
--- a/events/voiceChannelLeave.js
+++ b/events/voiceChannelLeave.js
@@ -1,6 +1,7 @@
import { players, queues, skipVotes } from "../utils/soundplayer.js";
import AwaitRejoin from "../utils/awaitrejoin.js";
import { random } from "../utils/misc.js";
+import { logger } from "../utils/logger.js";
const isWaiting = new Map();
@@ -16,9 +17,10 @@ export default async (client, member, oldChannel) => {
content: "🔊 Waiting 10 seconds for someone to return..."
});
const awaitRejoin = new AwaitRejoin(oldChannel, true, member.id);
- awaitRejoin.on("end", async (rejoined, newMember) => {
+ awaitRejoin.once("end", async (rejoined, newMember, cancel) => {
isWaiting.delete(oldChannel.id);
if (rejoined) {
+ if (cancel) return;
connection.player.setPaused(false);
if (member.id !== newMember.id) {
players.set(connection.voiceChannel.guildID, { player: connection.player, type: connection.type, host: newMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
@@ -29,19 +31,20 @@ export default async (client, member, oldChannel) => {
try {
await waitMessage.delete();
} catch {
- // no-op
+ logger.warn(`Failed to delete wait message ${waitMessage.id}`);
}
}
} else {
try {
if (waitMessage.channel.messages.has(waitMessage.id)) await waitMessage.delete();
} catch {
- // no-op
+ logger.warn(`Failed to delete wait message ${waitMessage.id}`);
}
+ if (cancel) return;
try {
connection.player.node.leaveChannel(connection.originalChannel.guildID);
} catch {
- // no-op
+ logger.warn(`Failed to leave voice channel ${connection.originalChannel.guildID}`);
}
players.delete(connection.originalChannel.guildID);
queues.delete(connection.originalChannel.guildID);
@@ -58,13 +61,13 @@ export default async (client, member, oldChannel) => {
content: "🔊 Waiting 10 seconds for the host to return..."
});
const awaitRejoin = new AwaitRejoin(oldChannel, false, member.id);
- awaitRejoin.on("end", async (rejoined) => {
+ awaitRejoin.once("end", async (rejoined) => {
isWaiting.delete(oldChannel.id);
if (rejoined) {
try {
if (waitMessage.channel.messages.has(waitMessage.id)) await waitMessage.delete();
} catch {
- // no-op
+ logger.warn(`Failed to delete wait message ${waitMessage.id}`);
}
} else {
const members = oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot);
@@ -72,12 +75,12 @@ export default async (client, member, oldChannel) => {
try {
if (waitMessage.channel.messages.has(waitMessage.id)) await waitMessage.delete();
} catch {
- // no-op
+ logger.warn(`Failed to delete wait message ${waitMessage.id}`);
}
try {
connection.player.node.leaveChannel(connection.originalChannel.guildID);
} catch {
- // no-op
+ logger.warn(`Failed to leave voice channel ${connection.originalChannel.guildID}`);
}
players.delete(connection.originalChannel.guildID);
queues.delete(connection.originalChannel.guildID);
@@ -99,7 +102,7 @@ export default async (client, member, oldChannel) => {
try {
connection.player.node.leaveChannel(connection.originalChannel.guildID);
} catch {
- // no-op
+ logger.warn(`Failed to leave voice channel ${connection.originalChannel.guildID}`);
}
players.delete(connection.originalChannel.guildID);
queues.delete(connection.originalChannel.guildID);
diff --git a/mkdocs.yml b/mkdocs.yml
index b283150..7f68add 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -2,7 +2,7 @@ site_name: esmBot
docs_dir: docs/
repo_name: 'esmBot/esmBot'
repo_url: 'https://github.com/esmBot/esmBot'
-copyright: Copyright © 2018 - 2022 Essem
+copyright: Copyright © 2018 - 2023 Essem
nav:
- Home: index.md
- setup.md
diff --git a/natives/blur.cc b/natives/blur.cc
index 8cdebd4..5347f8e 100644
--- a/natives/blur.cc
+++ b/natives/blur.cc
@@ -7,14 +7,14 @@
using namespace std;
using namespace vips;
-char *Blur(string *type, char *BufferData, size_t BufferLength,
+char *Blur(string type, string *outType, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
bool sharp = GetArgument(Arguments, "sharp");
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
@@ -25,7 +25,7 @@ char *Blur(string *type, char *BufferData, size_t BufferLength,
sharp ? in.sharpen(VImage::option()->set("sigma", 3)) : in.gaussblur(15);
void *buf;
- out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
+ out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
return (char *)buf;
}
diff --git a/natives/blur.h b/natives/blur.h
index 8b017e2..4f4b96d 100644
--- a/natives/blur.h
+++ b/natives/blur.h
@@ -4,5 +4,5 @@
using std::string;
-char* Blur(string* type, char* BufferData, size_t BufferLength,
+char* Blur(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/bounce.cc b/natives/bounce.cc
index 7faad55..e0d27a7 100644
--- a/natives/bounce.cc
+++ b/natives/bounce.cc
@@ -7,28 +7,29 @@
using namespace std;
using namespace vips;
-char *Bounce(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Bounce(string type, string *outType, char *BufferData,
+ size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
+ size_t *DataSize) {
VOption *options = VImage::option();
VImage in =
VImage::new_from_buffer(
BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1)->set("access", "sequential")
- : options)
+ type == "gif" ? options->set("n", -1)->set("access", "sequential")
+ : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
- int nPages = *type == "gif" ? vips_image_get_n_pages(in.get_image()) : 15;
+ int nPages = type == "gif" ? vips_image_get_n_pages(in.get_image()) : 15;
double mult = M_PI / nPages;
int halfHeight = pageHeight / 2;
vector img;
for (int i = 0; i < nPages; i++) {
VImage img_frame =
- *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
+ type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
double height = halfHeight * ((abs(sin(i * mult)) * -1) + 1);
VImage embedded =
img_frame.embed(0, height, width, pageHeight + halfHeight);
@@ -36,7 +37,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength,
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight + halfHeight);
- if (*type != "gif") {
+ if (type != "gif") {
vector delay(30, 50);
final.set("delay", delay);
}
@@ -44,7 +45,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(".gif", &buf, DataSize);
- *type = "gif";
+ *outType = "gif";
return (char *)buf;
}
\ No newline at end of file
diff --git a/natives/bounce.h b/natives/bounce.h
index 44a329f..0ea273a 100644
--- a/natives/bounce.h
+++ b/natives/bounce.h
@@ -4,5 +4,5 @@
using std::string;
-char* Bounce(string* type, char* BufferData, size_t BufferLength,
+char* Bounce(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/caption.cc b/natives/caption.cc
index d1824af..1979c4f 100644
--- a/natives/caption.cc
+++ b/natives/caption.cc
@@ -6,8 +6,8 @@
using namespace std;
using namespace vips;
-char *Caption(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Caption(string type, string *outType, char *BufferData,
+ size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
string caption = GetArgument(Arguments, "caption");
string font = GetArgument(Arguments, "font");
string basePath = GetArgument(Arguments, "basePath");
@@ -16,7 +16,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength,
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
@@ -57,7 +57,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength,
vector img;
for (int i = 0; i < nPages; i++) {
VImage img_frame =
- *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
+ type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage frame = captionImage.join(
img_frame, VIPS_DIRECTION_VERTICAL,
VImage::option()->set("background", 0xffffff)->set("expand", true));
@@ -68,9 +68,10 @@ char *Caption(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(
- ("." + *type).c_str(), &buf, DataSize,
- *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
- : 0);
+ ("." + *outType).c_str(), &buf, DataSize,
+ *outType == "gif"
+ ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
+ : 0);
return (char *)buf;
}
diff --git a/natives/caption.h b/natives/caption.h
index a84ccb1..6ff73c1 100644
--- a/natives/caption.h
+++ b/natives/caption.h
@@ -4,5 +4,5 @@
using std::string;
-char* Caption(string* type, char* BufferData, size_t BufferLength,
+char* Caption(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/caption2.cc b/natives/caption2.cc
index a7bf181..0b9026e 100644
--- a/natives/caption2.cc
+++ b/natives/caption2.cc
@@ -7,8 +7,8 @@
using namespace std;
using namespace vips;
-char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *CaptionTwo(string type, string *outType, char *BufferData,
+ size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
bool top = GetArgument(Arguments, "top");
string caption = GetArgument(Arguments, "caption");
string font = GetArgument(Arguments, "font");
@@ -18,7 +18,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
@@ -58,7 +58,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
vector img;
for (int i = 0; i < nPages; i++) {
VImage img_frame =
- *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
+ type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage frame =
(top ? captionImage : img_frame)
.join(top ? img_frame : captionImage, VIPS_DIRECTION_VERTICAL,
@@ -72,9 +72,10 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(
- ("." + *type).c_str(), &buf, DataSize,
- *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
- : 0);
+ ("." + *outType).c_str(), &buf, DataSize,
+ *outType == "gif"
+ ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
+ : 0);
return (char *)buf;
}
diff --git a/natives/caption2.h b/natives/caption2.h
index d45e2d2..6ee4790 100644
--- a/natives/caption2.h
+++ b/natives/caption2.h
@@ -4,5 +4,5 @@
using std::string;
-char* CaptionTwo(string* type, char* BufferData, size_t BufferLength,
+char* CaptionTwo(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/circle.cc b/natives/circle.cc
index 3834be3..96a1768 100644
--- a/natives/circle.cc
+++ b/natives/circle.cc
@@ -11,8 +11,9 @@
using namespace std;
using namespace Magick;
-char *Circle(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Circle(string type, string *outType, char *BufferData,
+ size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
+ size_t *DataSize) {
Blob blob;
list frames;
@@ -29,13 +30,13 @@ char *Circle(string *type, char *BufferData, size_t BufferLength,
for (Image &image : coalesced) {
image.rotationalBlur(10);
- image.magick(*type);
+ image.magick(*outType);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
- if (*type == "gif") {
+ if (*outType == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
diff --git a/natives/circle.h b/natives/circle.h
index 283ca79..4ee7f96 100644
--- a/natives/circle.h
+++ b/natives/circle.h
@@ -4,5 +4,5 @@
using std::string;
-char* Circle(string* type, char* BufferData, size_t BufferLength,
+char* Circle(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/cli/image.cc b/natives/cli/image.cc
new file mode 100644
index 0000000..344d0bb
--- /dev/null
+++ b/natives/cli/image.cc
@@ -0,0 +1,26 @@
+#include
+#include
+
+#include "../common.h"
+
+void showUsage(char *path) {
+ std::cout << "Usage: " << path << " operation [--arg=\"param\"] [...]" << std::endl;
+}
+
+int main(int argc, char *argv[]) {
+ if (argc < 1 ||
+ (argc == 1 && !strcmp(argv[1], "-h"))) {
+ showUsage(argv[0]);
+#ifdef _WIN32
+ system("PAUSE");
+#endif
+ return 1;
+ }
+
+ char *op = argv[1];
+
+ //handleArguments(argc, argv);
+
+ std::cout << "This does nothing yet, but it might in the future!" << std::endl;
+ return 0;
+}
\ No newline at end of file
diff --git a/natives/colors.cc b/natives/colors.cc
index 6c8fa62..b488600 100644
--- a/natives/colors.cc
+++ b/natives/colors.cc
@@ -10,15 +10,15 @@ using namespace vips;
VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870,
0.1140, 0.2392, 0.4696, 0.0912);
-char *Colors(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Colors(string type, string *outType, char *BufferData,
+ size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
string color = GetArgument(Arguments, "color");
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
VImage out;
@@ -30,7 +30,7 @@ char *Colors(string *type, char *BufferData, size_t BufferLength,
}
void *buf;
- out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
+ out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
return (char *)buf;
}
diff --git a/natives/colors.h b/natives/colors.h
index d0bddf5..4d00d0b 100644
--- a/natives/colors.h
+++ b/natives/colors.h
@@ -4,5 +4,5 @@
using std::string;
-char* Colors(string* type, char* BufferData, size_t BufferLength,
+char* Colors(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/common.h b/natives/common.h
index 2099433..1d71efb 100644
--- a/natives/common.h
+++ b/natives/common.h
@@ -12,6 +12,46 @@ using std::variant;
typedef variant ArgumentVariant;
typedef map ArgumentMap;
+#include "blur.h"
+#include "bounce.h"
+#include "caption.h"
+#include "caption2.h"
+#include "circle.h"
+#include "colors.h"
+#include "crop.h"
+#include "deepfry.h"
+#include "explode.h"
+#include "flag.h"
+#include "flip.h"
+#include "freeze.h"
+#include "gamexplain.h"
+#include "globe.h"
+#include "homebrew.h"
+#include "invert.h"
+#include "jpeg.h"
+#include "magik.h"
+#include "meme.h"
+#include "mirror.h"
+#include "motivate.h"
+#include "reddit.h"
+#include "resize.h"
+#include "reverse.h"
+#include "scott.h"
+#include "snapchat.h"
+#include "sonic.h"
+#include "speed.h"
+#include "spin.h"
+#include "squish.h"
+#include "swirl.h"
+#include "tile.h"
+#include "togif.h"
+#include "uncanny.h"
+#include "uncaption.h"
+#include "wall.h"
+#include "watermark.h"
+#include "whisper.h"
+#include "zamn.h"
+
template
T GetArgument(ArgumentMap map, string key) {
try {
@@ -42,4 +82,49 @@ T GetArgumentWithFallback(ArgumentMap map, string key, T fallback) {
const std::unordered_map fontPaths{
{"futura", "assets/fonts/caption.otf"},
{"helvetica", "assets/fonts/caption2.ttf"},
- {"roboto", "assets/fonts/reddit.ttf"}};
\ No newline at end of file
+ {"roboto", "assets/fonts/reddit.ttf"}};
+
+const std::map
+ FunctionMap = {{"blur", &Blur},
+ {"bounce", &Bounce},
+ {"caption", &Caption},
+ {"captionTwo", &CaptionTwo},
+ {"circle", &Circle},
+ {"colors", &Colors},
+ {"crop", &Crop},
+ {"deepfry", &Deepfry},
+ {"explode", &Explode},
+ {"flag", &Flag},
+ {"flip", &Flip},
+ {"freeze", &Freeze},
+ {"gamexplain", Gamexplain},
+ {"globe", Globe},
+ {"invert", Invert},
+ {"jpeg", Jpeg},
+ {"magik", Magik},
+ {"meme", Meme},
+ {"mirror", Mirror},
+ {"motivate", Motivate},
+ {"reddit", Reddit},
+ {"resize", Resize},
+ {"reverse", Reverse},
+ {"scott", Scott},
+ {"snapchat", Snapchat},
+ {"speed", &Speed},
+ {"spin", Spin},
+ {"squish", Squish},
+ {"swirl", Swirl},
+ {"tile", Tile},
+ {"togif", ToGif},
+ {"uncanny", Uncanny},
+ {"uncaption", &Uncaption},
+ {"wall", Wall},
+ {"watermark", &Watermark},
+ {"whisper", Whisper},
+ {"zamn", Zamn}};
+
+const std::map
+ NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};
\ No newline at end of file
diff --git a/natives/crop.cc b/natives/crop.cc
index 07cbad5..9faba5b 100644
--- a/natives/crop.cc
+++ b/natives/crop.cc
@@ -7,13 +7,13 @@
using namespace std;
using namespace vips;
-char *Crop(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Crop(string type, string *outType, char *BufferData, size_t BufferLength,
+ [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
int width = in.width();
@@ -24,7 +24,7 @@ char *Crop(string *type, char *BufferData, size_t BufferLength,
int finalHeight = 0;
for (int i = 0; i < nPages; i++) {
VImage img_frame =
- *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
+ type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
int frameWidth = img_frame.width();
int frameHeight = img_frame.height();
bool widthOrHeight = frameWidth / frameHeight >= 1;
@@ -42,9 +42,10 @@ char *Crop(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(
- ("." + *type).c_str(), &buf, DataSize,
- *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
- : 0);
+ ("." + *outType).c_str(), &buf, DataSize,
+ *outType == "gif"
+ ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
+ : 0);
return (char *)buf;
}
\ No newline at end of file
diff --git a/natives/crop.h b/natives/crop.h
index 439b4d1..c7cad96 100644
--- a/natives/crop.h
+++ b/natives/crop.h
@@ -4,5 +4,5 @@
using std::string;
-char* Crop(string* type, char* BufferData, size_t BufferLength,
+char* Crop(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/deepfry.cc b/natives/deepfry.cc
index dce5b97..9fe72a0 100644
--- a/natives/deepfry.cc
+++ b/natives/deepfry.cc
@@ -6,13 +6,14 @@
using namespace std;
using namespace vips;
-char *Deepfry(string *type, char *BufferData, size_t BufferLength,
- ArgumentMap Arguments, size_t *DataSize) {
+char *Deepfry(string type, string *outType, char *BufferData,
+ size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments,
+ size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
- *type == "gif" ? options->set("n", -1) : options)
+ type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
@@ -25,7 +26,7 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength,
VImage fried = (in * 1.3 - (255.0 * 1.3 - 255.0)) * 1.5;
VImage final;
- if (totalHeight > 65500 && *type == "gif") {
+ if (totalHeight > 65500 && type == "gif") {
vector img;
for (int i = 0; i < nPages; i++) {
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
@@ -48,13 +49,13 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength,
VImage::option()->set("Q", 1)->set("strip", true));
final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
- if (*type == "gif") final.set("delay", fried.get_array_int("delay"));
+ if (type == "gif") final.set("delay", fried.get_array_int("delay"));
}
void *buf;
final.write_to_buffer(
- ("." + *type).c_str(), &buf, DataSize,
- *type == "gif" ? VImage::option()->set("dither", 0) : 0);
+ ("." + *outType).c_str(), &buf, DataSize,
+ *outType == "gif" ? VImage::option()->set("dither", 0) : 0);
return (char *)buf;
}
\ No newline at end of file
diff --git a/natives/deepfry.h b/natives/deepfry.h
index 00cc403..9196438 100644
--- a/natives/deepfry.h
+++ b/natives/deepfry.h
@@ -4,5 +4,5 @@
using std::string;
-char* Deepfry(string* type, char* BufferData, size_t BufferLength,
+char* Deepfry(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);
\ No newline at end of file
diff --git a/natives/explode.cc b/natives/explode.cc
index 4d6d42c..bc167e0 100644
--- a/natives/explode.cc
+++ b/natives/explode.cc
@@ -1,58 +1,52 @@
+#include
+
#include "common.h"
-#include
-
-#include
-#include
-#include
-#include