-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
130 lines (105 loc) · 4.16 KB
/
main.cpp
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// DPP Includes
#include <dpp/dpp.h>
#include <dpp/fmt/format.h>
#include <dpp/nlohmann/json.hpp>
// Other Includes
#include <iomanip>
#include <sstream>
#include <vector>
#include <iostream>
#include <map>
// Project Includes
#include "configs.hpp"
#include "versions.hpp"
#include "cmds/bounce.hpp"
#include "cmds/info.hpp"
#include "cmds/ping.hpp"
#include "cmds/user-conf.hpp"
#include "cmds/guild-conf.hpp"
#include "cmds/leveling.hpp"
// Constants or Other Top-Level stuff
using json = nlohmann::json;
using namespace std;
void print_map( const dpp::slashcommand_map &m )
{
for ( const auto &[ key, value ] : m )
{
std::cout << key << " = " << value.name.c_str() << "; ";
std::cout << "\n";
}
//std::cout << "\n";
}
/*
@brief sus
*/
int main()
{
json configdocument;
std::ifstream configfile("./config.json");
configfile >> configdocument;
configfile.close();
dpp::cluster bot(configdocument["token"], dpp::i_default_intents | dpp::i_guild_members, 1);
bot.on_ready([&bot](const dpp::ready_t & event) {
std::cout << "Logged in as " << bot.me.username << "!" << std::endl;
bot.set_presence(dpp::presence(dpp::ps_online, dpp::at_listening, "your commands."));
// Create commands.
// Deleting commands.
bot.global_commands_get( [ & ]( const dpp::confirmation_callback_t &callback )
{ print_map( std::get< dpp::slashcommand_map >( callback.value ) ); if(callback.is_error()) std::cout << "sus";} );
//bot.global_command_delete(880716369656696873);
bot.current_user_get_guilds( [ & ]( const dpp::confirmation_callback_t &callback )
{
const auto &guilds = std::get< dpp::guild_map >( callback.value );
unsigned int gsize = guilds.size();
std::printf( "> Guild Count: %u\n", gsize );
for ( const auto &[ guild_snowflake, guild ] : guilds )
{
std::printf( "> Guild Name: %s\n", guild.name.c_str() );
}
} );
// Creating version. (Moved into versions.hpp)
cout << OB::getV().getText();
});
bot.on_interaction_create([&bot](const dpp::interaction_create_t & event) {
if (event.command.type == dpp::it_application_command) {
dpp::command_interaction cmd_data = std::get<dpp::command_interaction>(event.command.data);
checkConfigs(event);
checkConfig(std::to_string(event.command.usr.id));
if(cmd_data.name == "bounce") bounce_cmd::execute(event, cmd_data);
if(cmd_data.name == "info") info_cmd::execute(event, cmd_data, &bot);
if(cmd_data.name == "ping") ping_cmd::execute(event, cmd_data);
if(cmd_data.name == "user-config") user_conf_cmd::execute(event, cmd_data);
if(cmd_data.name == "guild-config") guild_conf_cmd::execute(event, cmd_data);
if(cmd_data.name == "leveling") leveling_cmd::execute(event, cmd_data);
}
});
bot.on_message_create([&bot](const dpp::message_create_t & event) {
//int integer = event.msg->member.user_id;
checkConfig(to_string(event.msg->member.user_id));
std::string id = std::to_string(event.msg->guild_id);
std::string id2 = std::to_string(event.msg->member.user_id);
if(getConf(id)["leveling"]["enabled"] && getConf(id2)["leveling"]["enabled"]) {
json z = getConf(id2);
int zint = z["leveling"]["xp"];
int vint = z["leveling"]["level"];
z["leveling"]["xp"] = zint + 1;
int v = z["leveling"]["level"];
int u = z["leveling"]["xp"];
int w = v * 15;
if(zint > w) {
z["leveling"]["level"] = vint + 1;
z["leveling"]["xp"] = 0;
}
std::ofstream o(fmt::format("./configs/{}.json", id2));
o << std::setw(4) << z << std::endl;
o.close();
}
});
/*bot.on_log([](const dpp::log_t & event) {
if (event.severity > dpp::ll_trace) {
std::cout << event.message << "\n";
} //I decided this is unnecessary.
});*/
bot.start(false);
return 0;
}