-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlanguage.cpp
More file actions
79 lines (63 loc) · 2.51 KB
/
Copy pathlanguage.cpp
File metadata and controls
79 lines (63 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2023 The Anilab Development Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
#include <fstream>
#include <string>
#include <spdlog/spdlog.h>
#include <nlohmann/json.hpp>
#include <cmd_lists.h>
#include <db_handler.h>
using json = nlohmann::json;
void language(dpp::cluster& client, const dpp::slashcommand_t& event)
{
const auto language = std::get<std::string>(event.get_parameter("option"));
DatabaseHandler database;
json language_config;
database.open("./database/language.db");
database.createTable("configuration", "id TEXT, language TEXT");
auto target_user = fmt::format("'{}'", event.command.usr.id);
auto check_user = database.findRecord("configuration", "id=" + target_user);
std::string change_language = "en-us";
if (language == "english")
{
if (check_user)
database.deleteRecord("configuration", "id=" + target_user);
}
else if (language == "japanese")
{
if (check_user)
database.deleteRecord("configuration", "id=" + target_user);
change_language = "ja-jp";
database.insert("configuration", target_user + ", '" + change_language + "'");
}
else if (language == "vietnamese")
{
if (check_user)
database.deleteRecord("configuration", "id=" + target_user);
change_language = "vi-vn";
database.insert("configuration", target_user + ", '" + change_language + "'");
}
auto language_file = fmt::format("./languages/{}.json", change_language);
std::ifstream open_file(language_file);
open_file >> language_config;
auto language_embed = language_config["LANGUAGE"];
auto create_embed = dpp::embed()
.set_title(language_embed["title"])
.set_color(0x38ff9b)
.set_description(language_embed["description"])
.set_timestamp(time(0));
event.reply(dpp::message().add_embed(create_embed).set_flags(dpp::m_ephemeral));
}