mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 01:45:15 +00:00
코드 가독성 리팩터
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
|
||||||
exec sudo "$0" "$@"
|
|
||||||
fi
|
|
||||||
cd build
|
cd build
|
||||||
cmake .. && make
|
cmake .. && make
|
||||||
cd ..
|
cd ..
|
||||||
|
|||||||
32
Dockerfile
32
Dockerfile
@@ -1,21 +1,21 @@
|
|||||||
FROM debian:sid
|
FROM debian:sid
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
RUN apt update
|
RUN apt-get update
|
||||||
RUN apt install -y curl
|
RUN apt-get install -y curl
|
||||||
RUN apt install -y libopus0
|
RUN apt-get install -y libopus0
|
||||||
RUN apt install -y tini
|
RUN apt-get install -y tini
|
||||||
RUN apt install -y liboggz2
|
RUN apt-get install -y liboggz2
|
||||||
RUN apt install -y xz-utils
|
RUN apt-get install -y xz-utils
|
||||||
RUN apt install -y python3
|
RUN apt-get install -y python3
|
||||||
RUN apt install -y python3-pip
|
RUN apt-get install -y python3-pip
|
||||||
RUN apt install -y ffmpeg
|
RUN apt-get install -y ffmpeg
|
||||||
RUN apt install -y python3-certifi
|
RUN apt-get install -y python3-certifi
|
||||||
RUN apt install -y python3-brotli
|
RUN apt-get install -y python3-brotli
|
||||||
RUN apt install -y python3-websockets
|
RUN apt-get install -y python3-websockets
|
||||||
RUN apt install -y python3-requests
|
RUN apt-get install -y python3-requests
|
||||||
RUN apt install -y python3-mutagen
|
RUN apt-get install -y python3-mutagen
|
||||||
RUN pip3 install --break-system-packages curl_cffi
|
RUN pip3 install --break-system-packages --no-cache-dir curl_cffi
|
||||||
RUN pip3 install --break-system-packages pycryptodome
|
RUN pip3 install --break-system-packages --no-cache-dir pycryptodome
|
||||||
RUN curl -Lo dpp.deb https://dl.dpp.dev/
|
RUN curl -Lo dpp.deb https://dl.dpp.dev/
|
||||||
RUN dpkg -i dpp.deb
|
RUN dpkg -i dpp.deb
|
||||||
RUN rm dpp.deb
|
RUN rm dpp.deb
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public:
|
|||||||
std::shared_ptr<dpp::cluster> cluster;
|
std::shared_ptr<dpp::cluster> cluster;
|
||||||
/// @brief guild id 배열
|
/// @brief guild id 배열
|
||||||
std::vector<dpp::snowflake> GIDs;
|
std::vector<dpp::snowflake> GIDs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief Command 목록
|
/// @brief Command 목록
|
||||||
std::unordered_map<std::string, std::shared_ptr<commands::ICommand>> commands;
|
std::unordered_map<std::string, std::shared_ptr<commands::ICommand>> commands;
|
||||||
|
|||||||
@@ -23,9 +23,11 @@ public:
|
|||||||
|
|
||||||
/// @brief 명령어 별명
|
/// @brief 명령어 별명
|
||||||
std::vector<std::string> aliases;
|
std::vector<std::string> aliases;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief 봇 ID
|
/// @brief 봇 ID
|
||||||
dpp::snowflake botID;
|
dpp::snowflake botID;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// @brief 음악재생 매니저
|
/// @brief 음악재생 매니저
|
||||||
std::shared_ptr<MusicPlayManager> musicManager;
|
std::shared_ptr<MusicPlayManager> musicManager;
|
||||||
@@ -51,9 +53,10 @@ public: \
|
|||||||
description = DESCRIPTION; \
|
description = DESCRIPTION; \
|
||||||
init(); \
|
init(); \
|
||||||
} \
|
} \
|
||||||
virtual void execute(const dpp::slashcommand_t &event) override; \
|
void execute(const dpp::slashcommand_t &event) override; \
|
||||||
|
\
|
||||||
protected: \
|
protected: \
|
||||||
virtual void init() override; \
|
void init() override; \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,22 +15,35 @@ public:
|
|||||||
currentPlayingPosition = queue.begin();
|
currentPlayingPosition = queue.begin();
|
||||||
repeat = true;
|
repeat = true;
|
||||||
}
|
}
|
||||||
void enqueue(std::shared_ptr<MusicQueueElement> Element);
|
void
|
||||||
std::shared_ptr<MusicQueueElement> dequeue();
|
enqueue(std::shared_ptr<MusicQueueElement> Element);
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator findById(std::string id);
|
std::shared_ptr<MusicQueueElement>
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator findByIndex(int index);
|
dequeue();
|
||||||
std::shared_ptr<MusicQueueElement> nowplaying();
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator next_music();
|
findById(std::string id);
|
||||||
std::shared_ptr<MusicQueueElement> jump_to_index(int idx);
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator
|
||||||
void clear();
|
findByIndex(int index);
|
||||||
std::shared_ptr<MusicQueueElement> erase(std::list<std::shared_ptr<MusicQueueElement>>::iterator it);
|
std::shared_ptr<MusicQueueElement>
|
||||||
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator> getQueueCopy();
|
nowplaying();
|
||||||
int size();
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator end();
|
next_music();
|
||||||
|
std::shared_ptr<MusicQueueElement>
|
||||||
|
jump_to_index(int idx);
|
||||||
|
void
|
||||||
|
clear();
|
||||||
|
std::shared_ptr<MusicQueueElement>
|
||||||
|
erase(std::list<std::shared_ptr<MusicQueueElement>>::iterator it);
|
||||||
|
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator>
|
||||||
|
getQueueCopy();
|
||||||
|
int
|
||||||
|
size();
|
||||||
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator
|
||||||
|
end();
|
||||||
|
|
||||||
bool repeat;
|
bool repeat;
|
||||||
|
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator currentPlayingPosition;
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator currentPlayingPosition;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::shared_ptr<MusicQueueElement>> queue;
|
std::list<std::shared_ptr<MusicQueueElement>> queue;
|
||||||
std::mutex queueMutex;
|
std::mutex queueMutex;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public:
|
|||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static dpp::embed makeEmbedPart(
|
static dpp::embed makeEmbedPart(
|
||||||
std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue,
|
std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue,
|
||||||
|
|||||||
@@ -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) {
|
void MusicPlayManager::send_audio_to_voice(std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client) {
|
||||||
std::string command = "./streamOpus.sh ";
|
std::thread t([](std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client) {
|
||||||
command += SettingsManager::getYTDLP_CMD() + " ";
|
std::string command = "./streamOpus.sh ";
|
||||||
command += SettingsManager::getFFMPEG_CMD() + " ";
|
command += SettingsManager::getYTDLP_CMD() + " ";
|
||||||
command += "https://youtu.be/";
|
command += SettingsManager::getFFMPEG_CMD() + " ";
|
||||||
command += music->id;
|
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(
|
oggz_set_read_callback(
|
||||||
og, -1,
|
og, -1,
|
||||||
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
||||||
auto voiceConn = (dpp::discord_voice_client *)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;
|
return 0;
|
||||||
},
|
},
|
||||||
(void *)client
|
(void *)client
|
||||||
);
|
);
|
||||||
|
|
||||||
while (client && !client->terminating && music != nullptr) {
|
while (client && !client->terminating && music != nullptr) {
|
||||||
static const constexpr long CHUNK_READ = BUFSIZ * 2;
|
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 */
|
/* break on eof */
|
||||||
if (!read_bytes) {
|
if (!read_bytes) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (music != nullptr)
|
if (music != nullptr)
|
||||||
client->creator->log(dpp::ll_info, "Sending " + music->embed.title + " - " + music->id + " complete!");
|
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))
|
if (pos < 0 || pos > musicManager->size(event.command.guild_id))
|
||||||
{
|
{
|
||||||
|
|
||||||
event.edit_original_response(dpp::message(std::string("이상한 인덱스 위치. Pos :") + std::to_string(pos)));
|
event.edit_original_response(dpp::message(std::string("이상한 인덱스 위치. Pos :") + std::to_string(pos)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,8 +222,8 @@ namespace bumbleBee::commands {
|
|||||||
event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!"));
|
event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
v->voiceclient->insert_marker();
|
||||||
musicManager->play(v->voiceclient);
|
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);
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
if (currentPlayingPosition == --queue.end() && repeat)
|
if (currentPlayingPosition == --queue.end() && repeat)
|
||||||
currentPlayingPosition = queue.begin();
|
currentPlayingPosition = queue.begin();
|
||||||
else if (currentPlayingPosition == --queue.end() && !repeat)
|
else if (currentPlayingPosition == --queue.end() && !repeat) // 반복이 꺼져있을 때 큐 재생이 끝난 경우
|
||||||
currentPlayingPosition = queue.end();
|
currentPlayingPosition = queue.end();
|
||||||
|
else if (currentPlayingPosition == queue.end() && !repeat) // 반복이 꺼져있고 현재 재생 곡이 없는데 새 곡이 들어왔을 경우
|
||||||
|
currentPlayingPosition = --queue.end();
|
||||||
else
|
else
|
||||||
++currentPlayingPosition;
|
++currentPlayingPosition;
|
||||||
return currentPlayingPosition;
|
return currentPlayingPosition;
|
||||||
|
|||||||
Reference in New Issue
Block a user