improved find name

This commit is contained in:
SuperNovaa41 2022-03-04 16:07:12 -05:00
parent 8bf125ce6e
commit 2c726b556e
2 changed files with 13 additions and 5 deletions

View File

@ -33,7 +33,7 @@ std::string commandParse(std::vector<std::string> args)
return genericResponse(); return genericResponse();
} else if (args[0] == "help") { } else if (args[0] == "help") {
return helpMessage(); return helpMessage();
} else if (args[0] == "findpos" ) { } else if (args[0] == "findpos") {
if (args.size() >= 2) if (args.size() >= 2)
return findNum(std::stoi(args[1])); return findNum(std::stoi(args[1]));
} else if (args[0] == "findname") { } else if (args[0] == "findname") {
@ -42,6 +42,9 @@ std::string commandParse(std::vector<std::string> args)
} else if (args[0] == "findgbp") { } else if (args[0] == "findgbp") {
if (args.size() >= 2) if (args.size() >= 2)
return findGBP(std::stoi(args[1])); return findGBP(std::stoi(args[1]));
} else if (args[0] == "fetchgbp") {
fetchLatestGBP();
return "Fetched latest GBP!";
} }
return "Invalid command!"; return "Invalid command!";
} }
@ -103,13 +106,18 @@ std::string findNum(int pos)
*/ */
std::string findName(std::string user) std::string findName(std::string user)
{ {
std::string out = "```";
std::map<unsigned short int, std::pair<int, std::string>> gbp = readGBPIntoList(); std::map<unsigned short int, std::pair<int, std::string>> gbp = readGBPIntoList();
for (std::map<unsigned short int, std::pair<int, std::string>>::iterator it = gbp.begin(); it != gbp.end(); it++) { for (std::map<unsigned short int, std::pair<int, std::string>>::iterator it = gbp.begin(); it != gbp.end(); it++) {
if (it->second.second.find(user) != -1) { if (it->second.second.find(user) != -1) {
return "```#" + std::to_string(it->first) + ": " + it->second.second + " (" + std::to_string(it->second.first) + " GBP)```\n"; out += "#" + std::to_string(it->first) + ": " + it->second.second + " (" + std::to_string(it->second.first) + " GBP)\n";
} }
} }
out += "```";
if (out == "``````")
return "User not found!"; return "User not found!";
return out;
} }
/** /**