diff --git a/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o b/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o index 542a514..5369f0f 100644 Binary files a/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o and b/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o differ diff --git a/src/commands.cpp b/src/commands.cpp index b464bb4..48a70b9 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -5,7 +5,6 @@ #include #define FILE_WARNING "/FILE/" -#define EMBED_WARNING "/EMBED/" typedef std::string (*vFunc)(void); typedef std::string (*vecFunc)(std::vector); @@ -32,7 +31,20 @@ std::string commandParse(std::vector args) return "Invalid command!"; } -#define FILE_NAME "temp-GBP" +std::string sendFile(std::string filePath, std::string fileName = "") +{ + if (fileName == "") + fileName = filePath; + /* + * Files are sent with: + * FILE_WARNING $PATH $FILENAME + * + * $FILENAME is the name of the file that will be sent to discord, if you don't want the file sent + * to have the save name as the one on disk, or if you have a custom path for the file, set $FILENAME + */ + return std::string(FILE_WARNING) + " " + filePath + " " + fileName; +} + /** * printFullGBPList * @@ -53,10 +65,8 @@ std::string printFullGBPList() } file.close(); - std::string out = std::string(FILE_WARNING) + " " + std::string(FILE_NAME); - return out; + return sendFile("temp-GBP", "gbp-list.txt"); } -#undef FILE_NAME /** * ##fetchGBP diff --git a/src/main.cpp b/src/main.cpp index cc03e1b..7b16b19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,8 @@ using json = nlohmann::json; +#define BOT_COMMAND "!gbp" + /** * ##separateArgs * @@ -29,10 +31,9 @@ std::vector separateArgs(std::string args) if (args.find(" ") == -1) { out.push_back(args); break; - } else { - out.push_back(args.substr(0, args.find(" "))); - args = args.substr(args.find(" ") + 1, args.length() - (args.find(" ") + 1)); } + out.push_back(args.substr(0, args.find(" "))); + args = args.substr(args.find(" ") + 1, args.length() - (args.find(" ") + 1)); } return out; } @@ -47,10 +48,7 @@ std::vector separateArgs(std::string args) */ bool hasCommand(dpp::message msg) { - json config; - std::ifstream configFile("../config.json"); - configFile >> config; - return msg.content.substr(0, (msg.content.find(" "))) == config["bot_command"]; + return msg.content.substr(0, (msg.content.find(" "))) == std::string(BOT_COMMAND); } /** @@ -79,10 +77,9 @@ void onMessage(dpp::cluster &bot, dpp::message msg) dpp::message toSend; if (messageArgs[0] == std::string(FILE_WARNING)) { toSend = dpp::message(msg.channel_id, ""); - toSend.add_file("gbp-list.txt", dpp::utility::read_file(messageArgs[1])); - } else { + toSend.add_file(messageArgs[2], dpp::utility::read_file(messageArgs[1])); + } else toSend = dpp::message(msg.channel_id, msgContent); - } /* Send the message */ bot.message_create(toSend); @@ -95,7 +92,6 @@ int main() json config; std::ifstream configFile("../config.json"); configFile >> config; - std::string token = config["token"]; dpp::cluster bot(token, dpp::i_default_intents | dpp::i_message_content);