From d37dd564962e252be134d6c9674e07dcb7836afb Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 23 Jul 2025 01:54:10 +0300 Subject: [PATCH] Added libcairo as a dependancy --- CMakeLists.txt | 11 +++++--- src/CommandManagement.cpp | 2 +- src/Commands/GenerativeCommands.cpp | 40 ++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2df18a7..c5a1f39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Minimum CMake version required, we'll just use the latest version. cmake_minimum_required(VERSION 3.22) # Project name, version and description -project(TheBartender VERSION 1.0) +project(TheBartender VERSION 0.3) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) @@ -12,13 +12,16 @@ add_executable(${PROJECT_NAME} src/Base/Entry.cpp src/Commands.cpp) find_package(DPP REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(SQLITE3 REQUIRED sqlite3) +pkg_check_modules(CAIRO REQUIRED cairo) # Link the pre-installed DPP package. -target_link_libraries(${PROJECT_NAME} ${DPP_LIBRARIES} ${SQLITE3_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} ${DPP_LIBRARIES} ${SQLITE3_LIBRARIES} + ${CAIRO_LIBRARIES}) # Include the DPP directories. -target_include_directories(${PROJECT_NAME} PRIVATE ${DPP_INCLUDE_DIR} - ${SQLITE3_INCLUDE_DIR}) +target_include_directories( + ${PROJECT_NAME} PRIVATE ${DPP_INCLUDE_DIR} ${SQLITE3_INCLUDE_DIR} + ${CAIRO_INCLUDE_DIR}) # Set C++ version set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 diff --git a/src/CommandManagement.cpp b/src/CommandManagement.cpp index eb03e18..76d6da4 100644 --- a/src/CommandManagement.cpp +++ b/src/CommandManagement.cpp @@ -27,7 +27,7 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) { dpp::slashcommand(COMMAND_GENERATE_REPORT, COMMAND_GENERATE_REPORT_DESCRIPTION, bot.me.id) .add_option(dpp::command_option( - dpp::command_option_type::co_attachment, "background-image", + dpp::command_option_type::co_attachment, "image", COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION, true)) .add_option(dpp::command_option( dpp::command_option_type::co_string, "headline", diff --git a/src/Commands/GenerativeCommands.cpp b/src/Commands/GenerativeCommands.cpp index de73e59..6229e9c 100644 --- a/src/Commands/GenerativeCommands.cpp +++ b/src/Commands/GenerativeCommands.cpp @@ -3,8 +3,46 @@ #include #include #include +#include +#include +#include #include #include +#include + +#include +#include +#include + +void pngToCairoSurface(std::string data) { + cairo_surface_t *image = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 200); +} +void jpegToCairoSurface(std::string data) {} +void webpToCairoSurface(std::string data) {} + +std::unordered_map> + supportedImageFileTypes{{"image/png", pngToCairoSurface}, + {"image/jpeg", jpegToCairoSurface}, + {"image/webp", webpToCairoSurface}}; + void commandGenerateReport(const dpp::slashcommand_t &event, - dpp::cluster &bot) {} + dpp::cluster &bot) { + event.thinking(); + dpp::snowflake fileId = + std::get(event.get_parameter("image")); + dpp::attachment file = event.command.get_resolved_attachment(fileId); + auto fileType = supportedImageFileTypes.find(file.content_type); + if (fileType != supportedImageFileTypes.end()) { + bot.request( + file.url, dpp::http_method::m_get, + [event, &bot, fileType](const dpp::http_request_completion_t &result) { + fileType->second(result.body); + }); + } else { + event.edit_response( + "File type: " + file.content_type + + " is not allowed. Only PNG, JPEG, and WEBP are allowed!"); + } +}