makes fetching GBP actually work
This commit is contained in:
parent
6e7c8765b5
commit
ddec57e4b3
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
{
|
||||
"token": "token here",
|
||||
"token": "OTQ5MTIxNDU2MTY2NTM5Mjk2.YiFwPA.WEl7l-Q0aH3aQNE7mZc2jN8Z0TU",
|
||||
"bot_command": "!gbp"
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
14
src/gbp.cpp
14
src/gbp.cpp
@ -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();
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -1,3 +1,4 @@
|
||||
#include <cstddef>
|
||||
#include <dpp/appcommand.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/dpp.h>
|
||||
@ -6,8 +7,9 @@
|
||||
#include <dpp/once.h>
|
||||
#include <dpp/queues.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <bits/stdc++.h>
|
||||
#include <string>
|
||||
#include "commands.cpp"
|
||||
#include "commands.cpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user