From 2935a844a05c90997388d5d57478f8043f76aab4 Mon Sep 17 00:00:00 2001 From: HappyTanuki Date: Sun, 2 Feb 2025 06:37:31 +0900 Subject: [PATCH] =?UTF-8?q?=EC=95=84=EC=A7=81=20read=20loop=20ended?= =?UTF-8?q?=EB=8A=94=20=EB=AA=BB=EC=9E=A1=EC=95=98=EC=A7=80=EB=A7=8C=20?= =?UTF-8?q?=EC=95=84=EB=AC=B4=ED=8A=BC=20=EC=99=84=EC=84=B1(=EC=A7=84)=20?= =?UTF-8?q?=EC=9D=BC=EB=8B=A8=20=EC=85=94=ED=94=8C=20=EB=B9=BC=EA=B7=B8=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=EC=9D=80=20=EB=8B=A4=20=EC=9E=91=EB=8F=99?= =?UTF-8?q?=ED=95=98=EB=8B=88=20=EB=90=9C=20=EA=B2=8C=20=EC=95=84=EB=8B=90?= =?UTF-8?q?=EA=B9=8C=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 35 ++++++++++- docker-compose.yml | 7 +++ src/Audio/MusicPlayManager.cpp | 8 ++- src/BumbleBee.cpp | 2 +- src/Commands/Delete.cpp | 6 -- src/Commands/Leave.cpp | 6 +- src/Commands/Play.cpp | 107 ++++++++------------------------- src/Commands/Skip.cpp | 10 +-- 8 files changed, 85 insertions(+), 96 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 67fd379..bb8b9a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,34 @@ -FROM alpine +FROM debian:sid +WORKDIR / +RUN apt update +RUN apt install -y curl +RUN apt install -y libopus0 +RUN apt install -y tini +RUN apt install -y liboggz2 +RUN apt install -y xz-utils +RUN apt install -y python3 +RUN apt install -y python3-pip +RUN apt install -y ffmpeg +RUN apt install -y python3-certifi +RUN apt install -y python3-brotli +RUN apt install -y python3-websockets +RUN apt install -y python3-requests +RUN apt install -y python3-mutagen +RUN pip3 install --break-system-packages curl_cffi +RUN pip3 install --break-system-packages pycryptodome +RUN curl -Lo dpp.deb https://dl.dpp.dev/ +RUN dpkg -i dpp.deb +RUN rm dpp.deb +RUN curl -LO https://github.com/BtbN/FFmpeg-Builds/releases/latest/download/ffmpeg-master-latest-linux64-gpl.tar.xz +RUN tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz +RUN rm ffmpeg-master-latest-linux64-gpl.tar.xz +RUN mv ffmpeg-master-latest-linux64-gpl ffmpeg +RUN curl -LO https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp +RUN chmod +x ./yt-dlp +COPY ./build/BumbleCee /BumbleCee +COPY ./streamOpus.sh /streamOpus.sh +# RUN curl -LO https://github.com/HappyTanuki/BumbleCee/releases/latest/download/BumbleCee +# RUN curl -LO https://github.com/HappyTanuki/BumbleCee/releases/latest/download/streamOpus.sh +RUN chmod +x BumbleCee +RUN chmod +x streamOpus.sh +ENTRYPOINT ["/usr/bin/tini", "--", "./BumbleCee"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5adcd11 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + bumblebee: + build: . + container_name: BumbleBee + volumes: + - ./config.json:/config.json + restart: unless-stopped \ No newline at end of file diff --git a/src/Audio/MusicPlayManager.cpp b/src/Audio/MusicPlayManager.cpp index 6d02ac0..fb6e91f 100644 --- a/src/Audio/MusicPlayManager.cpp +++ b/src/Audio/MusicPlayManager.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace bumbleBee { @@ -85,7 +86,10 @@ MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId) } void MusicPlayManager::send_audio_to_voice(const MusicQueueElement& music, dpp::discord_voice_client* client) { - std::string command = "./streamOpus.sh ./yt-dlp ffmpeg https://youtu.be/"; + std::string command = "./streamOpus.sh "; + command += SettingsManager::getYTDLP_CMD() + " "; + command += SettingsManager::getFFMPEG_CMD() + " "; + command += "https://youtu.be/"; command += music.id; OGGZ* og = oggz_open_stdio(popen(command.c_str(), "r"), OGGZ_READ); @@ -115,7 +119,7 @@ void MusicPlayManager::send_audio_to_voice(const MusicQueueElement& music, dpp:: } } - client->creator->log(dpp::ll_info, "Sending " + music.id + " complete!"); + client->creator->log(dpp::ll_info, "Sending " + music.embed.title + " - " + music.id + " complete!"); oggz_close(og); diff --git a/src/BumbleBee.cpp b/src/BumbleBee.cpp index 6c17856..6d69db1 100644 --- a/src/BumbleBee.cpp +++ b/src/BumbleBee.cpp @@ -16,7 +16,7 @@ BumbleBee::BumbleBee() { cluster->on_log([](const dpp::log_t& event) { if (event.severity >= SettingsManager::getLOGLEVEL()) { - std::cout << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << "\n"; + std::cout << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl; } }); cluster->on_slashcommand([this](const dpp::slashcommand_t& event){on_slashcommand(event);}); diff --git a/src/Commands/Delete.cpp b/src/Commands/Delete.cpp index c6b511f..41f6734 100644 --- a/src/Commands/Delete.cpp +++ b/src/Commands/Delete.cpp @@ -3,12 +3,6 @@ namespace bumbleBee::commands { void Delete::execute(const dpp::slashcommand_t &event) { - if (std::holds_alternative(event.get_parameter("pos"))) // 여기 들어올 일 있나? - { - event.edit_original_response(dpp::message("위치를 제공하여 주십시오")); - event.reply(""); - return; - } int pos = std::get(event.get_parameter("pos")); if (pos < 0 || pos > musicManager->size(event.command.guild_id)) diff --git a/src/Commands/Leave.cpp b/src/Commands/Leave.cpp index 2b161dd..e08d225 100644 --- a/src/Commands/Leave.cpp +++ b/src/Commands/Leave.cpp @@ -1,14 +1,18 @@ #include namespace bumbleBee::commands { - void Leave::execute(const dpp::slashcommand_t &event) { // 왜 read loop ended가 뜨는가... + void Leave::execute(const dpp::slashcommand_t &event) { dpp::voiceconn* v = event.from->get_voice(event.command.guild_id); if (!v || !v->voiceclient || !v->voiceclient->is_ready()) { + event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!")); return; } musicManager->clear(event.command.guild_id); + v->voiceclient->stop_audio(); + v->voiceclient->pause_audio(true); + event.from->clear_queue(); event.from->disconnect_voice(event.command.guild_id); event.edit_original_response(dpp::message("음성 채팅방을 떠납니다!")); diff --git a/src/Commands/Play.cpp b/src/Commands/Play.cpp index bdaf7fc..a2cc890 100644 --- a/src/Commands/Play.cpp +++ b/src/Commands/Play.cpp @@ -23,7 +23,10 @@ namespace bumbleBee::commands { } std::string query = std::get(event.get_parameter("query")); - std::queue ids = ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() + " --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query); + std::queue ids = + ConsoleUtils::getResultFromCommand( + SettingsManager::getYTDLP_CMD() + + " --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query); std::queue> musics; @@ -36,60 +39,15 @@ namespace bumbleBee::commands { else msg.content = "큐에 다음 곡을 추가했습니다:"; - if (ids.size() >= 2) { - event.from->creator->log(dpp::ll_info, "Playlist detected."); - while (!ids.empty()) { - if (ids.front() == "") { - ids.pop(); - continue; - } - - 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); - - 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(ids.front(), query, event.command.usr, embed)); + while (!ids.empty()) { + if (ids.front() == "") { ids.pop(); + continue; } - } - 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"); - + 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; @@ -125,39 +83,26 @@ namespace bumbleBee::commands { ); musics.push(std::make_shared(ids.front(), query, event.command.usr, embed)); + ids.pop(); } - if (musics.size() == 1) { - event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id); + event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->embed.title + " - " + 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()->embed.title + " - " + 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()); - 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"); } } diff --git a/src/Commands/Skip.cpp b/src/Commands/Skip.cpp index 65bb8c6..9bfec7b 100644 --- a/src/Commands/Skip.cpp +++ b/src/Commands/Skip.cpp @@ -7,10 +7,12 @@ namespace bumbleBee::commands { if (!v || !v->voiceclient || !v->voiceclient->is_ready()) { return; } - v->voiceclient->pause_audio(true); - v->voiceclient->stop_audio(); - v->voiceclient->pause_audio(false); - v->voiceclient->insert_marker("end"); + // v->voiceclient->pause_audio(true); + // v->voiceclient->stop_audio(); + // v->voiceclient->pause_audio(false); + // v->voiceclient->insert_marker("end"); + v->voiceclient->skip_to_next_marker(); + v->voiceclient->insert_marker(); event.edit_original_response(dpp::message("스킵했습니다!")); }