dtranslatebot/src/settings.h

96 lines
3.3 KiB
C
Raw Normal View History

2024-01-02 03:45:06 +01:00
/*****************************************************************************
* dtranslatebot Discord Translate Bot
* Copyright (C) 2023-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 SETTINGS_H
#define SETTINGS_H
#include <cstdint>
#include <dpp/snowflake.h>
#include <dpp/webhook.h>
#include <filesystem>
2024-01-02 03:45:06 +01:00
#include <mutex>
#include <string>
2024-01-02 03:45:06 +01:00
#include <vector>
2024-02-04 07:10:02 +01:00
#include "translator_core.h"
2024-01-02 03:45:06 +01:00
namespace bot {
namespace settings {
2024-01-12 11:18:15 +01:00
struct target {
std::string target;
dpp::webhook webhook;
2024-01-12 11:18:15 +01:00
};
2024-01-02 03:45:06 +01:00
struct channel {
dpp::snowflake id;
2024-01-02 03:45:06 +01:00
std::string source;
2024-01-12 11:18:15 +01:00
std::vector<bot::settings::target> targets;
2024-01-02 03:45:06 +01:00
};
struct guild {
dpp::snowflake id;
2024-01-02 03:45:06 +01:00
std::vector<bot::settings::channel> channel;
};
2024-02-04 07:10:02 +01:00
struct translator {
2024-01-02 03:45:06 +01:00
std::string hostname;
uint16_t port;
std::string url;
bool tls;
std::string apiKey;
};
class settings {
public:
2024-02-04 09:24:32 +01:00
/* add functions */
2024-02-04 07:10:02 +01:00
void add_channel(const channel &channel, dpp::snowflake guild_id);
bool add_target(const target &target, dpp::snowflake guild_id, dpp::snowflake channel_id);
void add_translatebot_webhook(dpp::snowflake webhook_id);
2024-02-04 09:24:32 +01:00
/* get functions */
uint16_t avatar_size();
const channel* get_channel(const guild *guild, dpp::snowflake channel_id) const;
const channel* get_channel(dpp::snowflake guild_id, dpp::snowflake channel_id) const;
const guild* get_guild(dpp::snowflake guild_id) const;
const std::vector<std::string> preferred_languages() const;
const std::filesystem::path storage_path() const;
std::unique_ptr<bot::translator::translator> get_translator() const;
const std::string token() const;
/* is functions */
bool is_translatebot(dpp::snowflake webhook_id) const;
/* lock functions */
2024-01-02 03:45:06 +01:00
void lock();
2024-02-04 09:24:32 +01:00
void unlock();
/* parse functions */
2024-02-04 07:10:02 +01:00
bool parse(const std::string &data);
bool parse_file(const std::string &filename);
2024-01-02 03:45:06 +01:00
private:
2024-02-04 09:24:32 +01:00
mutable std::recursive_mutex m_mutex;
size_t m_externallyLockedCount;
2024-01-17 12:38:16 +01:00
uint16_t m_avatarSize;
2024-02-04 07:10:02 +01:00
std::vector<guild> m_guilds;
2024-02-04 09:24:32 +01:00
std::vector<std::string> m_prefLangs;
std::filesystem::path m_storagePath;
bot::settings::translator m_translator;
2024-01-02 03:45:06 +01:00
std::string m_token;
std::vector<dpp::snowflake> m_webhookIds;
2024-01-02 03:45:06 +01:00
};
}
}
2024-01-17 12:38:16 +01:00
#endif // SETTINGS_H