[Commands] Add #findlanguage Command (#3434)

# Notes
- Add `#findlanguage` command.
This commit is contained in:
Alex King 2023-06-24 20:26:29 -04:00 committed by GitHub
parent d558f9ece2
commit 9154c90418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 0 deletions

View File

@ -143,6 +143,7 @@ int command_init(void)
command_add("findclass", "[Search Criteria] - Search for a class", AccountStatus::Guide, command_findclass) ||
command_add("findcurrency", "[Search Criteria] - Search for an alternate currency", AccountStatus::Guide, command_findcurrency) ||
command_add("findfaction", "[Search Criteria] - Search for a faction", AccountStatus::Guide, command_findfaction) ||
command_add("findlanguage", "[Search Criteria] - Search for a language", AccountStatus::Guide, command_findlanguage) ||
command_add("findnpctype", "[Search Criteria] - Search database NPC types", AccountStatus::GMAdmin, command_findnpctype) ||
command_add("findrace", "[Search Criteria] - Search for a race", AccountStatus::Guide, command_findrace) ||
command_add("findrecipe", "[Search Criteria] - Search for a recipe", AccountStatus::Guide, command_findrecipe) ||
@ -985,6 +986,7 @@ void command_bot(Client *c, const Seperator *sep)
#include "gm_commands/findclass.cpp"
#include "gm_commands/findcurrency.cpp"
#include "gm_commands/findfaction.cpp"
#include "gm_commands/findlanguage.cpp"
#include "gm_commands/findnpctype.cpp"
#include "gm_commands/findrace.cpp"
#include "gm_commands/findrecipe.cpp"

View File

@ -93,6 +93,7 @@ void command_findcharacter(Client *c, const Seperator *sep);
void command_findclass(Client *c, const Seperator *sep);
void command_findcurrency(Client *c, const Seperator *sep);
void command_findfaction(Client *c, const Seperator *sep);
void command_findlanguage(Client *c, const Seperator *sep);
void command_findnpctype(Client *c, const Seperator *sep);
void command_findrace(Client *c, const Seperator *sep);
void command_findrecipe(Client *c, const Seperator *sep);

View File

@ -0,0 +1,77 @@
#include "../client.h"
#include "../../common/languages.h"
void command_findlanguage(Client *c, const Seperator *sep)
{
const auto arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Command Syntax: #findlanguage [Search Criteria]");
return;
}
if (sep->IsNumber(1)) {
const auto language_id = Strings::ToInt(sep->arg[1]);
if (EQ::ValueWithin(language_id, LANG_COMMON_TONGUE, LANG_UNKNOWN)) {
c->Message(
Chat::White,
fmt::format(
"Language {} | {}",
language_id,
EQ::constants::GetLanguageName(language_id)
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Language ID {} was not found.",
language_id
).c_str()
);
return;
}
const auto& search_criteria = Strings::ToLower(sep->argplus[1]);
if (!search_criteria.empty()) {
const auto& m = EQ::constants::GetLanguageMap();
auto found_count = 0;
for (const auto& l : m) {
const auto& language_name_lower = Strings::ToLower(l.second);
if (Strings::Contains(language_name_lower, search_criteria)) {
continue;
}
c->Message(
Chat::White,
fmt::format(
"Language {} | {}",
l.first,
l.second
).c_str()
);
found_count++;
}
auto language_message = (
found_count > 0 ?
(
found_count == 1 ?
"A Language was" :
fmt::format("{} Languages were", found_count)
) :
"No Languages were"
);
c->Message(
Chat::White,
fmt::format(
"{} found.",
language_message
).c_str()
);
}
}