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 <mutex>
|
2024-02-06 16:19:08 +01:00
|
|
|
#include "database_core.h"
|
|
|
|
#include "settings_types.h"
|
2024-02-04 07:10:02 +01:00
|
|
|
#include "translator_core.h"
|
2024-01-02 03:45:06 +01:00
|
|
|
|
|
|
|
namespace bot {
|
|
|
|
namespace settings {
|
|
|
|
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);
|
2024-02-03 07:16:12 +01:00
|
|
|
void add_translatebot_webhook(dpp::snowflake webhook_id);
|
2024-02-04 09:24:32 +01:00
|
|
|
|
|
|
|
/* get functions */
|
|
|
|
uint16_t avatar_size();
|
2024-02-18 22:26:02 +01:00
|
|
|
static channel* get_channel(guild *guild, dpp::snowflake channel_id);
|
|
|
|
channel* get_channel(dpp::snowflake guild_id, dpp::snowflake channel_id);
|
|
|
|
guild* get_guild(dpp::snowflake guild_id);
|
|
|
|
target* get_target(dpp::snowflake guild_id, dpp::snowflake channel_id, const std::string &target);
|
|
|
|
static target* get_target(channel *channel, const std::string &target);
|
|
|
|
static const target* get_target(const channel *channel, const std::string &target);
|
2024-02-04 09:24:32 +01:00
|
|
|
const std::vector<std::string> preferred_languages() const;
|
2024-02-06 16:19:08 +01:00
|
|
|
std::shared_ptr<bot::database::database> get_database() const;
|
2024-02-04 09:24:32 +01:00
|
|
|
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-06 16:19:08 +01:00
|
|
|
std::shared_ptr<bot::database::database> m_database;
|
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;
|
|
|
|
bot::settings::translator m_translator;
|
2024-01-02 03:45:06 +01:00
|
|
|
std::string m_token;
|
2024-01-20 10:02:55 +01:00
|
|
|
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
|