아직 read loop ended는 못잡았지만 아무튼 완성(진) 일단 셔플 빼그 기능은 다 작동하니 된 게 아닐까?

This commit is contained in:
2025-02-02 06:37:31 +09:00
parent 0cb7ea8225
commit 2935a844a0
8 changed files with 85 additions and 96 deletions

View File

@@ -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"]

7
docker-compose.yml Normal file
View File

@@ -0,0 +1,7 @@
services:
bumblebee:
build: .
container_name: BumbleBee
volumes:
- ./config.json:/config.json
restart: unless-stopped

View File

@@ -2,6 +2,7 @@
#include <ogg/ogg.h>
#include <oggz/oggz.h>
#include <algorithm>
#include <Settings/SettingsManager.hpp>
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);

View File

@@ -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);});

View File

@@ -3,12 +3,6 @@
namespace bumbleBee::commands {
void Delete::execute(const dpp::slashcommand_t &event) {
if (std::holds_alternative<std::monostate>(event.get_parameter("pos"))) // 여기 들어올 일 있나?
{
event.edit_original_response(dpp::message("위치를 제공하여 주십시오"));
event.reply("");
return;
}
int pos = std::get<std::int64_t>(event.get_parameter("pos"));
if (pos < 0 || pos > musicManager->size(event.command.guild_id))

View File

@@ -1,14 +1,18 @@
#include <Commands/BumbleBeeCommand.hpp>
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("음성 채팅방을 떠납니다!"));

View File

@@ -23,7 +23,10 @@ namespace bumbleBee::commands {
}
std::string query = std::get<std::string>(event.get_parameter("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<std::string> ids =
ConsoleUtils::getResultFromCommand(
SettingsManager::getYTDLP_CMD() +
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
std::queue<std::shared_ptr<MusicQueueElement>> musics;
@@ -36,59 +39,14 @@ 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<MusicQueueElement>(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];
@@ -125,39 +83,26 @@ namespace bumbleBee::commands {
);
musics.push(std::make_shared<MusicQueueElement>(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");
}
}

View File

@@ -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("스킵했습니다!"));
}