diff --git a/.gitignore b/.gitignore index 584ef46..ffecea5 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ balances.txt gbp-bot +temp-GBP diff --git a/build/CMakeFiles/gbp-bot.dir/CXX.includecache b/build/CMakeFiles/gbp-bot.dir/CXX.includecache index c9e2a22..0cb730d 100644 --- a/build/CMakeFiles/gbp-bot.dir/CXX.includecache +++ b/build/CMakeFiles/gbp-bot.dir/CXX.includecache @@ -1121,6 +1121,8 @@ gbp.cpp /home/seth/documents/programming/discord-bots/gbp/src/gbp.cpp string - +vector +- /home/seth/documents/programming/discord-bots/gbp/src/gbp.cpp string diff --git a/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o b/build/CMakeFiles/gbp-bot.dir/src/main.cpp.o index 51272d1..90c6d8d 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/config.json b/config.json index d08949d..612f34d 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { - "token": "OTQ5MTIxNDU2MTY2NTM5Mjk2.YiFwPA.WEl7l-Q0aH3aQNE7mZc2jN8Z0TU", + "token": "token here", "bot_command": "!gbp" } diff --git a/src/commands.cpp b/src/commands.cpp index 75d242d..a423558 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1,10 +1,25 @@ #include "gbp.cpp" #include +#include #define FILE_WARNING "/FILE/" +std::string printFullGBPList(bool = false); +std::string genericResponse(); + +std::string commandParse(std::vector args) +{ + if (args[0] == "gbplist") + return printFullGBPList(); + else if (args[0] == "hi") + return genericResponse(); + else + return "Invalid command!"; +} + + #define FILE_NAME "temp-GBP" -std::string printFullGBPList(bool update = false) +std::string printFullGBPList(bool update) { std::map> gbp; if (update) @@ -23,10 +38,12 @@ std::string printFullGBPList(bool update = false) } file.close(); - std::string out; - out.append(FILE_WARNING); - out.append(" "); - out.append(FILE_NAME); + std::string out = std::string(FILE_WARNING) + " " + std::string(FILE_NAME); return out; } #undef FILE_NAME + +std::string genericResponse() +{ + return "Fuck you"; +} diff --git a/src/main.cpp b/src/main.cpp index f04aba9..0a89007 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,21 @@ using json = nlohmann::json; +std::vector separate_args(std::string args) +{ + std::vector out; + while (1) { + 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)); + } + } + return out; +} + /** * ##hasCommand * @@ -29,6 +44,21 @@ bool hasCommand(dpp::message msg) return msg.content.substr(0, (msg.content.find(" "))) == config["bot_command"]; } +dpp::message setMessage(unsigned int channel_id, std::string content) +{ + std::vector messageArgs = separate_args(content); + if (messageArgs[0] == std::string(FILE_WARNING)) { + dpp::message msg = dpp::message(channel_id, ""); + msg.add_file("gbp-list.txt", dpp::utility::read_file(content.substr(content.find(" ") + 1, content.length() - (content.find(" ") + 1)))); + return msg; + } else { + dpp::message msg = dpp::message(channel_id, content); + return msg; + } +} + + + /** * ##onMessage * @@ -42,18 +72,15 @@ void onMessage(dpp::cluster &bot, dpp::message msg) { if (!hasCommand(msg)) return; - std::cout << "Command received!\n"; - int argIdx = msg.content.find(" ") + 1; std::string argument = msg.content.substr(argIdx, msg.content.length() - argIdx); - std::string msgContent = ""; + std::vector args = separate_args(argument); + std::string msgContent = commandParse(args); + std::cout << msgContent << std::endl; - - - - dpp::message toSend = dpp::message(msg.channel_id, msgContent); + dpp::message toSend = setMessage(msg.channel_id, msgContent); bot.message_create(toSend); }