uint64_t -> dpp::snowflake + std::string -> dpp::webhook

This commit is contained in:
Syping 2024-01-20 10:02:55 +01:00
parent 7ee916537c
commit 06dec819ff
3 changed files with 19 additions and 21 deletions

View file

@ -95,7 +95,7 @@ void bot::message_queue::run(bot::settings::settings *settings, bot::submit_queu
std::cerr << "Exception thrown while translating: unknown" << std::endl;
}
submit_queue->add(make_translated_message(message, tr_message, dpp::webhook(target->webhook)));
submit_queue->add(make_translated_message(message, tr_message, target->webhook));
}
std::this_thread::yield();

View file

@ -26,7 +26,7 @@ uint16_t bot::settings::settings::get_avatar_size()
return m_avatarSize;
}
const bot::settings::channel *bot::settings::settings::get_channel(bot::settings::guild *guild, uint64_t channel_id)
const bot::settings::channel *bot::settings::settings::get_channel(const bot::settings::guild *guild, dpp::snowflake channel_id)
{
for (auto channel = guild->channel.begin(); channel != guild->channel.end(); channel++) {
if (channel->id == channel_id)
@ -35,7 +35,7 @@ const bot::settings::channel *bot::settings::settings::get_channel(bot::settings
return nullptr;
}
const bot::settings::channel *bot::settings::settings::get_channel(uint64_t guild_id, uint64_t channel_id)
const bot::settings::channel *bot::settings::settings::get_channel(dpp::snowflake guild_id, dpp::snowflake channel_id)
{
for (auto guild = m_guilds.begin(); guild != m_guilds.end(); guild++) {
if (guild->id == guild_id) {
@ -48,7 +48,7 @@ const bot::settings::channel *bot::settings::settings::get_channel(uint64_t guil
return nullptr;
}
const bot::settings::guild *bot::settings::settings::get_guild(uint64_t guild_id)
const bot::settings::guild *bot::settings::settings::get_guild(dpp::snowflake guild_id)
{
for (auto guild = m_guilds.begin(); guild != m_guilds.end(); guild++) {
if (guild->id == guild_id)
@ -67,7 +67,7 @@ const std::string bot::settings::settings::get_token()
return m_token;
}
bool bot::settings::settings::is_translatebot(uint64_t webhook_id)
bool bot::settings::settings::is_translatebot(dpp::snowflake webhook_id)
{
for (auto id = m_webhookIds.begin(); id != m_webhookIds.end(); id++) {
if (*id == webhook_id)
@ -209,21 +209,17 @@ bool bot::settings::settings::parse(const std::string &filename)
if (json_channel_target.value().is_string()) {
bot::settings::target target;
target.target = json_channel_target.value();
target.webhook = json_channel->at("webhook");
target.webhook = dpp::webhook(json_channel->at("webhook"));
channel.targets.push_back(target);
const dpp::webhook webhook(target.webhook);
m_webhookIds.push_back(webhook.id);
m_webhookIds.push_back(target.webhook.id);
}
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 = json_target.value();
target.webhook = dpp::webhook(json_target.value());
channel.targets.push_back(target);
const dpp::webhook webhook(target.webhook);
m_webhookIds.push_back(webhook.id);
m_webhookIds.push_back(target.webhook.id);
}
}
}

View file

@ -19,6 +19,8 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <cstdint>
#include <dpp/snowflake.h>
#include <dpp/webhook.h>
#include <mutex>
#include <string>
#include <vector>
@ -27,15 +29,15 @@ namespace bot {
namespace settings {
struct target {
std::string target;
std::string webhook;
dpp::webhook webhook;
};
struct channel {
uint64_t id;
dpp::snowflake id;
std::string source;
std::vector<bot::settings::target> targets;
};
struct guild {
uint64_t id;
dpp::snowflake id;
std::vector<bot::settings::channel> channel;
};
struct translate {
@ -49,12 +51,12 @@ namespace bot {
class settings {
public:
uint16_t get_avatar_size();
const bot::settings::channel* get_channel(bot::settings::guild *guild, uint64_t channel_id);
const bot::settings::channel* get_channel(uint64_t guild_id, uint64_t channel_id);
const bot::settings::guild* get_guild(uint64_t guild_id);
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 bot::settings::translate* get_translate();
const std::string get_token();
bool is_translatebot(uint64_t webhook_id);
bool is_translatebot(dpp::snowflake webhook_id);
void lock();
bool parse(const std::string &filename);
void unlock();
@ -65,7 +67,7 @@ namespace bot {
std::vector<bot::settings::guild> m_guilds;
bot::settings::translate m_translate;
std::string m_token;
std::vector<uint64_t> m_webhookIds;
std::vector<dpp::snowflake> m_webhookIds;
};
}
}