-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
475 lines (419 loc) · 19.4 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#include <iostream>
#include <cstdio>
#include <array>
#include <memory>
#include <unistd.h>
#include <stdexcept>
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <sys/types.h>
#include <fstream>
#include <string>
#include <cmath>
#include "./headers/presences.hpp"
#include "./headers/avatar-manipulation.cpp"
#include "./headers/extra-responses.hpp"
// visit dpp.dev for this dependency ;)
#include <dpp/dpp.h>
const std::string AUTHOR_ID = "708857740965183559";
const std::string PREFIX = "++";
std::string exec(std::string command) {
char buffer[128];
std::string result = "";
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) return "popen failed!";
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != NULL) result += buffer;
}
pclose(pipe);
return result;
}
template<typename ... Args>
std::string string_format( const std::string& format, Args ... args ) {
int size_s = std::snprintf( nullptr, 0, format.c_str(), args ... ) + 1;
if( size_s <= 0 ){ throw std::runtime_error( "Error during formatting." ); }
auto size = static_cast<size_t>( size_s );
std::unique_ptr<char[]> buf( new char[ size ] );
std::snprintf( buf.get(), size, format.c_str(), args ... );
return std::string( buf.get(), buf.get() + size - 1 );
}
int main() {
srand(time(0));
std::ifstream webhook_main_updates_channel ("updates1-webhook.txt");
std::ifstream webhook_second_updates_channel ("updates2-webhook.txt");
std::string updates_webhook_string, updates2_webhook_string;
dpp::webhook main_updates;
dpp::webhook ohio_updates;
if (webhook_main_updates_channel.is_open() && webhook_main_updates_channel.good()) {
webhook_main_updates_channel >> updates_webhook_string;
main_updates = dpp::webhook(updates_webhook_string);
} else {
std::cout << "no webhook main update url file" << std::endl;
}
if (webhook_second_updates_channel.is_open() && webhook_second_updates_channel.good()) {
webhook_second_updates_channel >> updates2_webhook_string;
ohio_updates = dpp::webhook(updates2_webhook_string);
} else {
std::cout << "no webhook ohio's update url file" << std::endl;
}
std::fstream tokenfile ("token.txt");
std::string token;
if (tokenfile.is_open() && tokenfile.good()) {
tokenfile >> token;
} else {
std::cout << "file cointaining token either doesn't exist or don't have read permissions." << std::endl;
std::ofstream outfile("token.txt");
outfile << "your-token-here";
outfile.close();
std::cout << "a token file was created, replace all contents in the file with your token." << std::endl;
exit(1);
}
dpp::cluster bot(token, dpp::i_default_intents | dpp::i_message_content);
bot.on_log(dpp::utility::cout_logger());
bot.on_message_create([&bot, main_updates, ohio_updates] (const dpp::message_create_t &event) {
if ((event.msg.content.find("bot") != std::string::npos &&
(event.msg.content.find("shutdown") != std::string::npos ||
event.msg.content.find("die") != std::string::npos)) &&
(event.msg.author.id).operator nlohmann::json() == AUTHOR_ID) {
bot.message_create(dpp::message(event.msg.channel_id, "as you wish.")
.set_reference(event.msg.id));
sleep(5);
bot.shutdown();
}
if ((event.msg.content.find("bot") != std::string::npos && event.msg.content.find("recompile") != std::string::npos) &&
(event.msg.author.id).operator nlohmann::json() == AUTHOR_ID) {
bot.message_create(dpp::message(event.msg.channel_id, "as you wish.")
.set_reference(event.msg.id));
sleep(2);
std::string recompile = exec("make recompile");
sleep(10);
if (recompile.find("Leaving") != std::string::npos || recompile.find("Error") != std::string::npos) {
dpp::message embed = dpp::message().add_embed(dpp::embed()
.set_color(dpp::colors::red)
.set_title(bot.me.username + " faced a recompile error")
.add_field("Compile error!", "Something went wrong recompiling my code. Look at the terminal for more information.", true)
.add_field("Verified.", "Only authorized webhooks can send this message.", true)
.set_thumbnail(bot.me.get_avatar_url())
);
bot.execute_webhook_sync(main_updates, embed);
bot.execute_webhook_sync(ohio_updates, embed);
}
sleep(2);
bot.shutdown();
}
Extras extra;
extra.responses(event, bot);
if (event.msg.content == PREFIX + "help") {
dpp::embed embed = dpp::embed().
set_color(dpp::colors::sti_blue).
set_title("Hey, i got some commands!").
set_description("Looks like you've waited a decade to this help be developed! so here i go.").
add_field(
"I have",
"/rgb /couple /gaytest /putatest and /notify-karbox-pc go testing ima fix this message later."
).
set_timestamp(time(0)).
set_footer(dpp::embed_footer().set_icon(event.msg.author.get_avatar_url()).set_text(event.msg.author.username));
bot.message_create(dpp::message(event.msg.channel_id, embed).set_reference(event.msg.id));
}
});
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "soma-seq") {
double terms[] = {
std::get<double>(event.get_parameter("stermo-1")),
std::get<double>(event.get_parameter("stermo-2")),
std::get<double>(event.get_parameter("stermo-3"))
};
int n = std::get<int64_t>(event.get_parameter("n-stermo"));
float r;
float r1 = (float)terms[1] - (float)terms[0];
float r2 = (float)terms[2] - (float)terms[1];
int rr1, rr2;
bool isPA, validSequence, rIsReal;
if (r1 == r2) {
r = r1;
isPA = true;
validSequence = true;
if (r != std::round(r)) { rIsReal = true; } else { rIsReal = false; }
} else {
r1 = (float)terms[1] / (float)terms[0];
r2 = (float)terms[2] / (float)terms[1];
rr1 = static_cast<int>(terms[1]) % static_cast<int>(terms[0]);
rr2 = static_cast<int>(terms[2]) % static_cast<int>(terms[1]);
if (r1 == r2) {
r = r1;
isPA = false;
validSequence = true;
if (rr1 == 0 && rr2 == 0) { rIsReal = false; } else { rIsReal = true; }
} else {
validSequence = false;
}
}
float sn;
if (isPA && validSequence) {
sn = (((float)terms[0] + n) * n) / 2;
event.reply(string_format("A soma dos números da sequência até o termo %i, é igual a %.2f (r=%.2f)", n, sn, r));
} else if (!isPA && validSequence) {
if (0 < r && r < 1) {
//PG Infinita
sn = ((float)terms[0]) / (1 - r);
} else {
// PG Finita
sn = ((float)terms[0] * (std::pow(r, n) - 1)) / (r - 1);
}
event.reply(string_format(
"A soma dos termos da sequência até o termo %i é igual a %.2f de razão q=%.4f, (%.0f de resto %i)"
, n, sn, r, std::round(r), rr1)
);
} else if (!validSequence) {
event.reply("A soma da sequência acima não existe, razão entre termos é irregular.");
}
}
if (event.command.get_command_name() == "sequence") {
double terms[] = {
std::get<double>(event.get_parameter("termo-1")),
std::get<double>(event.get_parameter("termo-2")),
std::get<double>(event.get_parameter("termo-3"))
};
int n = std::get<int64_t>(event.get_parameter("n-termo"));
float r;
float r1 = (float)terms[1] - (float)terms[0];
float r2 = (float)terms[2] - (float)terms[1];
int rr1, rr2;
bool isPA, validSequence, rIsReal;
if (r1 == r2) {
r = r1;
isPA = true;
validSequence = true;
if (r != std::round(r)) { rIsReal = true; } else { rIsReal = false; }
} else {
r1 = (float)terms[1] / (float)terms[0];
r2 = (float)terms[2] / (float)terms[1];
rr1 = static_cast<int>(terms[1]) % static_cast<int>(terms[0]);
rr2 = static_cast<int>(terms[2]) % static_cast<int>(terms[1]);
if (r1 == r2) {
r = r1;
isPA = false;
validSequence = true;
if (rr1 == 0 && rr2 == 0) { rIsReal = false; } else { rIsReal = true; }
} else {
validSequence = false;
}
}
float an;
if (isPA && validSequence) {
an = (float)terms[0] + (n - 1) * r;
event.reply(string_format("O %i termo é igual a %.4f de razão r=%.2f\n", n, an, r));
} else if (!isPA && validSequence) {
an = (float)terms[0] * std::pow(r, n-1);
event.reply(string_format("O %i termo é igual a %.4f de razão q=%.4f, (%.0f de resto %i)\n", n, an, r, std::round(r), rr1));
} else if (!validSequence) {
event.reply("A sequência não existe, razão entre termos é irregular.");
}
}
if (event.command.get_command_name() == "putatest") {
auto who = std::get<dpp::snowflake>(event.get_parameter("who"));
auto whoUser = event.command.get_resolved_user(who);
dpp::user msgauthor = event.command.get_issuing_user();
std::string usermention = whoUser.get_mention();
dpp::snowflake id = whoUser.id;
std::string avatar = whoUser.get_avatar_url();
if (id.operator nlohmann::json() == "851214582122283048") {
dpp::embed embed = dpp::embed().set_color(dpp::colors::black)
.set_description(usermention + std::string(" é 100% **puta**."))
.set_timestamp(time(0))
.set_title("100% PIRANHA")
.set_thumbnail(avatar)
.set_footer(dpp::embed_footer().set_icon(msgauthor.get_avatar_url()).set_text(msgauthor.username));
event.reply(dpp::message().add_embed(embed));
} else {
int puta = std::rand() % 100;
dpp::embed embed = dpp::embed().set_color(dpp::colors::red)
.set_description(usermention + std::string(" é " + std::to_string(puta) + "% puta/puto."))
.set_timestamp(time(0))
.set_title(std::to_string(puta) + "% Piranho")
.set_thumbnail(avatar)
.set_footer(dpp::embed_footer().set_icon(msgauthor.get_avatar_url()).set_text(msgauthor.username));
event.reply(dpp::message().add_embed(embed));
}
}
if (event.command.get_command_name() == "gaytest") {
auto who = std::get<dpp::snowflake>(event.get_parameter("who"));
auto whoUser = event.command.get_resolved_user(who);
dpp::user msgauthor = event.command.get_issuing_user();
std::string usermention = whoUser.get_mention();
dpp::snowflake id = whoUser.id;
std::string avatar = whoUser.get_avatar_url();
if (id.operator nlohmann::json() == AUTHOR_ID) {
dpp::embed embed = dpp::embed().set_color(dpp::colors::black)
.set_description(usermention + std::string(" é 0% gay."))
.set_timestamp(time(0))
.set_title("100% HETERO")
.set_thumbnail(avatar)
.set_footer(dpp::embed_footer().set_icon(msgauthor.get_avatar_url()).set_text(msgauthor.username));
event.reply(dpp::message().add_embed(embed));
} else if (id.operator nlohmann::json() == "381637890679111692") { // reynan
dpp::embed embed = dpp::embed().set_color(dpp::colors::pink)
.set_description(usermention + std::string(" é 0% hétero."))
.set_timestamp(time(0))
.set_title("100% GAY!!!")
.set_thumbnail(avatar)
.set_footer(dpp::embed_footer().set_icon(msgauthor.get_avatar_url()).set_text(msgauthor.username));
event.reply(dpp::message().add_embed(embed));
} {
int gay = std::rand() % 100;
//event.reply(usermention + " é " + gay + "% gay.");
dpp::embed embed = dpp::embed().set_color(dpp::colors::endeavour)
.set_description(usermention + std::string(" é " + std::to_string(gay) + "% gay."))
.set_timestamp(time(0))
.set_title(std::to_string(100 - gay) + "% Hétero")
.set_thumbnail(avatar)
.set_footer(dpp::embed_footer().set_icon(msgauthor.get_avatar_url()).set_text(msgauthor.username));
event.reply(dpp::message().add_embed(embed));
}
}
if (event.command.get_command_name() == "notify-karbox-pc") {
std::string message = std::get<std::string>(event.get_parameter("notification"));
dpp::user whosent = event.command.get_issuing_user();
dpp::embed embed = dpp::embed().set_color(dpp::colors::green)
.set_title("Message sent!")
.set_timestamp(time(0))
.add_field("Note", "All especial characteres that could break the syntax function of the notification call, will be deleted.");
event.reply(dpp::message().add_embed(embed));
std::replace(message.begin(), message.end(), '\'', char(' '));
std::replace(message.begin(), message.end(), '"', char(' '));
std::replace(message.begin(), message.end(), ';', char(' '));
std::replace(message.begin(), message.end(), '>', char(' '));
exec("notify-send 'C++ Discord Project' '" + whosent.username + " sent: " + message + "'");
}
if (event.command.get_command_name() == "rgb") {
dpp::user author = event.command.get_issuing_user();
int64_t r = std::get<int64_t>(event.get_parameter("red"));
int64_t g = std::get<int64_t>(event.get_parameter("green"));
int64_t b = std::get<int64_t>(event.get_parameter("blue"));
int64_t a = std::get<int64_t>(event.get_parameter("alpha"));
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (a > 1) a = 1;
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
if (a < 0) a = 0;
Avatar avatar;
auto rgba = avatar.createRGBA(r, g, b, a);
auto rgb = avatar.createRGB(r, g, b);
event.reply(dpp::message()
.add_embed(dpp::embed()
.set_color(rgb)
.set_title("Prontinho.")
.set_timestamp(time(0))
.add_field("RGB", std::to_string(rgb), true)
.add_field("RGBA", std::to_string(rgba), true)
)
);
}
if (event.command.get_command_name() == "couple") {
dpp::user user1 = event.command.get_resolved_user(std::get<dpp::snowflake>(event.get_parameter("user1")));
dpp::user user2 = event.command.get_resolved_user(std::get<dpp::snowflake>(event.get_parameter("user2")));
std::string half_user1 = user1.username.substr(0, round(user1.username.length()/2));
std::string half_user2 = user2.username.substr(round(user2.username.length()/2));
int porcent = round(std::rand() % 100);
std::string loading_ascii = "▰";
std::string background_ascii = "▱";
std::string progress_ascii = "";
std::uint32_t color = dpp::colors::red;
char* emoji = (char*)"./media/vomiting.png";
for (int i=0; i<10;i++) {
if (i<(porcent/10)) progress_ascii += loading_ascii;
if (i>(porcent/10)) progress_ascii += background_ascii;
}
if (porcent >= 35) emoji = (char*)"./media/thumbsup.png";
if (porcent >= 50) color = dpp::colors::forest_green;
if (porcent >= 60) { color = dpp::colors::lime; emoji = (char*)"heart"; }
Avatar avatar;
event.thinking();
bool hasDefaultAvatar = (user1.get_avatar_url().find("embed") != std::string::npos) ||
(user2.get_avatar_url().find("embed") != std::string::npos);
std::string result = avatar.run(user1.get_avatar_url(), user2.get_avatar_url(), emoji, hasDefaultAvatar);
dpp::message answer = dpp::message().add_embed(dpp::embed().set_color(color)
.set_title("Quão compatível será esse casal?")
.add_field("Casal", user1.get_mention() + " e " + user2.get_mention(), true)
.add_field("Compatibilidade", std::string(half_user1+half_user2)+" : **"+progress_ascii+"** "+std::to_string(porcent)+"%", true)
.set_image("attachment://" + result)
.set_timestamp(time(0))
.set_footer(dpp::embed_footer()
.set_icon(event.command.get_issuing_user().get_avatar_url())
.set_text(event.command.get_issuing_user().username)
)
).add_file(result, dpp::utility::read_file(result));
event.edit_original_response(answer);
remove(result.c_str());
}
});
bot.on_ready([&bot, main_updates, ohio_updates](const dpp::ready_t& event) {
dpp::message embed = dpp::message().add_embed(dpp::embed()
.set_color(dpp::colors::green)
.set_title(bot.me.username + " is online now.")
.add_field("Bot is ready!", "if you see this message more than once in 3 minutes, KarboXXX is probably having a hard time debugging me.", true)
.add_field("Verified.", "Only authorized webhooks can send this message.", true)
.set_thumbnail(bot.me.get_avatar_url())
);
bot.execute_webhook_sync(main_updates, embed);
bot.execute_webhook_sync(ohio_updates, embed);
Presences presences;
presences.default_type(bot);
bot.start_timer([&](const dpp::timer &timing) {
Presences presences;
int random_selected = (std::rand() % 3);
switch (random_selected) {
default: presences.default_type(bot);
case 0: presences.servers_type(bot);
break;
case 1: presences.default_type(bot);
break;
case 2: presences.suggestions_type(bot);
break;
}
}, 10);
if (dpp::run_once<struct register_bot_commands>()) {
dpp::slashcommand rgb("rgb", "gera um número inteiro, que vale um código RGB(A).", bot.me.id);
rgb.add_option( dpp::command_option(dpp::co_integer, "red", "Valor vermelho entre 0 e 255", true) );
rgb.add_option( dpp::command_option(dpp::co_integer, "green", "Valor verde entre 0 e 255", true) );
rgb.add_option( dpp::command_option(dpp::co_integer, "blue", "Valor azul entre 0 e 255", true) );
rgb.add_option( dpp::command_option(dpp::co_integer, "alpha", "Valor de opacidade entre 0 e 1", true) );
dpp::slashcommand gaytest("gaytest", "mostra o quão gay alguém é.", bot.me.id);
gaytest.add_option( dpp::command_option(dpp::co_user, "who", "Quem?", true) );
dpp::slashcommand putatest("putatest", "mostra o quão puta alguém é.", bot.me.id);
putatest.add_option( dpp::command_option(dpp::co_user, "who", "Quem?", true) );
dpp::slashcommand papg("sequence", "calcula PA ou PG de uma sequência.", bot.me.id);
papg.add_option( dpp::command_option(dpp::co_number, "termo-1", "Primeiro termo", true) );
papg.add_option( dpp::command_option(dpp::co_number, "termo-2", "Segundo termo", true) );
papg.add_option( dpp::command_option(dpp::co_number, "termo-3", "Terceiro termo", true) );
papg.add_option( dpp::command_option(dpp::co_integer, "n-termo", "Termo que você quer descobrir", true) );
dpp::slashcommand somapapg("soma-seq", "calcula a soma de uma PA ou PG.", bot.me.id);
somapapg.add_option( dpp::command_option(dpp::co_number, "stermo-1", "Primeiro termo", true) );
somapapg.add_option( dpp::command_option(dpp::co_number, "stermo-2", "Segundo termo", true) );
somapapg.add_option( dpp::command_option(dpp::co_number, "stermo-3", "Terceiro termo", true) );
somapapg.add_option( dpp::command_option(dpp::co_integer, "n-stermo", "Termo que você quer descobrir", true) );
dpp::slashcommand notify("notify-karbox-pc", "manda uma notificação pro computador do karbox.", bot.me.id);
notify.add_option( dpp::command_option(dpp::co_string, "notification", "Notificação em texto.", true) );
dpp::slashcommand couple("couple", "Quão bem esse casal daria?", bot.me.id);
couple.add_option( dpp::command_option(dpp::co_user, "user1", "Primeira pessoa", true) );
couple.add_option( dpp::command_option(dpp::co_user, "user2", "Segunda pessoa", true) );
bot.global_command_create(couple);
bot.global_command_create(gaytest);
bot.global_command_create(putatest);
bot.global_command_create(notify);
bot.global_command_create(rgb);
bot.global_command_create(papg);
bot.global_command_create(somapapg);
// bot.global_bulk_command_create({couple, gaytest, putatest, notify, rgb});
}
});
bot.start(dpp::st_wait);
return 0;
}