From 1ab3194bbf32719d2c5a9a87d24bc9f7e061f656 Mon Sep 17 00:00:00 2001 From: SuperNovaa41 Date: Thu, 3 Mar 2022 23:46:45 -0500 Subject: [PATCH] adds stuff to prevent my token from being leaked again --- .gitignore | 1 + config.json | 2 +- src/main.cpp | 26 +++++++++++++++----------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 584ef46..ce0a860 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ balances.txt gbp-bot +config.json diff --git a/config.json b/config.json index 077a650..943b44c 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { - "token": "token here", + "token": "OTQ5MTIxNDU2MTY2NTM5Mjk2.YiFwPA.uGYrCakjTDG2eaCRrg0560vWcrs", "bot_command": "!gbp" } diff --git a/src/main.cpp b/src/main.cpp index a35faf8..86f7400 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,16 +5,11 @@ #include #include #include +#include #include #include "gbp.h" - -//TODO: put these into a gitignored text file :)))))))) -const std::string BOT_TOKEN = "OTQ5MTIxNDU2MTY2NTM5Mjk2.YiFwPA.Hrj5LxqQuApFZfNuSUBVXe3kYEQ"; -const std::string BOT_COMMAND = "!gbp"; - - -const dpp::snowflake GUILD_ID = 865347537287249980; +using json = nlohmann::json; /** * ##hasCommand @@ -26,7 +21,10 @@ const dpp::snowflake GUILD_ID = 865347537287249980; */ bool hasCommand(dpp::message msg) { - return msg.content.substr(0, (msg.content.find(" "))) == BOT_COMMAND; + json config; + std::ifstream configFile("../config.json"); + configFile >> config; + return msg.content.substr(0, (msg.content.find(" "))) == config["bot_command"]; } /** @@ -51,10 +49,16 @@ void onMessage(dpp::cluster &bot, dpp::message msg) } int main() -{ - //Setup bot - dpp::cluster bot(BOT_TOKEN, dpp::i_default_intents | dpp::i_message_content); +{ + /* Setup the bot **/ + json config; + std::ifstream configFile("../config.json"); + configFile >> config; + std::string token = config["token"]; + dpp::cluster bot(token, dpp::i_default_intents | dpp::i_message_content); + + /* Start listening to commands */ bot.on_log(dpp::utility::cout_logger()); bot.on_message_create([&](const dpp::message_create_t &event) {