mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
코드 가독성 리팩터
This commit is contained in:
@@ -87,45 +87,52 @@ MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId)
|
||||
}
|
||||
|
||||
void MusicPlayManager::send_audio_to_voice(std::shared_ptr<bumbleBee::MusicQueueElement> 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<bumbleBee::MusicQueueElement> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::next_music()
|
||||
std::lock_guard<std::mutex> 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;
|
||||
|
||||
Reference in New Issue
Block a user