Updated the command systems to automatically add new commands and remove orphaned entries from the command settings tables

This commit is contained in:
Uleat
2019-08-30 06:38:48 -04:00
parent f837d423ef
commit d341a1b38f
9 changed files with 240 additions and 15 deletions
+33
View File
@@ -18,6 +18,8 @@
#ifdef BOTS
#include <fmt/format.h>
#include "../common/global_define.h"
#include "../common/rulesys.h"
#include "../common/string_util.h"
@@ -52,6 +54,37 @@ bool BotDatabase::LoadBotCommandSettings(std::map<std::string, std::pair<uint8,
return true;
}
bool BotDatabase::UpdateBotCommandSettings(const std::vector<std::pair<std::string, uint8>> &injected, const std::vector<std::string> &orphaned)
{
bool return_value = true;
if (injected.size()) {
query = fmt::format(
"REPLACE INTO `bot_command_settings`(`bot_command`, `access`) VALUES {}",
implode(",", string_string("(", ")"), join_pair(string_string(), ",", string_string("'", "'"), injected))
);
if (!database.QueryDatabase(query).Success()) {
return_value = false;
}
}
if (orphaned.size()) {
query = fmt::format(
"DELETE FROM `bot_command_settings` WHERE `bot_command` IN ({})",
implode(",", string_string("'", "'"), orphaned)
);
if (!database.QueryDatabase(query).Success()) {
return_value = false;
}
}
return return_value;
}
bool BotDatabase::LoadBotSpellCastingChances()
{
query =