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"
}

View File

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

View File

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

View File

@ -1,3 +1,4 @@
#include <cstddef>
#include <dpp/appcommand.h>
#include <dpp/dispatcher.h>
#include <dpp/dpp.h>
@ -6,6 +7,7 @@
#include <dpp/once.h>
#include <dpp/queues.h>
#include <dpp/nlohmann/json.hpp>
#include <bits/stdc++.h>
#include <string>
#include "commands.cpp"
@ -40,13 +42,13 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
{
if (!hasCommand(msg))
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 msgContent = "guh";
std::string msgContent = "";
if (argument == "gbp")
msgContent = printFullGBPList();
@ -57,6 +59,7 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
int main()
{
/* Setup the bot **/
json config;
std::ifstream configFile("../config.json");