From 25d83b243dda489f387a5079c9f6d9301f94a598 Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 3 Feb 2024 07:16:12 +0100 Subject: [PATCH] make code more efficient and added storage setting --- CMakeLists.txt | 2 + src/main.cpp | 172 +++--------------------------- src/message_queue.cpp | 18 ++-- src/message_queue.h | 1 - src/settings.cpp | 36 +++++-- src/settings.h | 5 +- src/slashcommands.cpp | 177 +++++++++++++++++++++++++++++++ src/slashcommands.h | 33 ++++++ src/submit_queue.h | 4 +- src/translate_libretranslate.cpp | 2 +- 10 files changed, 264 insertions(+), 186 deletions(-) create mode 100644 src/slashcommands.cpp create mode 100644 src/slashcommands.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e29d92..3b6fbe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ include(GNUInstallDirs) set(DTRANSLATEBOT_HEADERS src/message_queue.h src/settings.h + src/slashcommands.h src/submit_queue.h src/translate_core.h src/translate_libretranslate.h @@ -33,6 +34,7 @@ set(DTRANSLATEBOT_SOURCES src/main.cpp src/message_queue.cpp src/settings.cpp + src/slashcommands.cpp src/submit_queue.cpp src/translate_core.cpp src/translate_libretranslate.cpp diff --git a/src/main.cpp b/src/main.cpp index a275ee0..86fbb6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,12 +16,14 @@ * responsible for anything with use of the software, you are self responsible. *****************************************************************************/ -#include +#include +#include #include #include #include #include "message_queue.h" #include "settings.h" +#include "slashcommands.h" int main(int argc, char* argv[]) { if (argc != 2) { @@ -33,14 +35,14 @@ int main(int argc, char* argv[]) { if (!settings.parse(argv[1])) return 1; - { - std::vector languages; - languages = settings.get_translator()->get_languages(); + if (settings.get_translator()->get_languages().empty()) { + std::cerr << "Failed to initialise translateable languages" << std::endl; + return 2; + } - if (languages.empty()) { - std::cerr << "Failed to initialise translateable languages" << std::endl; - return 2; - } + if (!std::filesystem::exists(settings.get_storage_path())) { + std::cerr << "Storage directory " << settings.get_storage_path() << " can not be found" << std::endl; + return 2; } dpp::cluster bot(settings.get_token(), dpp::i_default_intents | dpp::i_message_content); @@ -83,167 +85,19 @@ int main(int argc, char* argv[]) { message.message = event.msg.content; message.source = channel->source; message.targets = channel->targets; - message_queue.add(message); + message_queue.add(std::move(message)); } }); bot.on_slashcommand([&bot, &settings](const dpp::slashcommand_t &event) { if (event.command.get_command_name() == "translate" || event.command.get_command_name() == "translate_pref") { - try { - std::variant v_target; - const std::string source = std::get(event.get_parameter("source")); - const std::string target = std::get(event.get_parameter("target")); - - dpp::command_interaction interaction = event.command.get_command_interaction(); - if (interaction.options[0].name == "channel") { - v_target = event.command.get_resolved_channel( - std::get(event.get_parameter("channel"))); - } - else if (interaction.options[0].name == "webhook") { - v_target = dpp::webhook(std::get(event.get_parameter("webhook"))); - } - - const std::vector languages = settings.get_translator()->get_languages(); - - std::ostringstream language_codes; - bool source_valid = false, target_valid = false; - for (const bot::translate::language &language : languages) { - if (language.code == source) - source_valid = true; - if (language.code == target) - target_valid = true; - if (source_valid && target_valid) - break; - language_codes << " " << language.code; - } - - if (source_valid && target_valid) { - const std::lock_guard guard(settings); - if (!settings.get_channel(event.command.guild_id, event.command.channel_id)) { - if (dpp::channel *channel = std::get_if(&v_target)) { - dpp::webhook webhook; - webhook.channel_id = channel->id; - webhook.guild_id = channel->guild_id; - webhook.name = "Translate Bot Webhook <" + std::to_string(event.command.channel_id) + ":" + source + ":" + target + ">"; - - bot.create_webhook(webhook, [&bot, &settings, event, source, target](const dpp::confirmation_callback_t &callback) { - if (callback.is_error()) { - event.reply(dpp::message("Failed to generate webhook!\n" + callback.http_info.body).set_flags(dpp::m_ephemeral)); - return; - } - const dpp::webhook webhook = callback.get(); - - bot::settings::channel s_channel; - s_channel.id = event.command.channel_id; - s_channel.source = source; - - bot::settings::target s_target; - s_target.target = target; - s_target.webhook = webhook; - s_channel.targets.emplace_back(s_target); - - settings.lock(); - settings.add_channel(s_channel, event.command.guild_id); - settings.add_translatebot_webhook(webhook); - settings.unlock(); - - event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral)); - }); - } - else if (dpp::webhook *webhook = std::get_if(&v_target)) { - bot::settings::channel s_channel; - s_channel.id = event.command.channel_id; - s_channel.source = source; - - bot::settings::target s_target; - s_target.target = target; - s_target.webhook = *webhook; - s_channel.targets.emplace_back(s_target); - - settings.lock(); - settings.add_channel(s_channel, event.command.guild_id); - settings.add_translatebot_webhook(*webhook); - settings.unlock(); - - event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral)); - } - } - else { - event.reply(dpp::message("The current channel is already being translated!").set_flags(dpp::m_ephemeral)); - } - } - else if (!source_valid && !target_valid) { - event.reply(dpp::message("Source and target languages are not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); - } - else if (!source_valid) { - event.reply(dpp::message("Source language is not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); - } - else if (!target_valid) { - event.reply(dpp::message("Target language is not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); - } - } - catch (const std::exception &exception) { - std::cerr << "Failed to process command /" << event.command.get_command_name() << ": " << exception.what() << std::endl; - event.reply(dpp::message("Failed to process command /" + event.command.get_command_name() + "\n" + exception.what()).set_flags(dpp::m_ephemeral)); - } + bot::slashcommands::process_translate_command(&bot, &settings, event); } }); bot.on_ready([&bot, &settings](const dpp::ready_t &event) { if (dpp::run_once()) { - settings.lock(); - const std::vector languages = settings.get_translator()->get_languages(); - const std::vector preferred_languages = settings.get_preferred_languages(); - settings.unlock(); - - std::vector commands; - - dpp::slashcommand command_translate("translate", "Translate current channel (ISO 639-1)", bot.me.id); - command_translate.set_default_permissions(dpp::p_manage_webhooks); - dpp::command_option channel_subcommand(dpp::co_sub_command, "channel", "Translate current channel to a channel (ISO 639-1)"); - dpp::command_option webhook_subcommand(dpp::co_sub_command, "webhook", "Translate current channel to a webhook (ISO 639-1)"); - dpp::command_option source_option(dpp::co_string, "source", "Source language", true); - source_option.set_max_length(2).set_min_length(2); - dpp::command_option target_option(dpp::co_string, "target", "Target language", true); - target_option.set_max_length(2).set_min_length(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); - channel_subcommand.add_option(source_option); - channel_subcommand.add_option(target_option); - channel_subcommand.add_option(channel_option); - webhook_subcommand.add_option(source_option); - webhook_subcommand.add_option(target_option); - webhook_subcommand.add_option(webhook_option); - command_translate.add_option(channel_subcommand); - command_translate.add_option(webhook_subcommand); - commands.emplace_back(command_translate); - - if (preferred_languages.size() > 1) { - dpp::slashcommand command_translate_pref("translate_pref", "Translate current channel (Preferred languages)", bot.me.id); - command_translate_pref.set_default_permissions(dpp::p_manage_webhooks); - dpp::command_option channel_pref_subcommand(dpp::co_sub_command, "channel", "Translate current channel to a channel (Preferred languages)"); - dpp::command_option webhook_pref_subcommand(dpp::co_sub_command, "webhook", "Translate current channel to a webhook (Preferred languages)"); - dpp::command_option source_pref_option(dpp::co_string, "source", "Source language", true); - dpp::command_option target_pref_option(dpp::co_string, "target", "Target language", true); - for (const bot::translate::language &language : languages) { - if (std::find(preferred_languages.begin(), preferred_languages.end(), language.code) != preferred_languages.end()) { - source_pref_option.add_choice(dpp::command_option_choice(language.name, language.code)); - target_pref_option.add_choice(dpp::command_option_choice(language.name, language.code)); - } - } - channel_pref_subcommand.add_option(source_pref_option); - channel_pref_subcommand.add_option(target_pref_option); - channel_pref_subcommand.add_option(channel_option); - webhook_pref_subcommand.add_option(source_pref_option); - webhook_pref_subcommand.add_option(target_pref_option); - webhook_pref_subcommand.add_option(webhook_option); - command_translate_pref.add_option(channel_pref_subcommand); - command_translate_pref.add_option(webhook_pref_subcommand); - commands.emplace_back(command_translate_pref); - } - - bot.global_bulk_command_create(commands); + bot::slashcommands::register_commands(&bot, &settings); } }); diff --git a/src/message_queue.cpp b/src/message_queue.cpp index 2b2c659..6a1e431 100644 --- a/src/message_queue.cpp +++ b/src/message_queue.cpp @@ -21,16 +21,6 @@ #include "settings.h" using namespace std::chrono_literals; -inline bot::translated_message make_translated_message(const bot::message &message, const std::string &translated_message, const dpp::webhook &webhook) -{ - bot::translated_message tr_message; - tr_message.author = message.author; - tr_message.avatar = message.avatar; - tr_message.message = translated_message; - tr_message.webhook = webhook; - return tr_message; -} - void bot::message_queue::add(const bot::message &message) { m_mutex.lock(); @@ -51,8 +41,12 @@ void bot::message_queue::run(bot::settings::settings *settings, bot::submit_queu std::unique_ptr translator = settings->get_translator(); for (auto target = message.targets.begin(); target != message.targets.end(); target++) { - const std::string tr_message = translator->translate(message.message, message.source, target->target); - submit_queue->add(make_translated_message(message, tr_message, target->webhook)); + bot::translated_message tr_message; + tr_message.author = message.author; + tr_message.avatar = message.avatar; + tr_message.message = translator->translate(message.message, message.source, target->target); + tr_message.webhook = target->webhook; + submit_queue->add(std::move(tr_message)); } std::this_thread::yield(); diff --git a/src/message_queue.h b/src/message_queue.h index e9069a6..702e85a 100644 --- a/src/message_queue.h +++ b/src/message_queue.h @@ -18,7 +18,6 @@ #ifndef MESSAGE_QUEUE_H #define MESSAGE_QUEUE_H -#include #include #include #include diff --git a/src/settings.cpp b/src/settings.cpp index b07fd74..9dc57a9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include "settings.h" @@ -35,13 +36,13 @@ void bot::settings::settings::add_channel(const bot::settings::channel &channel, // We will create the guild structure when it is not in memory bot::settings::guild guild; guild.id = guild_id; - guild.channel.emplace_back(channel); - m_guilds.emplace_back(guild); + guild.channel.push_back(std::move(channel)); + m_guilds.push_back(std::move(guild)); } -void bot::settings::settings::add_translatebot_webhook(const dpp::webhook &webhook) +void bot::settings::settings::add_translatebot_webhook(dpp::snowflake webhook_id) { - m_webhookIds.push_back(webhook.id); + m_webhookIds.push_back(webhook_id); } uint16_t bot::settings::settings::get_avatar_size() @@ -86,6 +87,11 @@ const std::vector bot::settings::settings::get_preferred_languages( return m_preflangs; } +const std::filesystem::path bot::settings::settings::get_storage_path() +{ + return m_storagepath; +} + const bot::settings::translate* bot::settings::settings::get_translate() { return &m_translate; @@ -95,7 +101,7 @@ std::unique_ptr bot::settings::settings::get_transla { const std::lock_guard guard(m_mutex); std::unique_ptr libretranslate( - new bot::translate::libretranslate(m_translate.hostname, m_translate.port, m_translate.url, m_translate.tls, m_translate.apiKey)); + new bot::translate::libretranslate(m_translate.hostname, m_translate.port, m_translate.url, m_translate.tls, m_translate.apiKey)); return libretranslate; } @@ -145,6 +151,16 @@ bool bot::settings::settings::parse(const std::string &filename) const std::lock_guard guard(m_mutex); m_token = json_token.value(); + auto json_storage = json.find("storage"); + if (json_storage != json.end()) + m_storagepath = std::string(json_storage.value()); + else if (char *storagepath = getenv("DTRANSLATEBOT_STORAGE")) + m_storagepath = storagepath; + + if (m_storagepath.empty()) + m_storagepath = std::filesystem::current_path(); + + // In future we should allow more services here, for now it's only LibreTranslate auto json_translate = json.find("translate"); if (json_translate == json.end()) { std::cerr << "Translate settings can not be found" << std::endl; @@ -248,25 +264,25 @@ bool bot::settings::settings::parse(const std::string &filename) bot::settings::target target; target.target = json_channel_target.value(); target.webhook = dpp::webhook(json_channel->at("webhook")); - channel.targets.emplace_back(target); m_webhookIds.push_back(target.webhook.id); + channel.targets.push_back(std::move(target)); } else if (json_channel_target.value().is_object()) { for (auto json_target = json_channel_target.value().begin(); json_target != json_channel_target.value().end(); json_target++) { bot::settings::target target; target.target = json_target.key(); target.webhook = dpp::webhook(json_target.value()); - channel.targets.emplace_back(target); m_webhookIds.push_back(target.webhook.id); + channel.targets.push_back(std::move(target)); } } } if (!channel.source.empty() && !channel.targets.empty()) - guild.channel.emplace_back(channel); + guild.channel.push_back(std::move(channel)); } } - m_guilds.emplace_back(guild); + m_guilds.push_back(std::move(guild)); } } } @@ -279,7 +295,7 @@ bool bot::settings::settings::parse(const std::string &filename) std::cerr << "\"preferred_lang\" is limited to 25 languages" << std::endl; break; } - m_preflangs.push_back(json_preflang); + m_preflangs.push_back(std::move(json_preflang)); i++; } } diff --git a/src/settings.h b/src/settings.h index ab13a7b..0cbf11b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -52,12 +53,13 @@ namespace bot { class settings { public: void add_channel(const bot::settings::channel &channel, dpp::snowflake guild_id); - void add_translatebot_webhook(const dpp::webhook &webhook); + void add_translatebot_webhook(dpp::snowflake webhook_id); uint16_t get_avatar_size(); const bot::settings::channel* get_channel(const bot::settings::guild *guild, dpp::snowflake channel_id); const bot::settings::channel* get_channel(dpp::snowflake guild_id, dpp::snowflake channel_id); const bot::settings::guild* get_guild(dpp::snowflake guild_id); const std::vector get_preferred_languages(); + const std::filesystem::path get_storage_path(); const bot::settings::translate* get_translate(); std::unique_ptr get_translator(); const std::string get_token(); @@ -71,6 +73,7 @@ namespace bot { std::recursive_mutex m_mutex; std::vector m_guilds; std::vector m_preflangs; + std::filesystem::path m_storagepath; bot::settings::translate m_translate; std::string m_token; std::vector m_webhookIds; diff --git a/src/slashcommands.cpp b/src/slashcommands.cpp new file mode 100644 index 0000000..f8108a7 --- /dev/null +++ b/src/slashcommands.cpp @@ -0,0 +1,177 @@ +/***************************************************************************** +* dtranslatebot Discord Translate Bot +* Copyright (C) 2024 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +*****************************************************************************/ + +#include "slashcommands.h" + +void bot::slashcommands::process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event) +{ + try { + std::variant v_target; + const std::string source = std::get(event.get_parameter("source")); + const std::string target = std::get(event.get_parameter("target")); + + dpp::command_interaction interaction = event.command.get_command_interaction(); + if (interaction.options[0].name == "channel") { + v_target = event.command.get_resolved_channel( + std::get(event.get_parameter("channel"))); + } + else if (interaction.options[0].name == "webhook") { + v_target = dpp::webhook(std::get(event.get_parameter("webhook"))); + } + + const std::vector languages = settings->get_translator()->get_languages(); + + std::ostringstream language_codes; + bool source_valid = false, target_valid = false; + for (const bot::translate::language &language : languages) { + if (language.code == source) + source_valid = true; + if (language.code == target) + target_valid = true; + if (source_valid && target_valid) + break; + language_codes << " " << language.code; + } + + if (source_valid && target_valid) { + const std::lock_guard guard(*settings); + if (!settings->get_channel(event.command.guild_id, event.command.channel_id)) { + if (dpp::channel *channel = std::get_if(&v_target)) { + dpp::webhook webhook; + webhook.channel_id = channel->id; + webhook.guild_id = channel->guild_id; + webhook.name = "Translate Bot Webhook <" + std::to_string(event.command.channel_id) + ":" + source + ":" + target + ">"; + + bot->create_webhook(webhook, [&bot, &settings, event, source, target](const dpp::confirmation_callback_t &callback) { + if (callback.is_error()) { + event.reply(dpp::message("Failed to generate webhook!\n" + callback.http_info.body).set_flags(dpp::m_ephemeral)); + return; + } + const dpp::webhook webhook = callback.get(); + + bot::settings::channel s_channel; + s_channel.id = event.command.channel_id; + s_channel.source = source; + + bot::settings::target s_target; + s_target.target = target; + s_target.webhook = webhook; + s_channel.targets.push_back(std::move(s_target)); + + settings->lock(); + settings->add_channel(s_channel, event.command.guild_id); + settings->add_translatebot_webhook(webhook.id); + settings->unlock(); + + event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral)); + }); + } + else if (dpp::webhook *webhook = std::get_if(&v_target)) { + bot::settings::channel s_channel; + s_channel.id = event.command.channel_id; + s_channel.source = source; + + bot::settings::target s_target; + s_target.target = target; + s_target.webhook = *webhook; + s_channel.targets.push_back(std::move(s_target)); + + settings->lock(); + settings->add_channel(s_channel, event.command.guild_id); + settings->add_translatebot_webhook(webhook->id); + settings->unlock(); + + event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral)); + } + } + else { + event.reply(dpp::message("The current channel is already being translated!").set_flags(dpp::m_ephemeral)); + } + } + else if (!source_valid && !target_valid) { + event.reply(dpp::message("Source and target languages are not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); + } + else if (!source_valid) { + event.reply(dpp::message("Source language is not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); + } + else if (!target_valid) { + event.reply(dpp::message("Target language is not valid!\nAvailable languages are:" + language_codes.str()).set_flags(dpp::m_ephemeral)); + } + } + catch (const std::exception &exception) { + std::cerr << "Failed to process command /" << event.command.get_command_name() << ": " << exception.what() << std::endl; + event.reply(dpp::message("Failed to process command /" + event.command.get_command_name() + "\n" + exception.what()).set_flags(dpp::m_ephemeral)); + } +} + +void bot::slashcommands::register_commands(dpp::cluster *bot, bot::settings::settings *settings) +{ + settings->lock(); + const std::vector languages = settings->get_translator()->get_languages(); + const std::vector preferred_languages = settings->get_preferred_languages(); + settings->unlock(); + + std::vector commands; + + dpp::slashcommand command_translate("translate", "Translate current channel (ISO 639-1)", bot->me.id); + command_translate.set_default_permissions(dpp::p_manage_webhooks); + dpp::command_option channel_subcommand(dpp::co_sub_command, "channel", "Translate current channel to a channel (ISO 639-1)"); + dpp::command_option webhook_subcommand(dpp::co_sub_command, "webhook", "Translate current channel to a webhook (ISO 639-1)"); + dpp::command_option source_option(dpp::co_string, "source", "Source language", true); + source_option.set_max_length(2).set_min_length(2); + dpp::command_option target_option(dpp::co_string, "target", "Target language", true); + target_option.set_max_length(2).set_min_length(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); + channel_subcommand.add_option(source_option); + channel_subcommand.add_option(target_option); + channel_subcommand.add_option(channel_option); + webhook_subcommand.add_option(source_option); + webhook_subcommand.add_option(target_option); + webhook_subcommand.add_option(webhook_option); + command_translate.add_option(channel_subcommand); + command_translate.add_option(webhook_subcommand); + commands.push_back(std::move(command_translate)); + + if (preferred_languages.size() > 1) { + dpp::slashcommand command_translate_pref("translate_pref", "Translate current channel (Preferred languages)", bot->me.id); + command_translate_pref.set_default_permissions(dpp::p_manage_webhooks); + dpp::command_option channel_pref_subcommand(dpp::co_sub_command, "channel", "Translate current channel to a channel (Preferred languages)"); + dpp::command_option webhook_pref_subcommand(dpp::co_sub_command, "webhook", "Translate current channel to a webhook (Preferred languages)"); + dpp::command_option source_pref_option(dpp::co_string, "source", "Source language", true); + dpp::command_option target_pref_option(dpp::co_string, "target", "Target language", true); + for (const bot::translate::language &language : languages) { + if (std::find(preferred_languages.begin(), preferred_languages.end(), language.code) != preferred_languages.end()) { + source_pref_option.add_choice(dpp::command_option_choice(language.name, language.code)); + target_pref_option.add_choice(dpp::command_option_choice(language.name, language.code)); + } + } + channel_pref_subcommand.add_option(source_pref_option); + channel_pref_subcommand.add_option(target_pref_option); + channel_pref_subcommand.add_option(channel_option); + webhook_pref_subcommand.add_option(source_pref_option); + webhook_pref_subcommand.add_option(target_pref_option); + webhook_pref_subcommand.add_option(webhook_option); + command_translate_pref.add_option(channel_pref_subcommand); + command_translate_pref.add_option(webhook_pref_subcommand); + commands.push_back(std::move(command_translate_pref)); + } + + bot->global_bulk_command_create(commands); +} diff --git a/src/slashcommands.h b/src/slashcommands.h new file mode 100644 index 0000000..4d46735 --- /dev/null +++ b/src/slashcommands.h @@ -0,0 +1,33 @@ +/***************************************************************************** +* dtranslatebot Discord Translate Bot +* Copyright (C) 2024 Syping +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* +* This software is provided as-is, no warranties are given to you, we are not +* responsible for anything with use of the software, you are self responsible. +*****************************************************************************/ + +#ifndef SLASHCOMMANDS_H +#define SLASHCOMMANDS_H + +#include +#include "settings.h" + +namespace bot { + class slashcommands { + public: + static void process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event); + static void register_commands(dpp::cluster *bot, bot::settings::settings *settings); + }; +} + +#endif // SLASHCOMMANDS_H diff --git a/src/submit_queue.h b/src/submit_queue.h index 1cd12e8..06db524 100644 --- a/src/submit_queue.h +++ b/src/submit_queue.h @@ -18,11 +18,11 @@ #ifndef SUBMIT_QUEUE_H #define SUBMIT_QUEUE_H -#include +#include +#include #include #include #include -#include namespace bot { struct translated_message { diff --git a/src/translate_libretranslate.cpp b/src/translate_libretranslate.cpp index a99eb69..6a9e55e 100644 --- a/src/translate_libretranslate.cpp +++ b/src/translate_libretranslate.cpp @@ -52,7 +52,7 @@ const std::vector bot::translate::libretranslate::get_ language.name = json_lang_name.value(); if (!language.code.empty() && !language.name.empty()) - languages.emplace_back(language); + languages.push_back(std::move(language)); } } }