mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-28 02:25:13 +00:00
완성(준)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <Commands/BumbleBeeCommand.hpp>
|
||||
#include <Utils/ConsoleUtils.hpp>
|
||||
#include <Settings/SettingsManager.hpp>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace bumbleBee::commands {
|
||||
@@ -10,7 +12,7 @@ namespace bumbleBee::commands {
|
||||
event.edit_original_response(dpp::message("GUILD NOT FOUND!! WHAT IS THIS SORCERY??"));
|
||||
return;
|
||||
}
|
||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query"))) // 이거 필요한가???
|
||||
{
|
||||
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
|
||||
return;
|
||||
@@ -21,11 +23,18 @@ namespace bumbleBee::commands {
|
||||
}
|
||||
std::string query = std::get<std::string>(event.get_parameter("query"));
|
||||
|
||||
std::queue<std::string> ids = ConsoleUtils::getResultFromCommand("./yt-dlp --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
|
||||
std::queue<std::string> ids = ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() + " --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
|
||||
|
||||
std::queue<MusicQueueElement> musics;
|
||||
std::queue<std::shared_ptr<MusicQueueElement>> musics;
|
||||
|
||||
dpp::message origMsg;
|
||||
int initialQueuedCount = musicManager->size(event.command.guild_id);
|
||||
|
||||
dpp::message msg;
|
||||
|
||||
if (musicManager->size(event.command.guild_id) == 0)
|
||||
msg.content = "다음 곡을 재생합니다:";
|
||||
else
|
||||
msg.content = "큐에 다음 곡을 추가했습니다:";
|
||||
|
||||
if (ids.size() >= 2) {
|
||||
event.from->creator->log(dpp::ll_info, "Playlist detected.");
|
||||
@@ -34,34 +43,122 @@ namespace bumbleBee::commands {
|
||||
ids.pop();
|
||||
continue;
|
||||
}
|
||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + ids.front());
|
||||
|
||||
MusicQueueElement music(
|
||||
ids.front(),
|
||||
query,
|
||||
event.command.usr
|
||||
);
|
||||
FILE* file = popen((SettingsManager::getYTDLP_CMD() + " --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors -J http://youtu.be/" + ids.front()).c_str(), "r");
|
||||
|
||||
std::ostringstream oss;
|
||||
char buffer[1024];
|
||||
size_t bytesRead;
|
||||
|
||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
oss.write(buffer, bytesRead);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
musics.push(music);
|
||||
std::istringstream iss(oss.str());
|
||||
nlohmann::json videoDataJson;
|
||||
iss >> videoDataJson;
|
||||
|
||||
// std::string dump = videoDataJson.dump(4);
|
||||
|
||||
time_t SongLength = int(videoDataJson["duration"]);
|
||||
char SongLengthStr[10];
|
||||
tm t;
|
||||
t.tm_mday = SongLength / 86400;
|
||||
t.tm_hour = (SongLength % 86400)/3600;
|
||||
t.tm_min = (SongLength % 3600)/60;
|
||||
t.tm_sec = SongLength%60;
|
||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
||||
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_title(std::string(videoDataJson["title"]))
|
||||
.set_description(std::string(videoDataJson["uploader"]))
|
||||
.set_url(std::string(videoDataJson["webpage_url"]))
|
||||
.set_image(std::string(videoDataJson["thumbnail"]))
|
||||
.add_field(
|
||||
"길이",
|
||||
SongLengthStr,
|
||||
true
|
||||
);
|
||||
|
||||
musics.push(std::make_shared<MusicQueueElement>(ids.front(), query, event.command.usr, embed));
|
||||
ids.pop();
|
||||
}
|
||||
}
|
||||
|
||||
MusicQueueElement music(
|
||||
ids.front(),
|
||||
query,
|
||||
event.command.usr
|
||||
);
|
||||
musics.push(music);
|
||||
if (!ids.empty()) {
|
||||
FILE* file = popen((SettingsManager::getYTDLP_CMD() + " --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors -J http://youtu.be/" + ids.front()).c_str(), "r");
|
||||
|
||||
std::ostringstream oss;
|
||||
char buffer[1024];
|
||||
size_t bytesRead;
|
||||
|
||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||
oss.write(buffer, bytesRead);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
while (!musics.empty()) {
|
||||
auto element = musics.front();
|
||||
musicManager->queue_music(std::make_shared<MusicQueueElement>(element));
|
||||
musics.pop();
|
||||
std::istringstream iss(oss.str());
|
||||
nlohmann::json videoDataJson;
|
||||
iss >> videoDataJson;
|
||||
|
||||
time_t SongLength = int(videoDataJson["duration"]);
|
||||
char SongLengthStr[10];
|
||||
tm t;
|
||||
t.tm_mday = SongLength / 86400;
|
||||
t.tm_hour = (SongLength % 86400)/3600;
|
||||
t.tm_min = (SongLength % 3600)/60;
|
||||
t.tm_sec = SongLength%60;
|
||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
||||
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_title(std::string(videoDataJson["title"]))
|
||||
.set_description(std::string(videoDataJson["uploader"]))
|
||||
.set_url(std::string(videoDataJson["webpage_url"]))
|
||||
.set_image(std::string(videoDataJson["thumbnail"]))
|
||||
.add_field(
|
||||
"길이",
|
||||
SongLengthStr,
|
||||
true
|
||||
);
|
||||
|
||||
musics.push(std::make_shared<MusicQueueElement>(ids.front(), query, event.command.usr, embed));
|
||||
}
|
||||
|
||||
event.edit_original_response(dpp::message("play"));
|
||||
musicManager->queuedCondition.notify_one();
|
||||
if (musics.size() == 1) {
|
||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
|
||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
||||
msg.add_embed(musics.front()->embed);
|
||||
musics.pop();
|
||||
|
||||
event.edit_original_response(msg);
|
||||
musicManager->queuedCondition.notify_all();
|
||||
}
|
||||
else if (musics.size() > 1) {
|
||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
|
||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
||||
msg.add_embed(musics.front()->embed);
|
||||
musics.pop();
|
||||
|
||||
event.edit_original_response(msg);
|
||||
musicManager->queuedCondition.notify_all();
|
||||
|
||||
while (!musics.empty()) {
|
||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
|
||||
dpp::message followMsg(event.command.channel_id, "");
|
||||
|
||||
followMsg.add_embed(musics.front()->embed);
|
||||
event.from->creator->message_create(followMsg); // 어차피 원래 메시지를 지정해서 수정할 것이기 때문에 먼저 팔로잉 메시지를 작성해도 상관없음.
|
||||
|
||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
||||
musics.pop();
|
||||
}
|
||||
}
|
||||
else { // ??
|
||||
event.from->creator->log(dpp::ll_error, "??? not queueed any music");
|
||||
}
|
||||
}
|
||||
|
||||
void Play::init() {
|
||||
|
||||
Reference in New Issue
Block a user