#pragma once #include #include #include #include // --- Play Command --- class Play : public Command { public: void execute(const CommandContext& ctx) override { if (ctx.musicManager.expired()) { LOG_ERROR("MusicManager is expired"); return; } std::string args(ctx.args); std::string invoker(ctx.invokerName); // 1. Handle Direct URL if (args.find("http") == 0) { if (ctx.musicManager.lock()->playUrl(args, invoker)) { ctx.reply("Added URL to queue."); } else { ctx.reply("Failed to add URL."); } return; } // 2. Handle Search auto results = ctx.musicManager.lock()->search(args, 5); if (results.empty()) { ctx.reply("No results found."); return; } if (results.size() == 1) { if (ctx.musicManager.lock()->playUrl(results[0].url, invoker)) { ctx.reply(std::format("Added: [{}]({})", results[0].name, results[0].shortUrl)); } else { ctx.reply("Failed to add result."); } } else { for (auto& result : results) { LOG_INFO("storing result: {}", result.url); } ctx.musicManager.lock()->storePendingSearch(ctx.clientID, results); std::string list = "Multiple results found. Use .select\\.sel :\n"; for (size_t i = 0; i < results.size(); ++i) { list += std::format("{}. [{}]({}) [{}]\n", (i + 1), results[i].name, results[i].shortUrl, results[i].length); } ctx.reply(list); } } std::string_view getDescription() const override { return "Plays a URL or searches YouTube."; } std::string_view getUsage() const override { return ""; } CommandCategory getCategory() const override { return CommandCategory::Music; } std::vector getAliases() const override { return {"p", "add"}; } };