Skip to content

Commit

Permalink
missing commits
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Jul 24, 2023
1 parent 844afee commit 6554961
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@
"future": "cpp",
"ranges": "cpp",
"stop_token": "cpp"
}
},
"cSpell.words": [
"premguild",
"resultset"
]
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include(buildtools/cmake/FindPCRE.cmake)
include_directories( "include" )

target_link_libraries(bot dl mysqlclient pcre dpp fmt spdlog)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -g -O2 -fPIC -rdynamic")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -g -O2 -fPIC -rdynamic -Wno-deprecated-declarations")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2")

target_link_libraries(bot)
Expand Down
8 changes: 6 additions & 2 deletions modules/trivia/cmd_reassignpremium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ void command_reassignpremium_t::call(const in_cmd &cmd, std::stringstream &token
db::resultset access = db::query("SELECT * FROM trivia_access WHERE user_id = '?' AND enabled = 1", {cmd.author_id});

if (access.size() && guild_id && user_id) {
db::resultset user = db::query("SELECT * FROM premium_credits WHERE user_id = ?", {user_id});
db::resultset user = db::query("SELECT * FROM premium_credits WHERE user_id = ? ORDER BY active DESC, since DESC", {user_id});
if (user.size()) {
std::string notice;
if (user.size() > 1) {
notice = "\n\n**WARNING**: __Multiple subscriptions for this user__. The most recent active subscription was updated.";
}
if (user[0]["active"] == "0") {
creator->SimpleEmbed(cmd.interaction_token, cmd.command_id, settings, ":warning:", "Premium subscription is not active!", cmd.channel_id);
return;
Expand All @@ -64,7 +68,7 @@ void command_reassignpremium_t::call(const in_cmd &cmd, std::stringstream &token
cmd.interaction_token,
cmd.command_id, settings,
":white_check_mark:",
fmt::format("Premium subscription {} reassigned to guild {}\n**Old** guild name: {}\n**New** guild name: {}", user[0]["subscription_id"], guild_id, oldname, newname),
fmt::format("Premium subscription {} reassigned to guild {}\n**Old** guild name: {}\n**New** guild name: {}{}", user[0]["subscription_id"], guild_id, oldname, newname, notice),
cmd.channel_id
);
} else {
Expand Down
6 changes: 5 additions & 1 deletion modules/trivia/cmd_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void command_subscription_t::call(const in_cmd &cmd, std::stringstream &tokens,
db::resultset access = db::query("SELECT * FROM trivia_access WHERE user_id = '?' AND enabled = 1", {cmd.author_id});

if (access.size() && user_id) {
db::resultset user = db::query("SELECT *, coalesce(date_format(since, '%d-%b-%Y %H:%i'), '<not set>') as hr_since, coalesce(date_format(cancel_date, '%d-%b-%Y %H:%i'), '<not set>') as hr_cancel_date, coalesce(date_format(payment_failed_date, '%d-%b-%Y %H:%i'), '<not set>') as hr_payment_failed_date, coalesce(date_format(manual_expiry_date, '%d-%b-%Y'), '<not set>') as hr_manual_expiry_date FROM premium_credits WHERE user_id = ?", {user_id});
db::resultset user = db::query("SELECT *, coalesce(date_format(since, '%d-%b-%Y %H:%i'), '<not set>') as hr_since, coalesce(date_format(cancel_date, '%d-%b-%Y %H:%i'), '<not set>') as hr_cancel_date, coalesce(date_format(payment_failed_date, '%d-%b-%Y %H:%i'), '<not set>') as hr_payment_failed_date, coalesce(date_format(manual_expiry_date, '%d-%b-%Y'), '<not set>') as hr_manual_expiry_date FROM premium_credits WHERE user_id = ? ORDER BY since DESC", {user_id});
db::resultset active_count = db::query("SELECT user_id FROM premium_credits WHERE user_id = ? AND active = 1", {user_id});
if (user.size()) {
db::resultset premguild = db::query("SELECT * FROM trivia_guild_cache WHERE snowflake_id = ?", {user[0]["guild_id"]});
std::vector<field_t> fields = {
Expand All @@ -62,6 +63,9 @@ void command_subscription_t::call(const in_cmd &cmd, std::stringstream &tokens,
{ "Last Payment Failed Date", user[0]["hr_payment_failed_date"] + BLANK_EMOJI, true },
{ "Manual Expiry Date", user[0]["hr_manual_expiry_date"] + BLANK_EMOJI, true },
};
if (active_count.size() > 1) {
fields.push_back({ "WARNING", fmt::format("__{} active subscriptions for this user__. The most recent subscription is shown.{}", active_count.size(), BLANK_EMOJI), false });
}
creator->EmbedWithFields(cmd.interaction_token, cmd.command_id, settings, "Premium Subscription Details", fields, cmd.channel_id, "", "", "https://triviabot.co.uk/images/crown.png", "Subscription Information");
} else {
creator->SimpleEmbed(cmd.interaction_token, cmd.command_id, settings, ":warning:", "This user does not have TriviaBot Premium!", cmd.channel_id);
Expand Down
4 changes: 2 additions & 2 deletions modules/trivia/numerics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int TriviaModule::random(int min, int max)
return min + rand() % (( max + 1 ) - min);
}

std::string TriviaModule::dec_to_roman(unsigned int decimal, const guild_settings_t &settings)
std::string TriviaModule::dec_to_roman(uint64_t decimal, const guild_settings_t &settings)
{
std::vector<int> numbers = { 1, 4 ,5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
std::vector<std::string> romans = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M" };
Expand Down Expand Up @@ -233,4 +233,4 @@ std::string TriviaModule::MakeFirstHint(const std::string &s, const guild_settin
} else {
return Q;
}
}
}
10 changes: 5 additions & 5 deletions modules/trivia/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ void state_t::do_normal_round(bool silent, const guild_settings_t& settings)
question.customhint2 = currency + question.customhint2;
uint32_t r = creator->random(1, 13);
if ((r < 3 && from_string<uint32_t>(question.customhint2, std::dec) <= 10000)) {
question.customhint2 = creator->dec_to_roman(from_string<unsigned int>(question.customhint2, std::dec), settings);
} else if ((r >= 3 && r < 6) || from_string<uint32_t>(question.customhint2, std::dec) > 10000) {
question.customhint2 = fmt::format(_("HEX", settings), from_string<uint32_t>(question.customhint2, std::dec));
question.customhint2 = creator->dec_to_roman(from_string<uint64_t>(question.customhint2, std::dec), settings);
} else if ((r >= 3 && r < 6) || from_string<uint64_t>(question.customhint2, std::dec) > 10000) {
question.customhint2 = fmt::format(_("HEX", settings), from_string<uint64_t>(question.customhint2, std::dec));
} else if (r >= 6 && r <= 10) {
question.customhint2 = fmt::format(_("OCT", settings), from_string<uint32_t>(question.customhint2, std::dec));
question.customhint2 = fmt::format(_("OCT", settings), from_string<uint64_t>(question.customhint2, std::dec));
} else {
question.customhint2 = fmt::format(_("BIN", settings), from_string<uint32_t>(question.customhint2, std::dec));
question.customhint2 = fmt::format(_("BIN", settings), from_string<uint64_t>(question.customhint2, std::dec));
}
} else {
uint32_t r = creator->random(1, 12);
Expand Down
2 changes: 1 addition & 1 deletion modules/trivia/trivia.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class TriviaModule : public Module
virtual std::string GetVersion();
virtual std::string GetDescription();
int random(int min, int max);
std::string dec_to_roman(unsigned int decimal, const guild_settings_t &settings);
std::string dec_to_roman(uint64_t decimal, const guild_settings_t &settings);
std::string tidy_num(std::string num);
void UpdatePresenceLine();
std::string conv_num(std::string datain, const guild_settings_t &settings);
Expand Down
16 changes: 4 additions & 12 deletions modules/trivia/webrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,9 @@ void leave_team(uint64_t snowflake_id)
/* Make a player join a team */
bool join_team(uint64_t snowflake_id, const std::string &team, uint64_t channel_id)
{
if (check_team_exists(team)) {
auto teaminfo = db::query("SELECT * FROM teams WHERE name = '?'", {team});
if (teaminfo.size() && teaminfo[0]["qualifying_score"].length() && from_string<uint64_t>(teaminfo[0]["qualifying_score"], std::dec) > 0) {
auto teaminfo = db::query("SELECT * FROM teams WHERE name = '?'", {team});
if (teaminfo.size()) {
if (teaminfo[0]["qualifying_score"].length() && from_string<uint64_t>(teaminfo[0]["qualifying_score"], std::dec) > 0) {
auto rs_score = db::query("SELECT * FROM vw_scorechart WHERE name = '?'", {team});
uint64_t score = (rs_score.size() ? from_string<uint64_t>(rs_score[0]["score"], std::dec) : 0);
if (score < from_string<uint64_t>(teaminfo[0]["qualifying_score"], std::dec)) {
Expand All @@ -743,7 +743,7 @@ bool join_team(uint64_t snowflake_id, const std::string &team, uint64_t channel_
}
}
db::query("DELETE FROM team_membership WHERE nick='?'", {snowflake_id});
db::query("INSERT INTO team_membership (nick, team, joined, points_contributed) VALUES('?','?',now(),0)", {snowflake_id, team});
db::query("INSERT INTO team_membership (nick, team, joined, points_contributed) VALUES('?','?',unix_timestamp(),0)", {snowflake_id, team});
db::query("UPDATE teams SET owner_id = '?' WHERE name = '?' AND owner_id IS NULL", {snowflake_id, team});
return true;
} else {
Expand Down Expand Up @@ -804,14 +804,6 @@ streak_t get_streak(uint64_t snowflake_id)
return s;
}

/* Returns true if a team name exists */
bool check_team_exists(const std::string &team)
{
// Replaced with direct db query for perforamance increase - 27Dec20
db::resultset r = db::query("SELECT name FROM teams WHERE name = '?'", {team});
return (r.size());
}

/* Add points to a team */
void add_team_points(const std::string &team, int points, uint64_t snowflake_id)
{
Expand Down
3 changes: 1 addition & 2 deletions modules/trivia/webrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define BACKEND_PATH_LIVE "/api/{0}"

/* Development API endpoint URL */
#define BACKEND_HOST_DEV "beta.brainbox.cc"
#define BACKEND_HOST_DEV "https://beta.brainbox.cc"
#define BACKEND_PATH_DEV "/api/{0}"

using json = nlohmann::json;
Expand Down Expand Up @@ -79,7 +79,6 @@ std::string get_current_team(uint64_t snowflake_id);
void leave_team(uint64_t snowflake_id);
streak_t get_streak(uint64_t snowflake_id, uint64_t guild_id);
streak_t get_streak(uint64_t snowflake_id);
bool check_team_exists(const std::string &team);
void add_team_points(const std::string &team, int points, uint64_t snowflake_id);
uint32_t get_team_points(const std::string &team);
void cache_user(const class dpp::user *_user, const class dpp::guild *_guild, const class dpp::guild_member* gi);
Expand Down
3 changes: 1 addition & 2 deletions src/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ bool ModuleLoader::Load(const std::string &filename)
if (Modules.find(filename) == Modules.end()) {

char buffer[PATH_MAX + 1];
getcwd(buffer, PATH_MAX);
std::string full_module_spec = std::string(buffer) + "/" + filename;
std::string full_module_spec = std::string(getcwd(buffer, PATH_MAX)) + "/" + filename;

m.dlopen_handle = dlopen(full_module_spec.c_str(), RTLD_NOW | RTLD_LOCAL);
if (!m.dlopen_handle) {
Expand Down

0 comments on commit 6554961

Please sign in to comment.