Findpos command
This commit is contained in:
parent
8e29c3dfa6
commit
c4f555bc6e
@ -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
|
||||
|
Binary file not shown.
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user