Findpos command

This commit is contained in:
SuperNovaa41 2022-03-04 14:46:39 -05:00
parent 8e29c3dfa6
commit c4f555bc6e
5 changed files with 51 additions and 7 deletions

View File

@ -1121,8 +1121,12 @@ gbp.cpp
/home/seth/documents/programming/discord-bots/gbp/src/gbp.cpp
string
-
unordered_map
-
vector
-
algorithm
-
/home/seth/documents/programming/discord-bots/gbp/src/gbp.cpp
string

View File

@ -1,11 +1,16 @@
#include "gbp.cpp"
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#define FILE_WARNING "/FILE/"
#define EMBED_WARNING "/EMBED/"
std::string printFullGBPList(bool = false);
std::string genericResponse();
std::string helpMessage();
std::string findNum(int pos);
/**
* ##commandParse
@ -17,12 +22,24 @@ std::string genericResponse();
*/
std::string commandParse(std::vector<std::string> args)
{
if (args[0] == "gbplist")
if (args[0] == "gbplist") {
if (args.size() >= 2)
return printFullGBPList(args[1] == "update" ? true : false);
else if (args[0] == "hi")
else
return printFullGBPList();
} else if (args[0] == "hi") {
return genericResponse();
} else if (args[0] == "help") {
return helpMessage();
} else if (args[0] == "findpos" ) {
if (args.size() >= 2)
return findNum(std::stoi(args[1]));
else
return "Invalid command!";
} else {
return "Invalid command!";
}
}
#define FILE_NAME "temp-GBP"
@ -57,6 +74,13 @@ std::string printFullGBPList(bool update)
}
#undef FILE_NAME
std::string findNum(int pos)
{
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";
return out;
}
/**
* ##genericResponse
*
@ -66,3 +90,20 @@ std::string genericResponse()
{
return "Fuck you";
}
/**
* ##helpMessage
*
* Return the list of commands.
*/
std::string helpMessage()
{
std::string out;
out += "```\n";
out += "Available Commands: \n";
out += "gbplist (update):\n";
out += "----> Print out the current GBP leaderboard. Add update to fetch the latest page.\n";
out += "```\n";
return out;
}

View File

@ -13,8 +13,8 @@ void fetchLatestGBP()
FILE* fp;
Py_Initialize();
fp = _Py_fopen("gbp-leaderboard.py", "r");
PyRun_SimpleFile(fp, "gbp-leaderboard.py");
fp = _Py_fopen("../src/gbp-leaderboard.py", "r");
PyRun_SimpleFile(fp, "../src/gbp-leaderboard.py");
Py_Finalize();
}

View File

@ -78,7 +78,6 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
std::vector<std::string> messageArgs = separateArgs(msgContent);
dpp::message toSend;
if (messageArgs[0] == std::string(FILE_WARNING)) {
std::cout << "Handling file!\n";
toSend = dpp::message(msg.channel_id, "");
toSend.add_file("gbp-list.txt", dpp::utility::read_file(messageArgs[1]));
} else {