From 2ad1bc3aa5801c30066cd37a45f8585126a4e0ad Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 12 Feb 2024 18:09:46 +0100 Subject: [PATCH] MSVC fixes --- CMakeLists.txt | 3 +++ src/database_file.cpp | 2 +- src/settings.cpp | 6 +++--- src/slashcommands.cpp | 5 +++-- src/webhook_push.cpp | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16305a1..1ba6f31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,9 @@ find_package(Threads REQUIRED) # dtranslatebot Target + Installs add_executable(dtranslatebot ${DTRANSLATEBOT_HEADERS} ${DTRANSLATEBOT_SOURCES}) +if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914) + target_compile_options(dtranslatebot PRIVATE $<$:/Zc:__cplusplus>) +endif() target_link_libraries(dtranslatebot PRIVATE Threads::Threads ${DPP_LIBRARIES}) target_include_directories(dtranslatebot PRIVATE ${DPP_INCLUDE_DIR}) set_target_properties(dtranslatebot PROPERTIES diff --git a/src/database_file.cpp b/src/database_file.cpp index 1f58955..fec8ca0 100644 --- a/src/database_file.cpp +++ b/src/database_file.cpp @@ -493,7 +493,7 @@ void file::list_guilds(std::vector *guilds) for (const auto &guild_file : std::filesystem::directory_iterator(guild_dir)) { const std::filesystem::path &guild_file_path = guild_file.path(); if (guild_file_path.extension() == ".json") { - const std::string &guild_filename = guild_file_path.stem(); + const std::string guild_filename = guild_file_path.stem().generic_string(); if (std::all_of(guild_filename.begin(), guild_filename.end(), ::isdigit)) { try { dpp::snowflake guild_id = std::stoull(guild_filename); diff --git a/src/settings.cpp b/src/settings.cpp index 4979ee1..e75c029 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -93,7 +93,7 @@ void process_guild_settings(const dpp::json &json, std::vector *guilds, s auto json_guild_id = json_guild->find("id"); if (json_guild_id != json_guild->end()) { if (json_guild_id->is_number()) - guild.id = *json_guild_id; + guild.id = static_cast(*json_guild_id); else if (json_guild_id->is_string()) guild.id = std::stoull(std::string(*json_guild_id)); else @@ -109,7 +109,7 @@ void process_guild_settings(const dpp::json &json, std::vector *guilds, s auto json_channel_id = json_channel->find("id"); if (json_channel_id != json_channel->end()) { if (json_channel_id->is_number()) - channel.id = *json_channel_id; + channel.id = static_cast(*json_channel_id); else if (json_channel_id->is_string()) channel.id = std::stoull(std::string(*json_channel_id)); else @@ -230,7 +230,7 @@ void settings::add_channel(const channel &channel, dpp::snowflake guild_id) // We will create the guild structure when it is not in memory guild guild; guild.id = guild_id; - guild.channel.push_back(std::move(channel)); + guild.channel.push_back(channel); m_guilds.push_back(std::move(guild)); } diff --git a/src/slashcommands.cpp b/src/slashcommands.cpp index 7cae9f8..dd09ad8 100644 --- a/src/slashcommands.cpp +++ b/src/slashcommands.cpp @@ -16,6 +16,7 @@ * responsible for anything with use of the software, you are self responsible. *****************************************************************************/ +#include #include "slashcommands.h" using namespace std::string_literals; @@ -167,9 +168,9 @@ void bot::slashcommands::register_commands(dpp::cluster *bot, bot::settings::set dpp::command_option channel_translate_subcommand(dpp::co_sub_command, "channel", "Translate current channel to a channel"); dpp::command_option webhook_translate_subcommand(dpp::co_sub_command, "webhook", "Translate current channel to a webhook"); dpp::command_option source_option(dpp::co_string, "source", "Source language (ISO 639-1)", true); - source_option.set_max_length(2).set_min_length(2); + source_option.set_max_length(static_cast(2)).set_min_length(static_cast(2)); dpp::command_option target_option(dpp::co_string, "target", "Target language (ISO 639-1)", true); - target_option.set_max_length(2).set_min_length(2); + target_option.set_max_length(static_cast(2)).set_min_length(static_cast(2)); dpp::command_option channel_option(dpp::co_channel, "channel", "Target channel", true); channel_option.add_channel_type(dpp::CHANNEL_TEXT); dpp::command_option webhook_option(dpp::co_string, "webhook", "Target webhook", true); diff --git a/src/webhook_push.cpp b/src/webhook_push.cpp index cff1044..c9f5a81 100644 --- a/src/webhook_push.cpp +++ b/src/webhook_push.cpp @@ -40,7 +40,7 @@ void bot::webhook_push::run(const bot::translated_message &message, dpp::cluster message_v = message_v.substr(1333 + pos); } else { - std::cmatch match; + std::match_results match; if (std::regex_match(message_eov.begin(), message_eov.end(), match, std::regex("^.*(\\.|\\?|\\!|\\。)\\s.*$"s))) { json_body["content"] = message_v.substr(0, 1334 + match.position(1)); message_v = message_v.substr(1334 + match.position(1));