Skip to content

Commit

Permalink
remove discriminators
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Jun 16, 2024
1 parent 3b6c666 commit 661df7c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/trivia/cmd_nitro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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>";
}
Expand Down
2 changes: 1 addition & 1 deletion modules/trivia/cmd_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(_user[0]["discriminator"], std::dec), _("PROFILETITLE", settings)),
fmt::format("{0} {1}", _user[0]["username"], _("PROFILETITLE", settings)),
{
{ _("BADGES", settings), emojis, true },
{ _("ACHIEVEMENTS", settings), a, true },
Expand Down
4 changes: 2 additions & 2 deletions modules/trivia/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t, dpp::snowflake>::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<uint32_t>(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++;
}
Expand Down
9 changes: 8 additions & 1 deletion modules/trivia/trivia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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<uint32_t>(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"]));
}
Expand Down
1 change: 1 addition & 0 deletions modules/trivia/trivia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &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<std::string> &stringmentions, dpp::snowflake author_id = 0);
void GetHelp(const std::string& interaction_token, dpp::snowflake command_id, const std::string &section, 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);
Expand Down
24 changes: 12 additions & 12 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace db {
std::queue<background_query> bg_copy;
{
std::lock_guard<std::mutex> db_lock(b_db_mutex);
while (background_queries.size()) {
while (!background_queries.empty()) {
bg_copy.emplace(background_queries.front());
background_queries.pop();
}
Expand All @@ -154,16 +154,16 @@ namespace db {
std::lock_guard<std::mutex> 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;
}
}
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 661df7c

Please sign in to comment.