diff --git a/modules/trivia/cmd_nitro.cpp b/modules/trivia/cmd_nitro.cpp index b043076..692e5dc 100644 --- a/modules/trivia/cmd_nitro.cpp +++ b/modules/trivia/cmd_nitro.cpp @@ -44,7 +44,7 @@ void command_nitro_t::call(const in_cmd &cmd, std::stringstream &tokens, guild_s db::resultset q = db::query("SELECT global_scores.*, trivia_user_cache.*, emojis FROM global_scores INNER JOIN trivia_user_cache ON snowflake_id = name LEFT JOIN trivia_access ON name = trivia_access.user_id LEFT JOIN vw_emojis ON vw_emojis.user_id = snowflake_id WHERE (trivia_access.id is null OR trivia_access.enabled = 0) AND (SELECT COUNT(*) FROM bans WHERE nitro_ban = 1 AND bans.snowflake_id = trivia_user_cache.snowflake_id) = 0 AND (SELECT COUNT(*) FROM inventory WHERE shop_id = 37 AND user_id = trivia_user_cache.snowflake_id) = 0 ORDER BY monthscore DESC, trivia_user_cache.snowflake_id LIMIT 10", {}); for (auto & user : q) { - desc += "**#" + std::to_string(rank) + "** `" + user["username"] + "#" + fmt::format("{:04d}", from_string(user["discriminator"], std::dec)) + "` (*" + user["monthscore"] + "*) " + user["emojis"]; + desc += "**#" + std::to_string(rank) + "** `" + user["username"] + "` (*" + user["monthscore"] + "*) " + user["emojis"]; if (rank++ == 1) { desc += " <:crown:722808671888736306>"; } diff --git a/modules/trivia/cmd_profile.cpp b/modules/trivia/cmd_profile.cpp index 3d9cf17..a19f151 100644 --- a/modules/trivia/cmd_profile.cpp +++ b/modules/trivia/cmd_profile.cpp @@ -82,7 +82,7 @@ void command_profile_t::call(const in_cmd &cmd, std::stringstream &tokens, guild creator->EmbedWithFields( cmd.interaction_token, cmd.command_id, settings, - fmt::format("{0}#{1:04d} {2}", _user[0]["username"], from_string(_user[0]["discriminator"], std::dec), _("PROFILETITLE", settings)), + fmt::format("{0} {1}", _user[0]["username"], _("PROFILETITLE", settings)), { { _("BADGES", settings), emojis, true }, { _("ACHIEVEMENTS", settings), a, true }, diff --git a/modules/trivia/state.cpp b/modules/trivia/state.cpp index 5ac5a84..ccde9de 100644 --- a/modules/trivia/state.cpp +++ b/modules/trivia/state.cpp @@ -651,9 +651,9 @@ void state_t::do_insane_board(const guild_settings_t& settings) { ordered.insert(std::make_pair(s->second, s->first)); } for (std::multimap::reverse_iterator sc = ordered.rbegin(); sc != ordered.rend(); ++sc) { - db::resultset info = db::query("SELECT username, discriminator, get_emojis(trivia_user_cache.snowflake_id) as emojis FROM trivia_user_cache WHERE snowflake_id = ?", {sc->second}); + db::resultset info = db::query("SELECT username, get_emojis(trivia_user_cache.snowflake_id) as emojis FROM trivia_user_cache WHERE snowflake_id = ?", {sc->second}); if (info.size()) { - desc += fmt::format("**#{0}** `{1}#{2:04d}` (*{3}*) {4}\n", i, info[0]["username"], from_string(info[0]["discriminator"], std::dec), Comma(sc->first), info[0]["emojis"]); + desc += fmt::format("**#{0}** `{1}` (*{2}*) {3}\n", i, info[0]["username"], Comma(sc->first), info[0]["emojis"]); } i++; } diff --git a/modules/trivia/trivia.cpp b/modules/trivia/trivia.cpp index ef89d26..ab9ff1b 100644 --- a/modules/trivia/trivia.cpp +++ b/modules/trivia/trivia.cpp @@ -53,6 +53,7 @@ TriviaModule::TriviaModule(Bot* instigator, ModuleLoader* ml) : Module(instigato I_OnPresenceUpdate, I_OnChannelDelete, I_OnGuildDelete, + I_OnGuildUpdate, I_OnAllShardsReady, I_OnGuildCreate, I_OnEntitlementCreate, @@ -203,6 +204,12 @@ bool TriviaModule::OnGuildCreate(const dpp::guild_create_t &guild) return true; } +bool TriviaModule::OnGuildUpdate(const dpp::guild_update_t &guild) +{ + cache_guild(*guild.updated); + return true; +} + bool TriviaModule::OnAllShardsReady() { /* Called when the framework indicates all shards are connected */ @@ -484,7 +491,7 @@ void TriviaModule::show_stats(const std::string& interaction_token, dpp::snowfla std::string msg; for(auto& r : topten) { if (!r["username"].empty()) { - msg.append(fmt::format("{0}. `{1}#{2:04d}` ({3}) {4}\n", count++, r["username"], from_string(r["discriminator"], std::dec), r["dayscore"], r["emojis"])); + msg.append(fmt::format("{0}. `{1}` ({2}) {3}\n", count++, r["username"], r["dayscore"], r["emojis"])); } else { msg.append(fmt::format("{}. <@{}> ({})\n", count++, r["snowflake_id"], r["dayscore"])); } diff --git a/modules/trivia/trivia.h b/modules/trivia/trivia.h index b1e25d9..d4af488 100644 --- a/modules/trivia/trivia.h +++ b/modules/trivia/trivia.h @@ -192,6 +192,7 @@ class TriviaModule : public Module void CheckForQueuedStarts(); virtual bool OnMessage(const dpp::message_create_t &message, const std::string& clean_message, bool mentioned, const std::vector &stringmentions); virtual bool OnGuildCreate(const dpp::guild_create_t &guild); + virtual bool OnGuildUpdate(const dpp::guild_update_t &guild); bool RealOnMessage(const dpp::message_create_t &message, const std::string& clean_message, bool mentioned, const std::vector &stringmentions, dpp::snowflake author_id = 0); void GetHelp(const std::string& interaction_token, dpp::snowflake command_id, const std::string §ion, dpp::snowflake channelID, const std::string &botusername, dpp::snowflake botid, const std::string &author, dpp::snowflake authorid, const guild_settings_t &settings); void CacheUser(dpp::snowflake user, dpp::user _user, dpp::guild_member gm, dpp::snowflake channel_id); diff --git a/src/database.cpp b/src/database.cpp index 6ea856a..ef00c73 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -128,7 +128,7 @@ namespace db { std::queue bg_copy; { std::lock_guard db_lock(b_db_mutex); - while (background_queries.size()) { + while (!background_queries.empty()) { bg_copy.emplace(background_queries.front()); background_queries.pop(); } @@ -154,16 +154,16 @@ namespace db { std::lock_guard db_lock2(b_db_mutex); log = logger; bool failed = false; - for (size_t i = 0; i < POOL_SIZE; ++i) { - if (mysql_init(&connections[i].connection) != nullptr) { - mysql_options(&connections[i].connection, MYSQL_SET_CHARSET_NAME, "utf8mb4"); - mysql_options(&connections[i].connection, MYSQL_INIT_COMMAND, CONNECT_STRING); + for (auto & connection : connections) { + if (mysql_init(&connection.connection) != nullptr) { + mysql_options(&connection.connection, MYSQL_SET_CHARSET_NAME, "utf8mb4"); + mysql_options(&connection.connection, MYSQL_INIT_COMMAND, CONNECT_STRING); char reconnect = 1; - if (mysql_options(&connections[i].connection, MYSQL_OPT_RECONNECT, &reconnect) == 0) { - if (!mysql_real_connect(&connections[i].connection, host.c_str(), user.c_str(), pass.c_str(), db.c_str(), port, NULL, CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS)) { + if (mysql_options(&connection.connection, MYSQL_OPT_RECONNECT, &reconnect) == 0) { + if (!mysql_real_connect(&connection.connection, host.c_str(), user.c_str(), pass.c_str(), db.c_str(), port, NULL, CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS)) { failed = true; - std::cout << mysql_error(&connections[i].connection) << "\n"; - logger->log(dpp::ll_error, "Database connection failed " + std::string(mysql_error(&connections[i].connection))); + std::cout << mysql_error(&connection.connection) << "\n"; + logger->log(dpp::ll_error, "Database connection failed " + std::string(mysql_error(&connection.connection))); break; } } @@ -269,14 +269,14 @@ namespace db { * TODO: Really, I should use a cached query and the built in parameterisation for this. * It would scale a lot better. */ - for (auto v = format.begin(); v != format.end(); ++v) { - if (*v == '?' && escaped_parameters.size() >= param + 1) { + for (char v : format) { + if (v == '?' && escaped_parameters.size() >= param + 1) { querystring.append(escaped_parameters[param]); if (param != escaped_parameters.size() - 1) { param++; } } else { - querystring += *v; + querystring += v; } }