makes fetching GBP actually work

This commit is contained in:
SuperNovaa41 2022-03-04 09:09:11 -05:00
parent 6e7c8765b5
commit ddec57e4b3
6 changed files with 1715 additions and 17 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
{ {
"token": "token here", "token": "OTQ5MTIxNDU2MTY2NTM5Mjk2.YiFwPA.WEl7l-Q0aH3aQNE7mZc2jN8Z0TU",
"bot_command": "!gbp" "bot_command": "!gbp"
} }

View File

@ -1,18 +1,19 @@
#include "gbp.cpp" #include "gbp.cpp"
#include <string>
std::string printFullGBPList(bool update = false) std::string printFullGBPList(bool update = false)
{ {
std::map<int, std::string> gbp; std::map<int, std::pair<int, std::string>> gbp;
if (update) if (update)
gbp = fetchAndReadGBP(); gbp = fetchAndReadGBP();
else else
gbp = readGBPIntoList(); gbp = readGBPIntoList();
std::string msg; std::string msg = "";
int i = 1; for (std::map<int, std::pair<int, std::string>>::iterator it = gbp.begin(); it != gbp.end(); it++) {
for (std::map<int, std::string>::iterator it = gbp.end(); it != gbp.begin(); it--) { msg += std::to_string(it->first) + ": " + it->second.second + "(" + std::to_string(it->second.first) + " GBP)\n";
msg += "#[i] [it->second], GBP: [it->first]\n";
i++;
} }
return msg; return msg;
} }

View File

@ -13,23 +13,25 @@ void fetchLatestGBP()
Py_Finalize(); Py_Finalize();
} }
std::map<int, std::string>readGBPIntoList() std::map<int, std::pair<int, std::string>>readGBPIntoList()
{ {
std::map<int, std::string> GBP; std::map<int, std::pair<int, std::string>> GBP;
std::ifstream file; std::ifstream file;
file.open("balances.txt"); file.open("../src/balances.txt");
std::string line; std::string line;
int i = 1;
while(getline(file, line)) { while(getline(file, line)) {
std::string username = line.substr(line.find(" "), line.rfind(" ") - line.find(" ")); std::string username = line.substr(line.find(" "), line.rfind(" ") - line.find(" "));
int tGBP = std::stoi(line.substr(line.rfind(" "), line.length() - line.rfind(" "))); int tGBP = std::stoi(line.substr(line.rfind(" "), line.length() - line.rfind(" ")));
GBP.insert({tGBP, username}); GBP.insert({i, {tGBP, username}});
i++;
} }
return GBP; return GBP;
} }
std::map<int, std::string>fetchAndReadGBP() std::map<int, std::pair<int, std::string>>fetchAndReadGBP()
{ {
fetchLatestGBP(); fetchLatestGBP();
return readGBPIntoList(); return readGBPIntoList();

View File

@ -1,3 +1,4 @@
#include <cstddef>
#include <dpp/appcommand.h> #include <dpp/appcommand.h>
#include <dpp/dispatcher.h> #include <dpp/dispatcher.h>
#include <dpp/dpp.h> #include <dpp/dpp.h>
@ -6,8 +7,9 @@
#include <dpp/once.h> #include <dpp/once.h>
#include <dpp/queues.h> #include <dpp/queues.h>
#include <dpp/nlohmann/json.hpp> #include <dpp/nlohmann/json.hpp>
#include <bits/stdc++.h>
#include <string> #include <string>
#include "commands.cpp" #include "commands.cpp"
using json = nlohmann::json; using json = nlohmann::json;
@ -40,13 +42,13 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
{ {
if (!hasCommand(msg)) if (!hasCommand(msg))
return; return;
std::cout << "Command received!\n";
readGBPIntoList();
int argIdx = msg.content.find(" "); int argIdx = msg.content.find(" ") + 1;
std::string argument = msg.content.substr(argIdx, msg.content.length() - argIdx); std::string argument = msg.content.substr(argIdx, msg.content.length() - argIdx);
std::string msgContent = "guh"; std::string msgContent = "";
if (argument == "gbp") if (argument == "gbp")
msgContent = printFullGBPList(); msgContent = printFullGBPList();
@ -57,6 +59,7 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
int main() int main()
{ {
/* Setup the bot **/ /* Setup the bot **/
json config; json config;
std::ifstream configFile("../config.json"); std::ifstream configFile("../config.json");