adds file sanitizing to automatically convert long messages to text files
This commit is contained in:
parent
837af4239a
commit
c4ec549fd0
@ -3,6 +3,24 @@
|
|||||||
#include <dpp/commandhandler.h>
|
#include <dpp/commandhandler.h>
|
||||||
#include <dpp/message.h>
|
#include <dpp/message.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
#define TEMP_FILE_NAME "gbp.txt"
|
||||||
|
void sanitize_message(std::string &content, dpp::message &msg)
|
||||||
|
{
|
||||||
|
if (content.length() < 2000)
|
||||||
|
return;
|
||||||
|
std::ofstream file(TEMP_FILE_NAME);
|
||||||
|
for (int i = 0; i < content.length(); i++) {
|
||||||
|
if (content[i] != '`')
|
||||||
|
file << content[i];
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
content = "";
|
||||||
|
msg.add_file(TEMP_FILE_NAME, dpp::utility::read_file(TEMP_FILE_NAME));
|
||||||
|
}
|
||||||
|
#undef TEMP_FILE_NAME
|
||||||
|
|
||||||
void init_commands(dpp::commandhandler &command_handler)
|
void init_commands(dpp::commandhandler &command_handler)
|
||||||
{
|
{
|
||||||
@ -16,13 +34,16 @@ void init_commands(dpp::commandhandler &command_handler)
|
|||||||
if (!parameters.empty())
|
if (!parameters.empty())
|
||||||
username = std::get<std::string>(parameters[0].second);
|
username = std::get<std::string>(parameters[0].second);
|
||||||
std::string response = find_username(username);
|
std::string response = find_username(username);
|
||||||
command_handler.reply(dpp::message(response), src);
|
dpp::message msg;
|
||||||
|
sanitize_message(response, msg);
|
||||||
|
msg.set_content(response);
|
||||||
|
command_handler.reply(msg, src);
|
||||||
},
|
},
|
||||||
"Finds the github username, and their associated GBP value."
|
"Finds the github username, and their associated GBP value."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Command added!\n";
|
std::cout << "Command added 1!\n";
|
||||||
command_handler.add_command(
|
command_handler.add_command(
|
||||||
"findgbp",
|
"findgbp",
|
||||||
{
|
{
|
||||||
@ -33,7 +54,10 @@ void init_commands(dpp::commandhandler &command_handler)
|
|||||||
if (!parameters.empty())
|
if (!parameters.empty())
|
||||||
gbp = std::stoi(std::get<std::string>(parameters[0].second));
|
gbp = std::stoi(std::get<std::string>(parameters[0].second));
|
||||||
std::string response = find_gbp(gbp);
|
std::string response = find_gbp(gbp);
|
||||||
command_handler.reply(dpp::message(response), src);
|
dpp::message msg;
|
||||||
|
sanitize_message(response, msg);
|
||||||
|
msg.set_content(response);
|
||||||
|
command_handler.reply(msg, src);
|
||||||
},
|
},
|
||||||
"Finds the users with the amount of GBP provided."
|
"Finds the users with the amount of GBP provided."
|
||||||
);
|
);
|
||||||
@ -49,17 +73,18 @@ void init_commands(dpp::commandhandler &command_handler)
|
|||||||
if (!parameters.empty())
|
if (!parameters.empty())
|
||||||
pos = std::stoi(std::get<std::string>(parameters[0].second));
|
pos = std::stoi(std::get<std::string>(parameters[0].second));
|
||||||
std::string response = find_gbp_pos(pos);
|
std::string response = find_gbp_pos(pos);
|
||||||
command_handler.reply(dpp::message(response), src);
|
dpp::message msg;
|
||||||
|
sanitize_message(response, msg);
|
||||||
|
msg.set_content(response);
|
||||||
|
command_handler.reply(msg, src);
|
||||||
},
|
},
|
||||||
"Finds the users with the amount of GBP provided."
|
"Finds the user at the specified spot on the leaderboard."
|
||||||
);
|
);
|
||||||
|
|
||||||
std::cout << "Command added!\n";
|
std::cout << "Command added!\n";
|
||||||
command_handler.add_command(
|
command_handler.add_command(
|
||||||
"fetchgbp",
|
"fetchgbp",
|
||||||
{
|
{},
|
||||||
{"Test", dpp::param_info(dpp::pt_string, true, "test")}
|
|
||||||
},
|
|
||||||
[&command_handler](const std::string &command, const dpp::parameter_list_t ¶meters, dpp::command_source src) {
|
[&command_handler](const std::string &command, const dpp::parameter_list_t ¶meters, dpp::command_source src) {
|
||||||
fetch_raw_gbp();
|
fetch_raw_gbp();
|
||||||
command_handler.reply(dpp::message("Fetched latest GBP!"), src);
|
command_handler.reply(dpp::message("Fetched latest GBP!"), src);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user