mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-26 22:02:26 +00:00
[Commands] Add #find bot Subcommand (#4563)
* [Commands] Add #find bot Subcommand * Update find.cpp * Update find.cpp
This commit is contained in:
parent
e258aaa068
commit
77793f364e
@ -1,6 +1,7 @@
|
|||||||
#include "../client.h"
|
#include "../client.h"
|
||||||
#include "find/aa.cpp"
|
#include "find/aa.cpp"
|
||||||
#include "find/body_type.cpp"
|
#include "find/body_type.cpp"
|
||||||
|
#include "find/bot.cpp"
|
||||||
#include "find/bug_category.cpp"
|
#include "find/bug_category.cpp"
|
||||||
#include "find/character.cpp"
|
#include "find/character.cpp"
|
||||||
#include "find/class.cpp"
|
#include "find/class.cpp"
|
||||||
@ -67,6 +68,16 @@ void command_find(Client *c, const Seperator *sep)
|
|||||||
Cmd{.cmd = "zone", .u = "zone [Search Criteria]", .fn = FindZone, .a = {"#fz", "#findzone"}},
|
Cmd{.cmd = "zone", .u = "zone [Search Criteria]", .fn = FindZone, .a = {"#fz", "#findzone"}},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (RuleB(Bots, Enabled)) {
|
||||||
|
commands.emplace_back(
|
||||||
|
Cmd{.cmd = "bot", .u = "bot [Search Criteria]", .fn = FindBot, .a = {"#findbot"}}
|
||||||
|
);
|
||||||
|
|
||||||
|
std::sort(commands.begin(), commands.end(), [](const Cmd& a, const Cmd& b) {
|
||||||
|
return a.cmd < b.cmd;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Check for arguments
|
// Check for arguments
|
||||||
const auto arguments = sep->argnum;
|
const auto arguments = sep->argnum;
|
||||||
if (!arguments) {
|
if (!arguments) {
|
||||||
|
|||||||
95
zone/gm_commands/find/bot.cpp
Normal file
95
zone/gm_commands/find/bot.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include "../../client.h"
|
||||||
|
#include "../../common/repositories/bot_data_repository.h"
|
||||||
|
|
||||||
|
void FindBot(Client *c, const Seperator *sep)
|
||||||
|
{
|
||||||
|
if (sep->IsNumber(2)) {
|
||||||
|
const auto bot_id = Strings::ToUnsignedInt(sep->arg[2]);
|
||||||
|
|
||||||
|
const auto& e = BotDataRepository::FindOne(content_db, bot_id);
|
||||||
|
if (!e.bot_id) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Bot ID {} does not exist or is invalid.",
|
||||||
|
bot_id
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Bot ID {} | {}",
|
||||||
|
bot_id,
|
||||||
|
e.name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto search_criteria = Strings::ToLower(sep->argplus[2]);
|
||||||
|
|
||||||
|
const auto& l = BotDataRepository::GetWhere(
|
||||||
|
content_db,
|
||||||
|
fmt::format(
|
||||||
|
"LOWER(`name`) LIKE '%%{}%%' AND `name` NOT LIKE '%-deleted-%' ORDER BY `bot_id` ASC LIMIT 50",
|
||||||
|
search_criteria
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (l.empty()) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"No bots found matching '{}'.",
|
||||||
|
sep->argplus[2]
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto found_count = 0;
|
||||||
|
|
||||||
|
for (const auto& e : l) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"Bot ID {} | {}",
|
||||||
|
Strings::Commify(e.bot_id),
|
||||||
|
e.name
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
found_count++;
|
||||||
|
|
||||||
|
if (found_count == 50) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found_count == 50) {
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"50 Bots found matching '{}', max reached.",
|
||||||
|
sep->argplus[2]
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
c->Message(
|
||||||
|
Chat::White,
|
||||||
|
fmt::format(
|
||||||
|
"{} Bot{} found matching '{}'.",
|
||||||
|
found_count,
|
||||||
|
found_count != 1 ? "s" : "",
|
||||||
|
sep->argplus[2]
|
||||||
|
).c_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ void FindCharacter(Client *c, const Seperator *sep)
|
|||||||
const auto& l = CharacterDataRepository::GetWhere(
|
const auto& l = CharacterDataRepository::GetWhere(
|
||||||
content_db,
|
content_db,
|
||||||
fmt::format(
|
fmt::format(
|
||||||
"LOWER(`name`) LIKE '%%{}%%' ORDER BY `id` ASC LIMIT 50",
|
"LOWER(`name`) LIKE '%%{}%%' AND `name` NOT LIKE '%-deleted-%' ORDER BY `id` ASC LIMIT 50",
|
||||||
search_criteria
|
search_criteria
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user