New command "stickernames" lists uniq and sorted sticker names

This commit is contained in:
jcorporation
2023-10-21 18:08:14 +02:00
parent 97da29cc90
commit f4f79a3d5f
6 changed files with 69 additions and 0 deletions

View File

@@ -186,6 +186,7 @@ static constexpr struct command commands[] = {
{ "status", PERMISSION_READ, 0, 0, handle_status },
#ifdef ENABLE_SQLITE
{ "sticker", PERMISSION_ADMIN, 3, -1, handle_sticker },
{ "stickernames", PERMISSION_ADMIN, 0, 0, handle_sticker_names },
#endif
{ "stop", PERMISSION_PLAYER, 0, 0, handle_stop },
{ "subscribe", PERMISSION_READ, 1, 1, handle_subscribe },

View File

@@ -102,6 +102,24 @@ public:
return CommandResult::OK;
}
virtual CommandResult Names() {
auto data = CallbackContext{
.name = "",
.sticker_type = sticker_type,
.response = response,
.is_song = StringIsEqual("song", sticker_type)
};
auto callback = [](const char *found_value, void *user_data) {
auto context = reinterpret_cast<CallbackContext *>(user_data);
context->response.Fmt("name: {}\n", found_value);
};
sticker_database.Names(callback, &data);
return CommandResult::OK;
}
protected:
DomainHandler(Response &_response,
const Database &_database,
@@ -292,6 +310,24 @@ private:
} // namespace
CommandResult
handle_sticker_names(Client &client, Request args, Response &r)
{
(void) args;
auto &instance = client.GetInstance();
if (!instance.HasStickerDatabase()) {
r.Error(ACK_ERROR_UNKNOWN, "sticker database is disabled");
return CommandResult::ERROR;
}
auto &db = client.GetPartition().GetDatabaseOrThrow();
auto &sticker_database = *instance.sticker_database;
std::unique_ptr<DomainHandler> handler = std::make_unique<SongHandler>(r, db, sticker_database);
return handler->Names();
}
CommandResult
handle_sticker(Client &client, Request args, Response &r)
{

View File

@@ -12,5 +12,7 @@ class Response;
CommandResult
handle_sticker(Client &client, Request request, Response &response);
CommandResult
handle_sticker_names(Client &client, Request request, Response &response);
#endif