Added the sendSuccess, sendError, getResultSet & executeQuery functions to the util.cpp
This commit is contained in:
parent
d6041b94f0
commit
6f9eeaf4c6
@ -13,6 +13,7 @@ uint32_t util::getHexColor(EmbedType type) {
|
||||
case INFO:
|
||||
return 0x748AD6;
|
||||
}
|
||||
return 0x000000;
|
||||
}
|
||||
|
||||
embed util::getDefaultEmbed(EmbedType type) {
|
||||
@ -23,16 +24,57 @@ embed util::getDefaultEmbed(EmbedType type) {
|
||||
return e;
|
||||
}
|
||||
|
||||
void util::sendSuccess(const dpp::slashcommand_t &event, const std::string &message) {
|
||||
embed e = getDefaultEmbed(SUCCESS);
|
||||
e.set_title("Success");
|
||||
e.set_description("> " + std::regex_replace(message, std::regex("\n"), "\n> "));
|
||||
|
||||
event.reply(dpp::message().add_embed(e).set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
||||
void util::sendError(const dpp::slashcommand_t &event, const std::string &message) {
|
||||
embed e = getDefaultEmbed(ERROR);
|
||||
e.set_title("<:max:1170311480160292894> An error occurred");
|
||||
e.set_description("> " + std::regex_replace(message, std::regex("\n"), "\n> "));
|
||||
|
||||
event.reply(dpp::message().add_embed(e).set_flags(dpp::m_ephemeral));
|
||||
}
|
||||
|
||||
sql::Connection *util::createConnection(const json &config) {
|
||||
sql::Driver *driver = sql::mariadb::get_driver_instance();
|
||||
|
||||
sql::SQLString url = "jdbc:" + config["string"].get<std::string>();
|
||||
|
||||
sql::Properties properties({{"user", config["username"].get<std::string>()},
|
||||
{"password", config["password"].get<std::string>()},
|
||||
{"autoReconnect", "true"},
|
||||
{"maxReconnects", "500"}});
|
||||
sql::Properties properties({{"user", config["username"].get<std::string>()},
|
||||
{"password", config["password"].get<std::string>()},
|
||||
{"autoReconnect", "true"},
|
||||
{"maxReconnects", "500"}});
|
||||
|
||||
sql::Connection *con = driver->connect(url, properties);
|
||||
return con;
|
||||
}
|
||||
|
||||
sql::ResultSet *util::getResultSet(sql::Connection &con, const std::string &query,
|
||||
std::initializer_list<std::string> params) {
|
||||
sql::PreparedStatement *stmt = con.prepareStatement(query);
|
||||
|
||||
int i = 1;
|
||||
for (auto ¶m: params) {
|
||||
stmt->setString(i, param);
|
||||
i++;
|
||||
}
|
||||
|
||||
return stmt->executeQuery();
|
||||
}
|
||||
|
||||
void util::executeQuery(sql::Connection &con, const std::string &query, std::initializer_list<std::string> params) {
|
||||
sql::PreparedStatement *stmt = con.prepareStatement(query);
|
||||
|
||||
int i = 1;
|
||||
for (auto ¶m: params) {
|
||||
stmt->setString(i, param);
|
||||
i++;
|
||||
}
|
||||
|
||||
stmt->execute();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user