mirror of
https://github.com/Syping/dtranslatebot.git
synced 2025-10-02 21:36:13 +02:00
code style changes and remove some constructors
This commit is contained in:
parent
de121beaac
commit
94429ca718
9 changed files with 60 additions and 50 deletions
|
@ -31,6 +31,8 @@ namespace bot {
|
|||
class database {
|
||||
public:
|
||||
explicit database() = default;
|
||||
database(const database&) = delete;
|
||||
database& operator=(const database&) = delete;
|
||||
virtual ~database() = default;
|
||||
virtual void add_channel_target(dpp::snowflake guild_id, dpp::snowflake channel_id, const bot::settings::target &target);
|
||||
virtual void delete_channel(dpp::snowflake guild_id, dpp::snowflake channel_id);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <thread>
|
||||
#include "message_queue.h"
|
||||
#include "settings.h"
|
||||
using namespace bot;
|
||||
using bot::message_queue;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void message_queue::add(const message &message)
|
||||
|
|
|
@ -18,19 +18,20 @@
|
|||
|
||||
#include <sstream>
|
||||
#include "slashcommands.h"
|
||||
using bot::slashcommands;
|
||||
using namespace std::string_literals;
|
||||
|
||||
void bot::slashcommands::process_command_event(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
void slashcommands::process_command_event(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
{
|
||||
if (event.command.get_command_name() == "edit")
|
||||
bot::slashcommands::process_edit_command(bot, settings, event);
|
||||
slashcommands::process_edit_command(bot, settings, event);
|
||||
else if (event.command.get_command_name() == "list")
|
||||
bot::slashcommands::process_list_command(bot, settings, event);
|
||||
slashcommands::process_list_command(bot, settings, event);
|
||||
else if (event.command.get_command_name() == "translate" || event.command.get_command_name() == "translate_pref")
|
||||
bot::slashcommands::process_translate_command(bot, settings, event);
|
||||
slashcommands::process_translate_command(bot, settings, event);
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
void slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
{
|
||||
try {
|
||||
dpp::permission user_permissions = event.command.get_resolved_permission(event.command.usr.id);
|
||||
|
@ -57,7 +58,7 @@ void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::
|
|||
}
|
||||
for (auto target = channel->targets.begin(); target != channel->targets.end();) {
|
||||
if (std::find(targets.begin(), targets.end(), target->target) != targets.end()) {
|
||||
bot->delete_webhook(target->webhook.id, std::bind(&bot::slashcommands::process_deleted_webhook, settings, target->webhook.id, std::placeholders::_1));
|
||||
bot->delete_webhook(target->webhook.id, std::bind(&slashcommands::process_deleted_webhook, settings, target->webhook.id, std::placeholders::_1));
|
||||
target = channel->targets.erase(target);
|
||||
}
|
||||
else {
|
||||
|
@ -89,7 +90,7 @@ void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::
|
|||
if (target_found) {
|
||||
for (auto _target = channel->targets.begin(); _target != channel->targets.end(); _target++) {
|
||||
if (_target->target == target) {
|
||||
bot->delete_webhook(_target->webhook.id, std::bind(&bot::slashcommands::process_deleted_webhook, settings, _target->webhook.id, std::placeholders::_1));
|
||||
bot->delete_webhook(_target->webhook.id, std::bind(&slashcommands::process_deleted_webhook, settings, _target->webhook.id, std::placeholders::_1));
|
||||
channel->targets.erase(_target);
|
||||
break;
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ void bot::slashcommands::process_edit_command(dpp::cluster *bot, bot::settings::
|
|||
}
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_deleted_webhook(bot::settings::settings *settings, dpp::snowflake webhook_id, const dpp::confirmation_callback_t &callback)
|
||||
void slashcommands::process_deleted_webhook(bot::settings::settings *settings, dpp::snowflake webhook_id, const dpp::confirmation_callback_t &callback)
|
||||
{
|
||||
if (callback.is_error()) {
|
||||
std::cerr << "[Error] Failed to delete Webhook " << webhook_id << std::endl;
|
||||
|
@ -175,7 +176,7 @@ void bot::slashcommands::process_deleted_webhook(bot::settings::settings *settin
|
|||
settings->erase_translatebot_webhook(webhook_id);
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_list_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
void slashcommands::process_list_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
{
|
||||
try {
|
||||
dpp::command_interaction interaction = event.command.get_command_interaction();
|
||||
|
@ -273,7 +274,7 @@ void bot::slashcommands::process_list_command(dpp::cluster *bot, bot::settings::
|
|||
}
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
void slashcommands::process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event)
|
||||
{
|
||||
try {
|
||||
dpp::permission user_permissions = event.command.get_resolved_permission(event.command.usr.id);
|
||||
|
@ -317,7 +318,7 @@ void bot::slashcommands::process_translate_command(dpp::cluster *bot, bot::setti
|
|||
webhook.guild_id = channel->guild_id;
|
||||
webhook.name = "Translate Bot Webhook <" + std::to_string(event.command.channel_id) + ":" + source + ":" + target + ">";
|
||||
|
||||
bot->create_webhook(webhook, std::bind(&bot::slashcommands::process_translate_webhook_new_channel, settings, event, source, target, std::placeholders::_1));
|
||||
bot->create_webhook(webhook, std::bind(&slashcommands::process_translate_webhook_new_channel, settings, event, source, target, std::placeholders::_1));
|
||||
}
|
||||
else if (dpp::webhook *webhook = std::get_if<dpp::webhook>(&v_target)) {
|
||||
const bot::settings::target s_target = { target, *webhook };
|
||||
|
@ -344,7 +345,7 @@ void bot::slashcommands::process_translate_command(dpp::cluster *bot, bot::setti
|
|||
webhook.guild_id = channel->guild_id;
|
||||
webhook.name = "Translate Bot Webhook <" + std::to_string(event.command.channel_id) + ":" + source + ":" + target + ">";
|
||||
|
||||
bot->create_webhook(webhook, std::bind(&bot::slashcommands::process_translate_webhook_add_target, settings, event, target, std::placeholders::_1));
|
||||
bot->create_webhook(webhook, std::bind(&slashcommands::process_translate_webhook_add_target, settings, event, target, std::placeholders::_1));
|
||||
}
|
||||
else if (dpp::webhook *webhook = std::get_if<dpp::webhook>(&v_target)) {
|
||||
const bot::settings::target s_target = { target, *webhook };
|
||||
|
@ -379,7 +380,7 @@ void bot::slashcommands::process_translate_command(dpp::cluster *bot, bot::setti
|
|||
}
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_translate_webhook_add_target(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &target, const dpp::confirmation_callback_t &callback)
|
||||
void slashcommands::process_translate_webhook_add_target(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &target, const dpp::confirmation_callback_t &callback)
|
||||
{
|
||||
if (callback.is_error()) {
|
||||
event.reply(dpp::message("Failed to generate webhook!").set_flags(dpp::m_ephemeral));
|
||||
|
@ -400,7 +401,7 @@ void bot::slashcommands::process_translate_webhook_add_target(bot::settings::set
|
|||
event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
||||
void bot::slashcommands::process_translate_webhook_new_channel(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &source, const std::string &target, const dpp::confirmation_callback_t &callback)
|
||||
void slashcommands::process_translate_webhook_new_channel(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &source, const std::string &target, const dpp::confirmation_callback_t &callback)
|
||||
{
|
||||
if (callback.is_error()) {
|
||||
event.reply(dpp::message("Failed to generate webhook!").set_flags(dpp::m_ephemeral));
|
||||
|
@ -423,7 +424,7 @@ void bot::slashcommands::process_translate_webhook_new_channel(bot::settings::se
|
|||
event.reply(dpp::message("Channel will be now translated!").set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
||||
void bot::slashcommands::register_commands(dpp::cluster *bot, bot::settings::settings *settings)
|
||||
void slashcommands::register_commands(dpp::cluster *bot, bot::settings::settings *settings)
|
||||
{
|
||||
settings->lock();
|
||||
const std::vector<bot::translator::language> languages = settings->get_translator()->get_languages();
|
||||
|
|
|
@ -23,16 +23,20 @@
|
|||
#include "settings.h"
|
||||
|
||||
namespace bot {
|
||||
namespace slashcommands {
|
||||
extern void process_command_event(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
extern void process_edit_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
extern void process_deleted_webhook(bot::settings::settings *settings, dpp::snowflake webhook_id, const dpp::confirmation_callback_t &callback);
|
||||
extern void process_list_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
extern void process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
extern void process_translate_webhook_add_target(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &target, const dpp::confirmation_callback_t &callback);
|
||||
extern void process_translate_webhook_new_channel(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &source, const std::string &target, const dpp::confirmation_callback_t &callback);
|
||||
extern void register_commands(dpp::cluster *bot, bot::settings::settings *settings);
|
||||
}
|
||||
class slashcommands {
|
||||
public:
|
||||
slashcommands() = delete;
|
||||
static void process_command_event(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
static void register_commands(dpp::cluster *bot, bot::settings::settings *settings);
|
||||
|
||||
private:
|
||||
static void process_edit_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
static void process_deleted_webhook(bot::settings::settings *settings, dpp::snowflake webhook_id, const dpp::confirmation_callback_t &callback);
|
||||
static void process_list_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
static void process_translate_command(dpp::cluster *bot, bot::settings::settings *settings, const dpp::slashcommand_t &event);
|
||||
static void process_translate_webhook_add_target(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &target, const dpp::confirmation_callback_t &callback);
|
||||
static void process_translate_webhook_new_channel(bot::settings::settings *settings, const dpp::slashcommand_t &event, const std::string &source, const std::string &target, const dpp::confirmation_callback_t &callback);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SLASHCOMMANDS_H
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <thread>
|
||||
#include "submit_queue.h"
|
||||
#include "webhook_push.h"
|
||||
using namespace bot;
|
||||
using bot::submit_queue;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void submit_queue::add(const translated_message &message)
|
||||
|
|
|
@ -33,6 +33,8 @@ namespace bot {
|
|||
public:
|
||||
explicit translator() = default;
|
||||
virtual ~translator() = default;
|
||||
translator(const translator&) = delete;
|
||||
translator& operator=(const translator&) = delete;
|
||||
virtual const std::vector<language> get_languages();
|
||||
virtual const std::string translate(const std::string &text, const std::string &source, const std::string &target);
|
||||
};
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace bot {
|
||||
class webhook_push {
|
||||
public:
|
||||
webhook_push() = delete;
|
||||
static void run(const bot::translated_message &message, dpp::cluster *bot);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue