find names

This commit is contained in:
SuperNovaa41 2022-03-04 14:56:16 -05:00
parent c4f555bc6e
commit 2245e48a66
2 changed files with 18 additions and 1 deletions

View File

@ -11,6 +11,7 @@ std::string printFullGBPList(bool = false);
std::string genericResponse(); std::string genericResponse();
std::string helpMessage(); std::string helpMessage();
std::string findNum(int pos); std::string findNum(int pos);
std::string findName(std::string user);
/** /**
* ##commandParse * ##commandParse
@ -37,6 +38,12 @@ std::string commandParse(std::vector<std::string> args)
else else
return "Invalid command!"; return "Invalid command!";
} else if (args[0] == "findname") {
if (args.size() >= 2)
return findName(args[1]);
else
return "Invalid command!";
} else { } else {
return "Invalid command!"; return "Invalid command!";
} }
@ -77,10 +84,20 @@ std::string printFullGBPList(bool update)
std::string findNum(int pos) std::string findNum(int pos)
{ {
std::map<unsigned short int, std::pair<int, std::string>> gbp = readGBPIntoList(); std::map<unsigned short int, std::pair<int, std::string>> gbp = readGBPIntoList();
std::string out = "#" + std::to_string(pos) + ": " + gbp[pos].second + " (" + std::to_string(gbp[pos].first) + "GBP)\n"; std::string out = "#" + std::to_string(pos) + ": " + gbp[pos].second + " (" + std::to_string(gbp[pos].first) + " GBP)\n";
return out; return out;
} }
std::string findName(std::string user)
{
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++) {
if (it->second.second == user)
return "#" + std::to_string(it->first) + ": " + it->second.second + " (" + std::to_string(it->second.first) + " GBP)\n";
}
return "User not found!";
}
/** /**
* ##genericResponse * ##genericResponse
* *