general code improvements
This commit is contained in:
parent
cb8675459b
commit
1e4d772244
Binary file not shown.
@ -5,7 +5,6 @@
|
||||
#include <algorithm>
|
||||
|
||||
#define FILE_WARNING "/FILE/"
|
||||
#define EMBED_WARNING "/EMBED/"
|
||||
|
||||
typedef std::string (*vFunc)(void);
|
||||
typedef std::string (*vecFunc)(std::vector<std::string>);
|
||||
@ -32,7 +31,20 @@ std::string commandParse(std::vector<std::string> args)
|
||||
return "Invalid command!";
|
||||
}
|
||||
|
||||
#define FILE_NAME "temp-GBP"
|
||||
std::string sendFile(std::string filePath, std::string fileName = "")
|
||||
{
|
||||
if (fileName == "")
|
||||
fileName = filePath;
|
||||
/*
|
||||
* Files are sent with:
|
||||
* FILE_WARNING $PATH $FILENAME
|
||||
*
|
||||
* $FILENAME is the name of the file that will be sent to discord, if you don't want the file sent
|
||||
* to have the save name as the one on disk, or if you have a custom path for the file, set $FILENAME
|
||||
*/
|
||||
return std::string(FILE_WARNING) + " " + filePath + " " + fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* printFullGBPList
|
||||
*
|
||||
@ -53,10 +65,8 @@ std::string printFullGBPList()
|
||||
}
|
||||
file.close();
|
||||
|
||||
std::string out = std::string(FILE_WARNING) + " " + std::string(FILE_NAME);
|
||||
return out;
|
||||
return sendFile("temp-GBP", "gbp-list.txt");
|
||||
}
|
||||
#undef FILE_NAME
|
||||
|
||||
/**
|
||||
* ##fetchGBP
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -13,6 +13,8 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define BOT_COMMAND "!gbp"
|
||||
|
||||
/**
|
||||
* ##separateArgs
|
||||
*
|
||||
@ -29,10 +31,9 @@ std::vector<std::string> separateArgs(std::string args)
|
||||
if (args.find(" ") == -1) {
|
||||
out.push_back(args);
|
||||
break;
|
||||
} else {
|
||||
out.push_back(args.substr(0, args.find(" ")));
|
||||
args = args.substr(args.find(" ") + 1, args.length() - (args.find(" ") + 1));
|
||||
}
|
||||
out.push_back(args.substr(0, args.find(" ")));
|
||||
args = args.substr(args.find(" ") + 1, args.length() - (args.find(" ") + 1));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -47,10 +48,7 @@ std::vector<std::string> separateArgs(std::string args)
|
||||
*/
|
||||
bool hasCommand(dpp::message msg)
|
||||
{
|
||||
json config;
|
||||
std::ifstream configFile("../config.json");
|
||||
configFile >> config;
|
||||
return msg.content.substr(0, (msg.content.find(" "))) == config["bot_command"];
|
||||
return msg.content.substr(0, (msg.content.find(" "))) == std::string(BOT_COMMAND);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,10 +77,9 @@ void onMessage(dpp::cluster &bot, dpp::message msg)
|
||||
dpp::message toSend;
|
||||
if (messageArgs[0] == std::string(FILE_WARNING)) {
|
||||
toSend = dpp::message(msg.channel_id, "");
|
||||
toSend.add_file("gbp-list.txt", dpp::utility::read_file(messageArgs[1]));
|
||||
} else {
|
||||
toSend.add_file(messageArgs[2], dpp::utility::read_file(messageArgs[1]));
|
||||
} else
|
||||
toSend = dpp::message(msg.channel_id, msgContent);
|
||||
}
|
||||
|
||||
/* Send the message */
|
||||
bot.message_create(toSend);
|
||||
@ -95,7 +92,6 @@ int main()
|
||||
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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user