Alex King f25e37d0c5
[Commands] Consolidate #set-like commands into a singular #set command (#3486)
* First push

* Final push.

* Consolidate zone commands in to one.

* Update command.cpp

* Remove debug messages.

* Test

* Add support for sub command status levels.

* Update command.cpp

* Update client.cpp

* Update database_update_manifest.cpp

* Update version.h

* Update item.cpp

* Update version.h

* Update database_update_manifest.cpp

* Fix command arguments.

* Help message.

* Update command.cpp

* Do DB injection/deletion

* Indent

* Update server_locked.cpp

* Update set.cpp

* Lock aliases

* Update command_subsettings_repository.h

* Update set.cpp

* Fix

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2023-07-15 00:37:51 -05:00

131 lines
2.2 KiB
C++

#include "../../client.h"
#include "../../command.h"
#include "../../common/repositories/tradeskill_recipe_repository.h"
void FindRecipe(Client *c, const Seperator *sep)
{
const auto can_view_recipes = c->Admin() >= GetCommandStatus("viewrecipe");
if (sep->IsNumber(2)) {
const auto recipe_id = static_cast<uint16>(Strings::ToUnsignedInt(sep->arg[2]));
const auto& l = TradeskillRecipeRepository::GetWhere(
database,
fmt::format("id = {}", recipe_id)
);
if (l.empty() || !l[0].id) {
c->Message(
Chat::White,
fmt::format(
"Recipe ID {} could not be found.",
Strings::Commify(recipe_id)
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"Recipe {} | {}{}",
Strings::Commify(recipe_id),
l[0].name,
(
can_view_recipes ?
fmt::format(
" | {}",
Saylink::Silent(
fmt::format(
"#viewrecipe {}",
l[0].id
),
"View"
)
) :
""
)
).c_str()
);
return;
}
const auto& search_criteria = Strings::ToLower(sep->argplus[2]);
auto found_count = 0;
const auto& l = TradeskillRecipeRepository::GetWhere(
database,
fmt::format(
"LOWER(`name`) LIKE '%%{}%%' ORDER BY `id` ASC",
search_criteria
)
);
if (l.empty() || !l[0].id) {
c->Message(
Chat::White,
fmt::format(
"No recipes were found matching '{}'.",
sep->argplus[2]
).c_str()
);
return;
}
for (const auto& e : l) {
c->Message(
Chat::White,
fmt::format(
"Recipe {} | {}{}",
Strings::Commify(e.id),
e.name,
(
can_view_recipes ?
fmt::format(
" | {}",
Saylink::Silent(
fmt::format(
"#viewrecipe {}",
e.id
),
"View"
)
) :
""
)
).c_str()
);
if (found_count == 50) {
break;
}
found_count++;
}
if (found_count == 50) {
c->Message(
Chat::White,
fmt::format(
"50 Recipes found matching '{}', max reached.",
sep->argplus[2]
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"{} Recipe{} found matching '{}'.",
found_count,
found_count != 1 ? "s" : "",
sep->argplus[2]
).c_str()
);
}