1 parent
df99b6ea7f
commit
d146f11f02
63 files changed
+8331
-2709
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../MusicManager.hpp"
|
||||
#include "Command.hpp"
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <format>
|
||||
@@ -8,7 +9,9 @@
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
class SearchCommand : public Command
|
||||
// Shared search rendering. Concrete commands pick the catalog scope:
|
||||
// !search (both), !youtube/!yb (YouTube), !ya/!yandex (Yandex).
|
||||
class SearchCommandBase : public Command
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -23,12 +26,11 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
if (ctx.args.empty()) {
|
||||
ctx.reply("Usage: search <query>\nExample: search "
|
||||
"never gonna give you up");
|
||||
ctx.reply(std::format("Usage: {} <query>", label()));
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = manager->search(ctx.args);
|
||||
auto result = manager->search(ctx.args, scope());
|
||||
if (!result) {
|
||||
Void::Log::error("SearchCommand", "{}",
|
||||
std::format("Search failed for '{}': {}", ctx.args,
|
||||
@@ -67,7 +69,7 @@ namespace Echoion::Core
|
||||
// duration: TeamSpeak parses [..] as a link reference).
|
||||
msg << std::format(
|
||||
"{}. {}", i + 1,
|
||||
markdownLink(displayText, track.shortenedUrl));
|
||||
markdownLink(displayText, trackLinkUrl(track)));
|
||||
if (track.duration.has_value()) {
|
||||
msg << " " << kDot << " "
|
||||
<< formatDuration(*track.duration);
|
||||
@@ -82,28 +84,23 @@ namespace Echoion::Core
|
||||
ctx.reply(msg.str());
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
Void::Log::error("SearchCommand", "{}",
|
||||
Void::Log::error("SearchCommand", "{}",
|
||||
std::format("Search command exception: {}", e.what()));
|
||||
ctx.reply("Something went wrong. Please try again.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Searches for tracks and shows results.";
|
||||
}
|
||||
|
||||
std::string_view getUsage() const override { return "<query>"; }
|
||||
|
||||
CommandCategory getCategory() const override
|
||||
{
|
||||
return CommandCategory::Music;
|
||||
return CommandCategory::Search;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"find", "s"};
|
||||
}
|
||||
protected:
|
||||
|
||||
// The catalog(s) this command searches, and the command name
|
||||
// used in usage text.
|
||||
[[nodiscard]] virtual MusicManager::SearchScope scope() const = 0;
|
||||
[[nodiscard]] virtual std::string_view label() const = 0;
|
||||
|
||||
private:
|
||||
|
||||
@@ -122,4 +119,28 @@ namespace Echoion::Core
|
||||
}
|
||||
};
|
||||
|
||||
// !search — both YouTube and Yandex Music.
|
||||
class SearchCommand : public SearchCommandBase
|
||||
{
|
||||
public:
|
||||
|
||||
std::string_view getDescription() const override
|
||||
{
|
||||
return "Search YouTube and Yandex Music for tracks.";
|
||||
}
|
||||
std::string_view getUsage() const override { return "<query>"; }
|
||||
std::vector<std::string_view> getAliases() const override
|
||||
{
|
||||
return {"find", "s"};
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
MusicManager::SearchScope scope() const override
|
||||
{
|
||||
return MusicManager::SearchScope::All;
|
||||
}
|
||||
std::string_view label() const override { return "search"; }
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user