From 52146c1f6a65f653c54dcf54a8b15ed12870e8a1 Mon Sep 17 00:00:00 2001 From: HappyTanuki Date: Thu, 13 Feb 2025 16:43:11 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EA=B0=80=EB=8F=85?= =?UTF-8?q?=EC=84=B1=20=EB=A6=AC=ED=8C=A9=ED=84=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BuildDockerAndUpload.sh | 3 - Dockerfile | 32 +++++----- include/BumbleBee.hpp | 1 + include/Commands/BumbleBeeCommand.hpp | 7 ++- include/Queue/MusicQueue.hpp | 37 +++++++---- .../Utils/QueuedMusicListEmbedProvider.hpp | 1 + src/Audio/MusicPlayManager.cpp | 61 +++++++++++-------- src/Commands/Delete.cpp | 1 - src/Commands/Play.cpp | 4 +- src/Queue/MusicQueue.cpp | 4 +- 10 files changed, 87 insertions(+), 64 deletions(-) diff --git a/BuildDockerAndUpload.sh b/BuildDockerAndUpload.sh index 05b27b5..c3b1596 100755 --- a/BuildDockerAndUpload.sh +++ b/BuildDockerAndUpload.sh @@ -1,7 +1,4 @@ #!/bin/bash -if [ "$(id -u)" -ne 0 ]; then - exec sudo "$0" "$@" -fi cd build cmake .. && make cd .. diff --git a/Dockerfile b/Dockerfile index 9bb828b..fcaaf28 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ 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 apt-get update +RUN apt-get install -y curl +RUN apt-get install -y libopus0 +RUN apt-get install -y tini +RUN apt-get install -y liboggz2 +RUN apt-get install -y xz-utils +RUN apt-get install -y python3 +RUN apt-get install -y python3-pip +RUN apt-get install -y ffmpeg +RUN apt-get install -y python3-certifi +RUN apt-get install -y python3-brotli +RUN apt-get install -y python3-websockets +RUN apt-get install -y python3-requests +RUN apt-get install -y python3-mutagen +RUN pip3 install --break-system-packages --no-cache-dir curl_cffi +RUN pip3 install --break-system-packages --no-cache-dir pycryptodome RUN curl -Lo dpp.deb https://dl.dpp.dev/ RUN dpkg -i dpp.deb RUN rm dpp.deb diff --git a/include/BumbleBee.hpp b/include/BumbleBee.hpp index d0c099a..bc35d55 100644 --- a/include/BumbleBee.hpp +++ b/include/BumbleBee.hpp @@ -43,6 +43,7 @@ public: std::shared_ptr cluster; /// @brief guild id 배열 std::vector GIDs; + private: /// @brief Command 목록 std::unordered_map> commands; diff --git a/include/Commands/BumbleBeeCommand.hpp b/include/Commands/BumbleBeeCommand.hpp index a97143f..8ee6e36 100644 --- a/include/Commands/BumbleBeeCommand.hpp +++ b/include/Commands/BumbleBeeCommand.hpp @@ -23,9 +23,11 @@ public: /// @brief 명령어 별명 std::vector aliases; + private: /// @brief 봇 ID dpp::snowflake botID; + protected: /// @brief 음악재생 매니저 std::shared_ptr musicManager; @@ -51,9 +53,10 @@ public: \ description = DESCRIPTION; \ init(); \ } \ - virtual void execute(const dpp::slashcommand_t &event) override; \ + void execute(const dpp::slashcommand_t &event) override; \ + \ protected: \ - virtual void init() override; \ + void init() override; \ }; \ } diff --git a/include/Queue/MusicQueue.hpp b/include/Queue/MusicQueue.hpp index 7cf77cb..41b85be 100644 --- a/include/Queue/MusicQueue.hpp +++ b/include/Queue/MusicQueue.hpp @@ -15,22 +15,35 @@ public: currentPlayingPosition = queue.begin(); repeat = true; } - void enqueue(std::shared_ptr Element); - std::shared_ptr dequeue(); - std::list>::iterator findById(std::string id); - std::list>::iterator findByIndex(int index); - std::shared_ptr nowplaying(); - std::list>::iterator next_music(); - std::shared_ptr jump_to_index(int idx); - void clear(); - std::shared_ptr erase(std::list>::iterator it); - std::pair>>, std::list>::iterator> getQueueCopy(); - int size(); - std::list>::iterator end(); + void + enqueue(std::shared_ptr Element); + std::shared_ptr + dequeue(); + std::list>::iterator + findById(std::string id); + std::list>::iterator + findByIndex(int index); + std::shared_ptr + nowplaying(); + std::list>::iterator + next_music(); + std::shared_ptr + jump_to_index(int idx); + void + clear(); + std::shared_ptr + erase(std::list>::iterator it); + std::pair>>, std::list>::iterator> + getQueueCopy(); + int + size(); + std::list>::iterator + end(); bool repeat; std::list>::iterator currentPlayingPosition; + private: std::list> queue; std::mutex queueMutex; diff --git a/include/Utils/QueuedMusicListEmbedProvider.hpp b/include/Utils/QueuedMusicListEmbedProvider.hpp index e339681..801393c 100644 --- a/include/Utils/QueuedMusicListEmbedProvider.hpp +++ b/include/Utils/QueuedMusicListEmbedProvider.hpp @@ -20,6 +20,7 @@ public: } return returnValue; } + private: static dpp::embed makeEmbedPart( std::shared_ptr>> queue, diff --git a/src/Audio/MusicPlayManager.cpp b/src/Audio/MusicPlayManager.cpp index 0e8f949..97b2e14 100644 --- a/src/Audio/MusicPlayManager.cpp +++ b/src/Audio/MusicPlayManager.cpp @@ -87,45 +87,52 @@ MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId) } void MusicPlayManager::send_audio_to_voice(std::shared_ptr music, dpp::discord_voice_client* client) { - std::string command = "./streamOpus.sh "; - command += SettingsManager::getYTDLP_CMD() + " "; - command += SettingsManager::getFFMPEG_CMD() + " "; - command += "https://youtu.be/"; - command += music->id; + std::thread t([](std::shared_ptr music, dpp::discord_voice_client* client) { + 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); + OGGZ* og = oggz_open_stdio(popen(command.c_str(), "r"), OGGZ_READ); - client->stop_audio(); + // client->stop_audio(); //이거 필요함?? - oggz_set_read_callback( - og, -1, - [](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) { - auto voiceConn = (dpp::discord_voice_client *)user_data; + oggz_set_read_callback( + og, -1, + [](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) { + auto voiceConn = (dpp::discord_voice_client *)user_data; - voiceConn->send_audio_opus(packet->op.packet, packet->op.bytes); + voiceConn->send_audio_opus(packet->op.packet, packet->op.bytes); - return 0; - }, - (void *)client - ); + return 0; + }, + (void *)client + ); - while (client && !client->terminating && music != nullptr) { - static const constexpr long CHUNK_READ = BUFSIZ * 2; + while (client && !client->terminating && music != nullptr) { + static const constexpr long CHUNK_READ = BUFSIZ * 2; - const long read_bytes = oggz_read(og, CHUNK_READ); + const long read_bytes = oggz_read(og, CHUNK_READ); - /* break on eof */ - if (!read_bytes) { - break; + /* break on eof */ + if (!read_bytes) { + break; + } } - } - if (music != nullptr) - client->creator->log(dpp::ll_info, "Sending " + music->embed.title + " - " + music->id + " complete!"); + if (music != nullptr) + client->creator->log(dpp::ll_info, "Sending " + music->embed.title + " - " + music->id + " complete!"); + else { + client->stop_audio(); + client->pause_audio(true); + } - oggz_close(og); + oggz_close(og); - client->insert_marker(); + client->insert_marker(); + }, music, client); + t.detach(); } } diff --git a/src/Commands/Delete.cpp b/src/Commands/Delete.cpp index 41f6734..a6dc4db 100644 --- a/src/Commands/Delete.cpp +++ b/src/Commands/Delete.cpp @@ -7,7 +7,6 @@ namespace bumbleBee::commands { if (pos < 0 || pos > musicManager->size(event.command.guild_id)) { - event.edit_original_response(dpp::message(std::string("이상한 인덱스 위치. Pos :") + std::to_string(pos))); return; } diff --git a/src/Commands/Play.cpp b/src/Commands/Play.cpp index 93685de..2eb04eb 100644 --- a/src/Commands/Play.cpp +++ b/src/Commands/Play.cpp @@ -222,8 +222,8 @@ namespace bumbleBee::commands { event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!")); return; } - - musicManager->play(v->voiceclient); + v->voiceclient->insert_marker(); + v->voiceclient->pause_audio(false); } } diff --git a/src/Queue/MusicQueue.cpp b/src/Queue/MusicQueue.cpp index 9699f06..453c955 100644 --- a/src/Queue/MusicQueue.cpp +++ b/src/Queue/MusicQueue.cpp @@ -46,8 +46,10 @@ std::list>::iterator MusicQueue::next_music() std::lock_guard lock(queueMutex); if (currentPlayingPosition == --queue.end() && repeat) currentPlayingPosition = queue.begin(); - else if (currentPlayingPosition == --queue.end() && !repeat) + else if (currentPlayingPosition == --queue.end() && !repeat) // 반복이 꺼져있을 때 큐 재생이 끝난 경우 currentPlayingPosition = queue.end(); + else if (currentPlayingPosition == queue.end() && !repeat) // 반복이 꺼져있고 현재 재생 곡이 없는데 새 곡이 들어왔을 경우 + currentPlayingPosition = --queue.end(); else ++currentPlayingPosition; return currentPlayingPosition;