add_target function for settings

This commit is contained in:
Syping 2024-02-03 08:10:28 +01:00
parent 25d83b243d
commit 92b480c8eb
3 changed files with 18 additions and 2 deletions

View file

@ -69,8 +69,7 @@ int main(int argc, char* argv[]) {
return;
const std::lock_guard<bot::settings::settings> guard(settings);
const bot::settings::channel *channel = settings.get_channel(event.msg.guild_id, event.msg.channel_id);
if (channel) {
if (const bot::settings::channel *channel = settings.get_channel(event.msg.guild_id, event.msg.channel_id)) {
bot::message message;
message.id = event.msg.id;

View file

@ -40,6 +40,22 @@ void bot::settings::settings::add_channel(const bot::settings::channel &channel,
m_guilds.push_back(std::move(guild));
}
bool bot::settings::settings::add_target(const bot::settings::target &target, dpp::snowflake guild_id, dpp::snowflake channel_id)
{
for (auto guild = m_guilds.begin(); guild != m_guilds.end(); guild++) {
if (guild->id == guild_id) {
for (auto channel = guild->channel.begin(); channel != guild->channel.end(); channel++) {
if (channel->id == channel_id) {
channel->targets.push_back(target);
return true;
}
}
return false;
}
}
return false;
}
void bot::settings::settings::add_translatebot_webhook(dpp::snowflake webhook_id)
{
m_webhookIds.push_back(webhook_id);

View file

@ -53,6 +53,7 @@ namespace bot {
class settings {
public:
void add_channel(const bot::settings::channel &channel, dpp::snowflake guild_id);
bool add_target(const bot::settings::target &target, dpp::snowflake guild_id, dpp::snowflake channel_id);
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);