[Commands] Add #findcharacter Command. (#2692)

# Commands
- Add `#findcharacter [Search Criteria]`.

# Notes
- Allows operators to search for characters by ID or a portion of their name to easily get ID/Name.
This commit is contained in:
Alex King 2023-01-03 14:32:21 -05:00 committed by GitHub
parent af4ee9f8d8
commit a80a6de59f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 0 deletions

View File

@ -147,6 +147,7 @@ int command_init(void)
command_add("size", "Change your targets size (alias of #feature size)", AccountStatus::QuestTroupe, command_feature) ||
command_add("findaa", "[Search Criteria] - Search for an AA", AccountStatus::Guide, command_findaa) ||
command_add("findaliases", "[Search Criteria]- Searches for available command aliases, by alias or command", AccountStatus::Player, command_findaliases) ||
command_add("findcharacter", "[Search Criteria] - Search for a character", AccountStatus::Guide, command_findcharacter) ||
command_add("findclass", "[Search Criteria] - Search for a class", AccountStatus::Guide, command_findclass) ||
command_add("findfaction", "[Search Criteria] - Search for a faction", AccountStatus::Guide, command_findfaction) ||
command_add("findnpctype", "[Search Criteria] - Search database NPC types", AccountStatus::GMAdmin, command_findnpctype) ||
@ -983,6 +984,7 @@ void command_bot(Client *c, const Seperator *sep)
#include "gm_commands/faction.cpp"
#include "gm_commands/feature.cpp"
#include "gm_commands/findaa.cpp"
#include "gm_commands/findcharacter.cpp"
#include "gm_commands/findclass.cpp"
#include "gm_commands/findfaction.cpp"
#include "gm_commands/findnpctype.cpp"

View File

@ -88,6 +88,7 @@ void command_faction_association(Client *c, const Seperator *sep);
void command_feature(Client *c, const Seperator *sep);
void command_findaa(Client *c, const Seperator *sep);
void command_findaliases(Client *c, const Seperator *sep);
void command_findcharacter(Client *c, const Seperator *sep);
void command_findclass(Client *c, const Seperator *sep);
void command_findfaction(Client *c, const Seperator *sep);
void command_findnpctype(Client *c, const Seperator *sep);

View File

@ -0,0 +1,93 @@
#include "../client.h"
#include "../../common/repositories/character_data_repository.h"
void command_findcharacter(Client *c, const Seperator *sep)
{
const auto arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Usage: #findcharacter [Search Criteria]");
return;
}
if (sep->IsNumber(1)) {
const auto character_id = std::stoul(sep->arg[1]);
const auto& e = CharacterDataRepository::FindOne(content_db, character_id);
if (!e.id) {
c->Message(
Chat::White,
fmt::format(
"Character ID {} does not exist or is invalid.",
character_id
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Character ID {} | {}",
character_id,
e.name
).c_str()
);
} else {
const auto search_criteria = Strings::ToLower(sep->argplus[1]);
const auto& l = CharacterDataRepository::GetWhere(
content_db,
fmt::format(
"LOWER(`name`) LIKE '%%{}%%'",
search_criteria
).c_str()
);
if (l.empty()) {
c->Message(
Chat::White,
fmt::format(
"No characters found matching '{}'.",
sep->argplus[1]
).c_str()
);
}
auto found_count = 0;
for (const auto& e : l) {
c->Message(
Chat::White,
fmt::format(
"Character ID {} | {}",
e.id,
e.name
).c_str()
);
found_count++;
if (found_count == 50) {
break;
}
}
if (found_count == 50) {
c->Message(
Chat::White,
fmt::format(
"50 Characters found matching '{}', max reached.",
sep->argplus[1]
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"{} Character{} found matching '{}'.",
found_count,
found_count != 1 ? "s" : "",
sep->argplus[1]
).c_str()
);
}
}
}