-
Notifications
You must be signed in to change notification settings - Fork 1
/
configs.hpp
70 lines (52 loc) · 1.84 KB
/
configs.hpp
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
#pragma once
#include <dpp/dpp.h>
#include <dpp/nlohmann/json.hpp>
#include <iomanip>
#include <sstream>
#include <filesystem>
namespace fs = std::filesystem;
void checkConfigs(const dpp::interaction_create_t& event) {
std::ifstream f;
f.open(fmt::format("./configs/{}.json", event.command.guild_id));
if(!f.good()) {
std::string str = "{ \"leveling\": { \"enabled\": false } }";
std::ofstream configfile;
configfile.open(fmt::format("./configs/{}.json", event.command.guild_id));
configfile << str;
configfile.close();
}
f.close();
}
void checkConfig(std::string id) {
std::ifstream f;
f.open(fmt::format("./configs/{}.json", id));
if(!f.good()) {
std::string str = "{ \"leveling\": { \"enabled\": false, \"xp\": 0, \"level\": 0 } }";
std::ofstream configfile;
configfile.open(fmt::format("./configs/{}.json", id));
configfile << str;
configfile.close();
}
f.close();
std::string path = "./configs/";
for (const auto & entry : fs::directory_iterator(path)) {
//std::cout << entry.path() << std::endl;
if(entry.is_regular_file()) {
std::string s = entry.path().string();
s = s.substr(10);
if(s != "placeholder.txt") {
if(s.length() == 20) { // For some odd reason when using C++20 This has to be 19.
const char* fileC = entry.path().c_str();
std::remove(fileC);
}
}
}
}
}
nlohmann::json getConf(std::string id) {
nlohmann::json x;
std::ifstream y(fmt::format("./configs/{}.json", id));
y >> x;
y.close();
return x;
}