mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 01:45:15 +00:00
완성(준)
This commit is contained in:
@@ -8,13 +8,19 @@
|
||||
namespace bumbleBee {
|
||||
class MusicPlayManager {
|
||||
public:
|
||||
MusicPlayManager(std::shared_ptr<dpp::cluster> cluster) {
|
||||
this->cluster = cluster;
|
||||
this->queue = std::make_unique<MusicQueue>();
|
||||
MusicPlayManager(std::shared_ptr<dpp::cluster> cluster, std::vector<dpp::snowflake> GIDs) :
|
||||
cluster(cluster), GIDs(GIDs) {
|
||||
queueMap = std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>>();
|
||||
queueEmptyMutex = std::unordered_map<dpp::snowflake, std::shared_ptr<std::mutex>>();
|
||||
|
||||
cluster->on_voice_ready([this](const dpp::voice_ready_t &event){on_voice_ready(event);});
|
||||
cluster->on_voice_track_marker([this](const dpp::voice_track_marker_t &event){on_voice_track_marker(event);});
|
||||
cluster->on_voice_client_disconnect([this](const dpp::voice_client_disconnect_t& event){on_voice_client_disconnect(event);});
|
||||
|
||||
for (auto GID : GIDs) {
|
||||
queueMap[GID] = std::make_shared<MusicQueue>();
|
||||
queueEmptyMutex[GID] = std::make_shared<std::mutex>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,18 +39,31 @@ public:
|
||||
**/
|
||||
void on_voice_client_disconnect(const dpp::voice_client_disconnect_t& event);
|
||||
|
||||
void queue_music(const std::shared_ptr<MusicQueueElement> music);
|
||||
void play(dpp::discord_voice_client* client);
|
||||
|
||||
void queue_music(const dpp::snowflake guildId, const std::shared_ptr<MusicQueueElement> music);
|
||||
|
||||
void clear(const dpp::snowflake guildId);
|
||||
std::shared_ptr<MusicQueueElement> remove(const dpp::snowflake guildId, dpp::discord_voice_client* client, int index);
|
||||
int size(const dpp::snowflake guildId);
|
||||
|
||||
void setRepeat(const dpp::snowflake guildId, const bool value);
|
||||
bool getRepeat(const dpp::snowflake guildId);
|
||||
|
||||
std::list<MusicQueueElement> getQueue(const dpp::snowflake guildId);
|
||||
MusicQueueElement getNowPlaying(const dpp::snowflake guildId);
|
||||
|
||||
std::condition_variable queuedCondition;
|
||||
private:
|
||||
std::shared_ptr<dpp::cluster> cluster;
|
||||
|
||||
std::vector<dpp::snowflake> GIDs;
|
||||
/// @brief 음악 큐
|
||||
std::unique_ptr<MusicQueue> queue;
|
||||
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> queueMap;
|
||||
|
||||
std::mutex queueEmptyMutex;
|
||||
std::unordered_map<dpp::snowflake, std::shared_ptr<std::mutex>> queueEmptyMutex;
|
||||
|
||||
void send_audio_to_voice(const MusicQueueElement& music, const dpp::voice_ready_t &event);
|
||||
void send_audio_to_voice(const MusicQueueElement& music, const dpp::voice_track_marker_t& event);
|
||||
void send_audio_to_voice(const MusicQueueElement& music, dpp::discord_voice_client* client);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
|
||||
/// @brief DPP 기본 클러스터 객체
|
||||
std::shared_ptr<dpp::cluster> cluster;
|
||||
/// @brief guild id 배열
|
||||
std::vector<dpp::snowflake> GIDs;
|
||||
private:
|
||||
/// @brief Command 목록
|
||||
std::unordered_map<std::string, std::shared_ptr<commands::ICommand>> commands;
|
||||
|
||||
@@ -62,7 +62,7 @@ protected: \
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Delete, d, "큐의 해당하는 번호의 노래를 지웁니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Leave, l, "음성 채팅방을 떠납니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Play, p, "노래 재생")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Queue, q, "노래 예약 큐를 출력합니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Queue, q, "노래 예약 큐를 확인합니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Repeat, r, "반복을 켜거나 끕니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Skip, s, "현재 재생중인 곡을 스킵합니다")
|
||||
_DECLARE_BUMBLEBEE_COMMAND(Shuffle, shuffle, "큐를 섞습니다")
|
||||
|
||||
@@ -15,20 +15,25 @@ public:
|
||||
MusicQueue() {
|
||||
queue = std::list<std::shared_ptr<MusicQueueElement>>();
|
||||
currentPlayingPosition = queue.begin();
|
||||
repeat = false;
|
||||
repeat = true;
|
||||
}
|
||||
void enqueue(std::shared_ptr<MusicQueueElement> Element);
|
||||
std::shared_ptr<MusicQueueElement> dequeue();
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator findById(std::string id);
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator findByIndex(int index);
|
||||
std::shared_ptr<MusicQueueElement> nowplaying();
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator 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::list<std::shared_ptr<MusicQueueElement>> getQueueCopy();
|
||||
int size();
|
||||
|
||||
bool repeat;
|
||||
|
||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator currentPlayingPosition;
|
||||
std::list<std::shared_ptr<MusicQueueElement>> queue;
|
||||
private:
|
||||
std::list<std::shared_ptr<MusicQueueElement>> queue;
|
||||
std::mutex queueMutex;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ public:
|
||||
MusicQueueElement(
|
||||
std::string id,
|
||||
std::string query,
|
||||
dpp::user issuingUser) :
|
||||
id(id), query(query), issuingUser(issuingUser) {}
|
||||
dpp::user issuingUser,
|
||||
dpp::embed embed) :
|
||||
id(id), query(query), issuingUser(issuingUser), embed(embed) {}
|
||||
|
||||
const std::string id;
|
||||
const std::string query;
|
||||
const dpp::user issuingUser;
|
||||
const dpp::embed embed;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -12,7 +12,7 @@ public:\
|
||||
|
||||
namespace bumbleBee {
|
||||
/// @brief 모든 설정은 이 객체를 통해 스태틱하게 제공됨.
|
||||
class settingsManager {
|
||||
class SettingsManager {
|
||||
/// @brief 봇 토큰
|
||||
_DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(std::string, TOKEN, TOKEN)
|
||||
/// @brief yt-dlp 실행 명령어
|
||||
@@ -22,7 +22,7 @@ class settingsManager {
|
||||
/// @brief 로그레벨
|
||||
_DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(dpp::loglevel, LOGLEVEL, LOGLEVEL)
|
||||
/// @brief 이전에 있던 명령을 지우고 등록할지 선택합니다.
|
||||
_DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(bool, CLCOMMAND, CLCOMMAND)
|
||||
_DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(bool, REGISTER_COMMAND, REGISTER_COMMAND)
|
||||
public:
|
||||
/// @brief 설정 로드하기, 설정은 이 load()를 부르기 전까지는 적절하지 못한 값을 가지고 있음.
|
||||
/// @return 로드 성공 시 true, 실패 시 false 반환.
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
static void validateYTDLPFFMPEGBinary(std::shared_ptr<dpp::cluster> cluster) {
|
||||
cluster->log(dpp::ll_info, "Checking if yt-dlp and ffmpeg is available...");
|
||||
std::queue<std::string> result = ConsoleUtils::getResultFromCommand(settingsManager::getFFMPEG_CMD() + " -version");
|
||||
std::queue<std::string> result = ConsoleUtils::getResultFromCommand(SettingsManager::getFFMPEG_CMD() + " -version");
|
||||
std::string front = result.front();
|
||||
if (front[0] != 'f' ||
|
||||
front[1] != 'f' ||
|
||||
@@ -40,9 +40,9 @@ public:
|
||||
system("tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||
system("rm ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||
system("mv ffmpeg-master-latest-linux64-gpl ffmpeg");
|
||||
settingsManager::setFFMPEG_CMD("./ffmpeg/bin/ffmpeg");
|
||||
SettingsManager::setFFMPEG_CMD("./ffmpeg/bin/ffmpeg");
|
||||
}
|
||||
result = ConsoleUtils::getResultFromCommand(settingsManager::getYTDLP_CMD() + " --version");
|
||||
result = ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() + " --version");
|
||||
front = result.front();
|
||||
if ((front[0]-'0' < 0 || front[0]-'0' > 9) ||
|
||||
(front[1]-'0' < 0 || front[1]-'0' > 9) ||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
system("curl -LO https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp");
|
||||
system("chmod +x ./yt-dlp");
|
||||
settingsManager::setYTDLP_CMD("./yt-dlp");
|
||||
SettingsManager::setYTDLP_CMD("./yt-dlp");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user