23 Commits

Author SHA1 Message Date
c59fef1d0b 일단 저장 2025-08-28 20:46:37 +09:00
125fbcc49c TODO 추가가 2025-03-09 17:29:09 +09:00
4915a5c3b8 TODO리스트는 늘어만 간다.. 2025-03-09 17:27:42 +09:00
4435337f40 TODO 추가가 2025-03-07 17:25:58 +09:00
77d16c1cdb 아마도? 쉘 인젝션 취약점 픽스 2025-03-07 17:19:58 +09:00
5760f1afdc todo 추가가 2025-02-13 17:42:17 +09:00
bb6cd89f51 Update README.md 2025-02-13 17:31:17 +09:00
2a238f804d 사람 나갈 때 음악 꺼지는 문제 해결결 2025-02-13 17:22:42 +09:00
ea7d42638e 코드 리팩터링 중.. 2025-02-13 17:18:03 +09:00
30f97e3dfb 3차 코드 리팩터터 2025-02-13 17:01:38 +09:00
17236f32b5 도커파일 이미지 크기최적화 2025-02-13 16:54:10 +09:00
00134ee7b1 2차 리팩터터 2025-02-13 16:50:03 +09:00
52146c1f6a 코드 가독성 리팩터 2025-02-13 16:43:11 +09:00
bf0268c1e9 Merge branch 'master' of github.com:HappyTanuki/BumbleCee 2025-02-03 01:42:06 +09:00
2f5185e0c3 큐 출력 스타일 변경 2025-02-03 01:42:02 +09:00
96a4096971 Update README.md 2025-02-03 01:32:55 +09:00
ec65b550e6 Update README.md 2025-02-03 01:32:19 +09:00
14db2a31e8 와 이제 진짜 진짜 버그 다 고친 듯? 2025-02-02 23:55:47 +09:00
1af829c711 Merge branch 'master' of github.com:HappyTanuki/BumbleCee 2025-02-02 07:51:56 +09:00
46c59d40de 도커허브 업로드 자동화 구현 2025-02-02 07:51:52 +09:00
b08641f87e Update README.md 2025-02-02 07:10:21 +09:00
1ca928c4df Update README.md 2025-02-02 07:09:57 +09:00
2935a844a0 아직 read loop ended는 못잡았지만 아무튼 완성(진) 일단 셔플 빼그 기능은 다 작동하니 된 게 아닐까? 2025-02-02 06:37:31 +09:00
34 changed files with 631 additions and 255 deletions

3
.gitignore vendored
View File

@@ -3,4 +3,5 @@ Temp/
Music
*.json
yt-dlp
ffmpeg
ffmpeg
password

View File

@@ -102,6 +102,8 @@
"hash_set": "cpp",
"regex": "cpp",
"stack": "cpp",
"__memory": "cpp"
"__memory": "cpp",
"__verbose_abort": "cpp",
"print": "cpp"
}
}

8
BuildDockerAndUpload.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
(
cd build
cmake .. && make
)
docker login -u happytanuki12 --password-stdin < password
docker build --tag happytanuki12/bumblebee:latest .
docker push happytanuki12/bumblebee:latest

View File

@@ -1,5 +1,7 @@
cmake_minimum_required (VERSION 3.6)
INCLUDE_DIRECTORIES(include . ${Boost_INCLUDE_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(BOT_NAME "BumbleCee")
@@ -18,8 +20,11 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
add_definitions( -DBOOST_ALL_NO_LIB )
set( Boost_USE_STATIC_LIBS ON )
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED)
target_include_directories(${BOT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
@@ -35,6 +40,7 @@ target_link_libraries(${BOT_NAME}
${CMAKE_THREAD_LIBS_INIT}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${Boost_LIBRARIES}
)
link_directories(/usr/lib)

View File

@@ -1 +1,21 @@
FROM alpine
FROM debian:sid
WORKDIR /
RUN apt-get update && \
apt-get install -y curl libopus0 tini liboggz2 xz-utils ffmpeg python3 \
python3-pip python3-certifi python3-brotli python3-websockets python3-requests python3-mutagen && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
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/latest
RUN curl -Lo dpp-legacy.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.0.35/libdpp-10.0.35-linux-x64.deb
RUN dpkg -i dpp.deb
RUN dpkg -i dpp-legacy.deb
RUN rm dpp.deb
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 chmod +x BumbleCee
RUN chmod +x streamOpus.sh
ENTRYPOINT ["/usr/bin/tini", "--", "./BumbleCee"]

View File

@@ -1,18 +1,25 @@
# 이게 뭔가요?
[![CodeFactor](https://www.codefactor.io/repository/github/happytanuki/bumblecee/badge)](https://www.codefactor.io/repository/github/happytanuki/bumblecee)
C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악봇입니다!
<div align="center">
<a href="https://github.com/brainboxdotcc/DPP" alt="DPP"> <img src="DPP-markdown-logo.png" /> </a>
</div>
# 어떻게 써요?
1. 실행파일 경로에 config.json 파일을 만들고 다음과 같이 입력하세요:
```
{"token": "디스코드에서 발급받은 개인 봇 토큰"}
{
"CLEAR_PREVIOUS_COMMAND": true,
"FFMPEG_CMD": "ffmpeg",
"LOGLEVEL": "debug",
"TOKEN": "발급받은 토큰",
"YTDLP_CMD": "./yt-dlp"
}
```
2. Music 디렉터리를 만드세요
3. Music/Archive 파일을 만드세요
4. 봇을 실행시키고 초대하셔서 사용하시면 됩니다.
2. 봇을 초대하시고 사용하시면 됩니다.
# 명령어
## /p
@@ -36,3 +43,6 @@ C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악
음성 채팅을 떠납니다.
사용법:
/l
# docker
happytanuki12/bumblebee:latest

7
docker-compose.yml Normal file
View File

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

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _MUSICPLAYMANAGER_HPP_
#define _MUSICPLAYMANAGER_HPP_
#include <dpp/dpp.h>
#include <Queue/MusicQueue.hpp>
#include <condition_variable>
@@ -50,10 +48,11 @@ public:
void setRepeat(const dpp::snowflake guildId, const bool value);
bool getRepeat(const dpp::snowflake guildId);
std::list<MusicQueueElement> getQueue(const dpp::snowflake guildId);
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator> getQueue(const dpp::snowflake guildId);
MusicQueueElement getNowPlaying(const dpp::snowflake guildId);
std::condition_variable queuedCondition;
private:
std::shared_ptr<dpp::cluster> cluster;
@@ -63,7 +62,6 @@ private:
std::unordered_map<dpp::snowflake, std::shared_ptr<std::mutex>> queueEmptyMutex;
void send_audio_to_voice(const MusicQueueElement& music, dpp::discord_voice_client* client);
void send_audio_to_voice(std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client);
};
}
#endif
}

View File

@@ -0,0 +1,18 @@
#pragma once
#include <memory>
#include <dpp/dpp.h>
#include <Queue/MusicQueueElement.hpp>
#include "Utils/ThreadPool.hpp"
namespace bumbleBee {
class ThreadManager : public ThreadPool<dpp::snowflake, int, int> {
public:
bool addMusic(std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client);
void stopSending(dpp::snowflake gid);
private:
// GID, 쓰레드
std::unordered_map<dpp::snowflake, std::thread> threadPool;
// GID, 쓰레드 종료
std::unordered_map<dpp::snowflake, bool> terminating;
};
}

View File

@@ -43,6 +43,7 @@ public:
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;

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _BUMBLEBEECOMMAND_HPP_
#define _BUMBLEBEECOMMAND_HPP_
#include <dpp/dpp.h>
#include <Audio/MusicPlayManager.hpp>
#include <functional>
@@ -25,9 +23,11 @@ public:
/// @brief 명령어 별명
std::vector<std::string> aliases;
private:
/// @brief 봇 ID
dpp::snowflake botID;
protected:
/// @brief 음악재생 매니저
std::shared_ptr<MusicPlayManager> musicManager;
@@ -53,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; \
}; \
}
@@ -65,6 +66,4 @@ _DECLARE_BUMBLEBEE_COMMAND(Play, p, "노래 재생")
_DECLARE_BUMBLEBEE_COMMAND(Queue, q, "노래 예약 큐를 확인합니다")
_DECLARE_BUMBLEBEE_COMMAND(Repeat, r, "반복을 켜거나 끕니다")
_DECLARE_BUMBLEBEE_COMMAND(Skip, s, "현재 재생중인 곡을 스킵합니다")
_DECLARE_BUMBLEBEE_COMMAND(Shuffle, shuffle, "큐를 섞습니다")
#endif
_DECLARE_BUMBLEBEE_COMMAND(Shuffle, shuffle, "큐를 섞습니다")

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _MUSICQUEUE_HPP_
#define _MUSICQUEUE_HPP_
#include <memory>
#include <functional>
#include <condition_variable>
@@ -17,25 +15,37 @@ public:
currentPlayingPosition = queue.begin();
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();
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::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;
std::list<std::shared_ptr<MusicQueueElement>>::iterator currentPlayingPosition;
private:
std::list<std::shared_ptr<MusicQueueElement>> queue;
std::mutex queueMutex;
};
}
#endif
}

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _MUSICQUEUEELEMENT_HPP_
#define _MUSICQUEUEELEMENT_HPP_
#include <dpp/dpp.h>
namespace bumbleBee {
@@ -19,5 +17,4 @@ public:
const dpp::user issuingUser;
const dpp::embed embed;
};
}
#endif
}

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _SETTINGSMANAGER_HPP_
#define _SETTINGSMANAGER_HPP_
#include <dpp/dpp.h>
#define _DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(type, name, Name)\
@@ -33,5 +31,4 @@ public:
/// @return 유효한 토큰이면 true, 아니면 false를 반환합니다.
static bool validateToken();
};
}
#endif
}

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _ASYNCDOWNLOADMANAGER_HPP_
#define _ASYNCDOWNLOADMANAGER_HPP_
#include <queue>
#include <string>
#include <thread>
@@ -55,6 +53,4 @@ private:
std::vector<std::thread> worker_thread;
bool terminate;
};
}
#endif
}

View File

@@ -1,9 +1,9 @@
#pragma once
#ifndef _CONSOLEUTILS_HPP_
#define _CONSOLEUTILS_HPP_
#include <iostream>
#include <sstream>
#include <queue>
#include <regex>
#include <boost/process.hpp>
namespace bumbleBee {
class ConsoleUtils {
@@ -11,30 +11,36 @@ public:
/**
* @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 \n을 구분자로 토큰화하여 반환합니다
* @param cmd 실행할 명령
* @param args 아규먼트
* @return std::queue<std::string> tokens
*/
static std::queue<std::string> getResultFromCommand(std::string cmd) {
std::string result, token;
static std::queue<std::string> safe_execute_command(const std::string& cmd, const std::vector<std::string>& args) {
std::queue<std::string> tokens;
FILE* stream;
const int maxBuffer = 12; // 적당한 크기
char buffer[maxBuffer];
cmd.append(" 2>&1"); // 표준에러를 표준출력으로 redirect
try {
boost::process::ipstream output; // 명령의 출력을 받을 스트림
boost::process::child c(cmd, boost::process::args(args), boost::process::std_out > output);
stream = popen(cmd.c_str(), "r"); // 주어진 command를 shell로 실행하고 파이프 연결 (fd 반환)
if (stream) {
while (fgets(buffer, maxBuffer, stream) != NULL) result.append(buffer); // fgets: fd (stream)를 길이 (maxBuffer)만큼 읽어 버퍼 (buffer)에 저장
pclose(stream);
}
std::string line;
while (!output.eof() && std::getline(output, line))
tokens.push(line);
std::stringstream ss(result);
while (std::getline(ss, token, '\n')) {
tokens.push(token);
c.wait(); // 프로세스가 종료될 때까지 대기
return tokens;
} catch (const std::exception& e) {
return tokens;
}
}
/**
* @brief 명령어를 쉘에서 실행하고 결과를 파이프로 연결하여 반환합니다
* @param cmd 실행할 명령
* @param args 아규먼트
* @return FILE* fd
*/
static FILE* safe_open_pipe(const std::string& cmd, const std::vector<std::string>& args) {
boost::process::pipe pipe;
boost::process::child c(cmd, boost::process::args(args), boost::process::std_out > pipe);
return tokens;
return fdopen(pipe.native_source(), "r");
}
};
}
#endif
}

View File

@@ -0,0 +1,77 @@
#pragma once
#include <dpp/dpp.h>
#include <Queue/MusicQueueElement.hpp>
#include <cmath>
namespace bumbleBee {
class QueuedMusicListEmbedProvider {
public:
static std::queue<dpp::embed> makeEmbed(std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue, std::list<std::shared_ptr<MusicQueueElement>>::iterator np, bool repeat) {
std::queue<dpp::embed> returnValue;
std::list<std::shared_ptr<MusicQueueElement>>::iterator it = queue->begin();
if (queue->size() == 0) {
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
returnValue.push(embed);
return returnValue;
}
for (int i = 0; i < std::ceil(queue->size() / 5.0) && it != queue->end(); i++) {
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
returnValue.push(embed);
}
return returnValue;
}
private:
static dpp::embed makeEmbedPart(
std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue,
std::list<std::shared_ptr<MusicQueueElement>>::iterator np,
bool repeat,
std::list<std::shared_ptr<MusicQueueElement>>::iterator &startIter) {
dpp::embed embed = dpp::embed()
.set_color(dpp::colors::sti_blue);
if (queue->begin() == queue->end()) {
embed
.set_title("큐가 비었습니다!")
.set_timestamp(time(0));
if (repeat)
embed.add_field(":repeat:","");
return embed;
}
int startIndex = std::distance(queue->begin(), startIter) + 1;
int index = startIndex;
for (; (index < startIndex + 5) && startIter != queue->end() && index < queue->size()+1; startIter++, index++) { //iter로 순회하면 왠지 모르게 이상한 값을 읽을 때가 있음 이유는 나도 몰?루
if (*startIter == *np)
embed.add_field (
"np",
"",
true
);
else
embed.add_field (
std::to_string(index),
"",
true
);
embed.add_field (
(*startIter)->embed.title,
(*startIter)->embed.description,
true
)
.add_field("","");
}
if (startIter == queue->end() || index >= queue->size()+1) {
embed.set_timestamp(time(0));
if (repeat)
embed.add_field(":repeat:","");
}
return embed;
}
};
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include <memory>
#include <functional>
#include <thread>
#include <condition_variable>
#include <queue>
namespace bumbleBee {
template <typename FuncRet, typename FuncParam>
class ThreadPool {
public:
ThreadPool() = delete;
ThreadPool(std::int32_t threadCount);
std::thread::id execute(std::function<FuncRet(FuncParam)> function);
void gracefullStop(std::thread::id thread);
void gracefullAllStop();
private:
std::mutex mutex_;
std::condition_variable condition_;
std::int32_t threadCount_;
std::vector<std::thread> threadPool_;
std::unordered_map<std::thread, std::bool> terminating_;
};
}

View File

@@ -1,6 +1,4 @@
#pragma once
#ifndef _VERSIONCHECKUTILS_HPP_
#define _VERSIONCHECKUTILS_HPP_
#include <dpp/dpp.h>
#include "ConsoleUtils.hpp"
#include "../Settings/SettingsManager.hpp"
@@ -9,7 +7,7 @@ namespace bumbleBee {
class VersionsCheckUtils {
public:
static bool isThereCMD(std::shared_ptr<dpp::cluster> cluster, std::string cmd) {
if (ConsoleUtils::getResultFromCommand("which " + cmd).size() == 0) {
if (ConsoleUtils::safe_execute_command("/usr/bin/which", {cmd}).size() == 0) {
cluster->log(dpp::ll_error, cmd + " is unavaliable. unresolable error please install " + cmd);
return false;
}
@@ -17,9 +15,8 @@ public:
return true;
}
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");
static void validateFFMPEG(std::shared_ptr<dpp::cluster> cluster) {
std::queue<std::string> result = ConsoleUtils::safe_execute_command(SettingsManager::getFFMPEG_CMD(), {"-version"});
std::string front = result.front();
if (front[0] != 'f' ||
front[1] != 'f' ||
@@ -39,11 +36,15 @@ public:
system("curl -LO https://github.com/BtbN/FFmpeg-Builds/releases/latest/download/ffmpeg-master-latest-linux64-gpl.tar.xz");
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");
system("mv ffmpeg-master-latest-linux64-gpl/bin/ffmpeg .");
system("rm -rf ffmpeg-master-latest-linux64-gpl");
SettingsManager::setFFMPEG_CMD("./ffmpeg");
}
result = ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() + " --version");
front = result.front();
}
static void validateYTDLP(std::shared_ptr<dpp::cluster> cluster) {
std::queue<std::string> result = ConsoleUtils::safe_execute_command(SettingsManager::getYTDLP_CMD(), {"--version"});
std::string front = result.front();
if ((front[0]-'0' < 0 || front[0]-'0' > 9) ||
(front[1]-'0' < 0 || front[1]-'0' > 9) ||
(front[2]-'0' < 0 || front[2]-'0' > 9) ||
@@ -63,9 +64,15 @@ public:
}
}
static void validateYTDLPFFMPEGBinary(std::shared_ptr<dpp::cluster> cluster) {
cluster->log(dpp::ll_info, "Checking if yt-dlp and ffmpeg is available...");
validateFFMPEG(cluster);
validateYTDLP(cluster);
}
static void updateytdlp(std::shared_ptr<dpp::cluster> cluster) {
cluster->log(dpp::ll_info, "Checking if yt-dlp update is available...");
std::queue<std::string> result = ConsoleUtils::getResultFromCommand("./yt-dlp -U");
std::queue<std::string> result = ConsoleUtils::safe_execute_command("./yt-dlp", {"-U"});
while(!result.empty()) {
std::string front = result.front();
result.pop();
@@ -73,5 +80,4 @@ public:
}
}
};
}
#endif
}

View File

@@ -2,6 +2,7 @@
#include <ogg/ogg.h>
#include <oggz/oggz.h>
#include <algorithm>
#include <Settings/SettingsManager.hpp>
namespace bumbleBee {
@@ -10,25 +11,28 @@ void MusicPlayManager::on_voice_ready(const dpp::voice_ready_t& event) {
}
void MusicPlayManager::on_voice_track_marker(const dpp::voice_track_marker_t& event) {
dpp::snowflake gid = dpp::find_channel(event.voice_client->channel_id)->guild_id;
queueMap[gid]->next_music(); // TODO("repeat가 꺼져 있을 때 노래 큐에서 지우기")
play(event.voice_client);
}
void MusicPlayManager::on_voice_client_disconnect(const dpp::voice_client_disconnect_t& event) { // 안 불리는 듯?
dpp::snowflake gid = dpp::find_channel(event.voice_client->channel_id)->guild_id;
event.voice_client->stop_audio();
queueMap[gid]->clear();
void MusicPlayManager::on_voice_client_disconnect(const dpp::voice_client_disconnect_t& event) { // 이거 봇이 나갈 때가 아니고 같이 있는 유저가 나갈 때였고
// dpp::snowflake gid = dpp::find_channel(event.voice_client->channel_id)->guild_id;
// event.voice_client->stop_audio();
// queueMap[gid]->clear();
}
void MusicPlayManager::play(dpp::discord_voice_client* client) {
std::thread t([&](dpp::discord_voice_client* client){
dpp::snowflake gid = dpp::find_channel(client->channel_id)->guild_id;
std::unique_lock<std::mutex> queueEmptyLock(*queueEmptyMutex[gid]);
queuedCondition.wait(queueEmptyLock, [&]{ return queueMap[gid]->size() != 0; });
auto np = queueMap[gid]->next_music();
auto music = **np;
send_audio_to_voice(music, client);
queuedCondition.wait(queueEmptyLock, [&]{
return queueMap[gid]->size() != 0 && queueMap[gid]->currentPlayingPosition != queueMap[gid]->end();
});
auto next = queueMap[gid]->currentPlayingPosition;
send_audio_to_voice(*next, client);
}, client);
t.detach();
}
@@ -68,58 +72,67 @@ bool MusicPlayManager::getRepeat(const dpp::snowflake guildId) {
return queueMap[guildId]->repeat;
}
std::list<MusicQueueElement> MusicPlayManager::getQueue(const dpp::snowflake guildId){
std::list<std::shared_ptr<MusicQueueElement>> queue = queueMap[guildId]->getQueueCopy();
std::list<MusicQueueElement> returnValue;
for (auto iter = queue.begin(); iter != queue.end(); iter++)
returnValue.push_back(**iter);
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator>
MusicPlayManager::getQueue(const dpp::snowflake guildId){
auto returnValue = queueMap[guildId]->getQueueCopy();
return returnValue;
}
MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId) {
std::shared_ptr<MusicQueueElement> nowplaying = queueMap[guildId]->nowplaying();
if (nowplaying == nullptr)
return MusicQueueElement("", "", dpp::user(), dpp::embed());
MusicQueueElement returnValue(*nowplaying);
return returnValue;
}
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/";
command += music.id;
void MusicPlayManager::send_audio_to_voice(std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client) {
std::thread t([](std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client) { // TODO: thread 벡터 만들고 delete, leave, skip시에 전송 중지하도록 만들고. 또 노래 캐싱하고 ytdlp를 버퍼링하여 혹시 있을지 모르는 음성의 끊김을 방지할 것것
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) {
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;
}
}
}
client->creator->log(dpp::ll_info, "Sending " + 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();
}
}

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,17 +3,10 @@
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))
{
event.edit_original_response(dpp::message(std::string("이상한 인덱스 위치. Pos :") + std::to_string(pos)));
return;
}

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

@@ -2,10 +2,12 @@
#include <Utils/ConsoleUtils.hpp>
#include <Settings/SettingsManager.hpp>
#include <dpp/nlohmann/json.hpp>
#include <Utils/QueuedMusicListEmbedProvider.hpp>
#include <Utils/ConsoleUtils.hpp>
#include <variant>
namespace bumbleBee::commands {
void Play::execute(const dpp::slashcommand_t &event) {
void Play::execute(const dpp::slashcommand_t &event) { // TODO : 길드 단위로 잠구고 메타데이터 로딩 중엔 로딩 중임을 표시할 수 있는 UI 만들 것것
dpp::guild *g = dpp::find_guild(event.command.guild_id);
if (!g) { //wtf?
@@ -22,8 +24,20 @@ namespace bumbleBee::commands {
return;
}
std::string query = std::get<std::string>(event.get_parameter("query"));
// query = "\"" + 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::safe_execute_command(
SettingsManager::getYTDLP_CMD(), {
"--default-search",
"ytsearch",
"--flat-playlist",
"--skip-download",
"--quiet",
"--ignore-errors",
"--print",
"id",
query});
std::queue<std::shared_ptr<MusicQueueElement>> musics;
@@ -36,81 +50,39 @@ 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));
if (!ids.empty()) { // TODO : 이거 멀티스레드로 바꿔서 더 빨리 정보를 받아올 수 있도록 개선할 것것
if (ids.front() == "") {
ids.pop();
}
}
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");
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::string jsonData = ConsoleUtils::safe_execute_command(SettingsManager::getYTDLP_CMD(), {
"--default-search",
"ytsearch",
"--flat-playlist",
"--skip-download",
"--quiet",
"--ignore-errors",
"-J",
"http://youtu.be/" + ids.front()
}).front();
std::istringstream iss(oss.str());
std::istringstream iss(jsonData);
nlohmann::json videoDataJson;
iss >> videoDataJson;
time_t SongLength = int(videoDataJson["duration"]);
char SongLengthStr[10];
char SongLengthStr[13];
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);
if (t.tm_mday > 0)
strftime(SongLengthStr, sizeof(SongLengthStr), "%d:%H:%M:%S", &t);
else if (t.tm_hour > 0)
strftime(SongLengthStr, sizeof(SongLengthStr), "%H:%M:%S", &t);
else
strftime(SongLengthStr, sizeof(SongLengthStr), "%M:%S", &t);
dpp::embed embed = dpp::embed()
.set_color(dpp::colors::sti_blue)
@@ -125,39 +97,140 @@ 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);
musicManager->queue_music(event.command.guild_id, musics.front());
msg.add_embed(musics.front()->embed);
musics.pop();
if (!ids.empty()) {
std::thread t([](
std::queue<std::string> ids,
dpp::snowflake guildId,
dpp::snowflake channelId,
std::string query,
dpp::user user,
dpp::cluster* cluster,
std::shared_ptr<MusicPlayManager> manager
) {
while (!ids.empty()) {
if (ids.front() == "") {
ids.pop();
continue;
}
std::string jsonData = ConsoleUtils::safe_execute_command(SettingsManager::getYTDLP_CMD(), {
"--default-search",
"ytsearch",
"--flat-playlist",
"--skip-download",
"--quiet",
"--ignore-errors",
"-J",
"http://youtu.be/" + ids.front()
}).front();
event.edit_original_response(msg);
musicManager->queuedCondition.notify_all();
std::istringstream iss(jsonData);
nlohmann::json videoDataJson;
iss >> videoDataJson;
time_t SongLength = int(videoDataJson["duration"]);
char SongLengthStr[13];
tm t;
t.tm_mday = SongLength / 86400;
t.tm_hour = (SongLength % 86400)/3600;
t.tm_min = (SongLength % 3600)/60;
t.tm_sec = SongLength%60;
if (t.tm_mday > 0)
strftime(SongLengthStr, sizeof(SongLengthStr), "%d:%H:%M:%S", &t);
else if (t.tm_hour > 0)
strftime(SongLengthStr, sizeof(SongLengthStr), "%H:%M:%S", &t);
else
strftime(SongLengthStr, sizeof(SongLengthStr), "%M:%S", &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
);
auto music = std::make_shared<MusicQueueElement>(ids.front(), query, user, embed);
cluster->log(dpp::ll_info, "Enqueuing " + music->embed.title + " - " + music->id);
manager->queue_music(guildId, music);
ids.pop();
}
std::mutex messageorder;
std::unique_lock lock(messageorder);
std::condition_variable messageSentCondition; // 개씨발 코드 개더러워 ;;
bool messagesent = false;
auto queue = manager->getQueue(guildId);
auto queued = QueuedMusicListEmbedProvider::makeEmbed(queue.first, queue.second, manager->getRepeat(guildId));
if (!queued.empty()) {
dpp::message followMsg(channelId, "현재 큐에 있는 항목:");
followMsg.add_embed(queued.front());
messagesent = false;
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
messagesent = true;
messageSentCondition.notify_all();
});
messageSentCondition.wait(lock, [&](){ return messagesent; });
queued.pop();
}
while (!queued.empty()) {
dpp::message followMsg(channelId, "");
followMsg.add_embed(queued.front());
messagesent = false;
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
messagesent = true;
messageSentCondition.notify_all();
});
messageSentCondition.wait(lock, [&](){ return messagesent; });
queued.pop();
}
},
ids,
event.command.guild_id,
event.command.channel_id,
query,
event.command.usr,
event.from->creator,
musicManager);
t.detach();
}
else if (musics.size() > 1) {
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
if (!musics.empty()) {
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()->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");
else {
msg.content = "검색 결과가 없습니다";
event.edit_original_response(msg);
}
if (musicManager->getNowPlaying(event.command.guild_id).id == "") {
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;
}
v->voiceclient->insert_marker();
v->voiceclient->pause_audio(false);
}
}

View File

@@ -1,32 +1,71 @@
#include <Commands/BumbleBeeCommand.hpp>
#include <Utils/QueuedMusicListEmbedProvider.hpp>
namespace bumbleBee::commands {
void Queue::execute(const dpp::slashcommand_t &event) {
auto queue = musicManager->getQueue(event.command.guild_id);
auto nowplaying = musicManager->getNowPlaying(event.command.guild_id);
dpp::message msg;
dpp::embed embed;
if (queue.size() == 0) {
embed
.set_title("큐가 비었습니다!")
.set_timestamp(time(0));
msg.add_embed(embed);
auto queued = QueuedMusicListEmbedProvider::makeEmbed(queue.first, queue.second, musicManager->getRepeat(event.command.guild_id));
// if (queue.first.size() == 0) {
// msg.add_embed(queued.front());
// event.edit_original_response(msg);
// return;
// }
// &&
// queue.first.size() != 0 &&
// *queue.second != nullptr &&
// (*queue.second)->id != ""
if (queue.first->size() != 0 && queue.first->end() != queue.second && (*queue.second)->id != "") {
msg.content = "지금 재생 중:";
msg.add_embed((*queue.second)->embed);
event.edit_original_response(msg);
return;
}
msg.content = "지금 재생 중:";
msg.add_embed(nowplaying.embed);
for (auto iter = queue.begin(); iter != queue.end(); iter++) {
dpp::message followMsg(event.command.channel_id, "");
followMsg.add_embed(iter->embed);
event.from->creator->message_create(followMsg); // 어차피 원래 메시지를 지정해서 수정할 것이기 때문에 먼저 팔로잉 메시지를 작성해도 상관없음.
else {
msg.content = "재생 중인 노래가 없습니다";
event.edit_original_response(msg);
}
event.edit_original_response(msg);
std::thread t([](std::queue<dpp::embed> queued, dpp::snowflake channel_id, dpp::cluster* cluster) {
std::mutex messageorder;
std::unique_lock lock(messageorder);
std::condition_variable messageSentCondition;
bool messagesent = false;
if (!queued.empty()) {
dpp::message followMsg(channel_id, "현재 큐에 있는 항목:");
followMsg.add_embed(queued.front());
messagesent = false;
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
messagesent = true;
messageSentCondition.notify_all();
});
messageSentCondition.wait(lock, [&](){ return messagesent; });
queued.pop();
}
while (!queued.empty()) {
dpp::message followMsg(channel_id, "");
followMsg.add_embed(queued.front());
messagesent = false;
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
messagesent = true;
messageSentCondition.notify_all();
});
messageSentCondition.wait(lock, [&](){ return messagesent; });
queued.pop();
}
}, queued, event.command.channel_id, event.from->creator);
t.detach();
}
void Queue::init() {

View File

@@ -3,6 +3,7 @@
namespace bumbleBee::commands {
void Shuffle::execute(const dpp::slashcommand_t &event) {
event.edit_original_response(dpp::message("shuffle"));
// TODO : 구현
}
void Shuffle::init() {

View File

@@ -5,12 +5,11 @@ namespace bumbleBee::commands {
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;
}
v->voiceclient->pause_audio(true);
v->voiceclient->stop_audio();
v->voiceclient->pause_audio(false);
v->voiceclient->insert_marker("end");
v->voiceclient->insert_marker();
event.edit_original_response(dpp::message("스킵했습니다!"));
}

View File

View File

@@ -1,6 +1,7 @@
#include <Queue/MusicQueue.hpp>
#include <iostream>
#include <algorithm>
#include <Utils/QueuedMusicListEmbedProvider.hpp>
namespace bumbleBee {
@@ -36,14 +37,19 @@ std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::findByIndex(
}
std::shared_ptr<MusicQueueElement> MusicQueue::nowplaying() {
std::lock_guard<std::mutex> lock(queueMutex);
return *currentPlayingPosition;
if (currentPlayingPosition == queue.end())
return nullptr;
else
return *currentPlayingPosition;
}
std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::next_music() {
std::lock_guard<std::mutex> lock(queueMutex);
if (currentPlayingPosition == --queue.end() && !repeat)
return queue.end();
if (currentPlayingPosition == --queue.end() && repeat)
currentPlayingPosition = queue.begin();
else if (currentPlayingPosition == --queue.end() && !repeat) // 반복이 꺼져있을 때 큐 재생이 끝난 경우
currentPlayingPosition = queue.end();
else if (currentPlayingPosition == queue.end() && !repeat) // 반복이 꺼져있고 현재 재생 곡이 없는데 새 곡이 들어왔을 경우
currentPlayingPosition = --queue.end();
else
++currentPlayingPosition;
return currentPlayingPosition;
@@ -82,16 +88,28 @@ std::shared_ptr<MusicQueueElement> MusicQueue::erase(std::list<std::shared_ptr<M
return removedValue;
}
}
std::list<std::shared_ptr<MusicQueueElement>> MusicQueue::getQueueCopy(){
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator>
MusicQueue::getQueueCopy() {
std::lock_guard<std::mutex> lock(queueMutex);
std::list<std::shared_ptr<MusicQueueElement>> returnValue;
std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> returnValue = std::make_shared<std::list<std::shared_ptr<MusicQueueElement>>>();
std::copy(queue.begin(), queue.end(), std::back_inserter(returnValue));
for (auto i = queue.begin(); i != queue.end(); i++)
returnValue->push_back(*i);
return returnValue;
if (returnValue->begin() == returnValue->end() || currentPlayingPosition == queue.end())
return std::make_pair(returnValue, returnValue->end());
std::list<std::shared_ptr<MusicQueueElement>>::iterator iter = returnValue->begin();
std::advance(iter, std::distance(queue.begin(), currentPlayingPosition));
return std::make_pair(returnValue, iter);
}
int MusicQueue::size() {
std::lock_guard<std::mutex> lock(queueMutex);
return queue.size();
}
std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::end() {
std::lock_guard<std::mutex> lock(queueMutex);
return queue.end();
}
}

View File

@@ -8,19 +8,25 @@ namespace bumbleBee {
std::string SettingsManager::TOKEN = "";
std::string SettingsManager::YTDLP_CMD = "./yt-dlp";
std::string SettingsManager::FFMPEG_CMD = "./ffmpeg/bin/ffmpeg";
std::string SettingsManager::FFMPEG_CMD = "./ffmpeg";
dpp::loglevel SettingsManager::LOGLEVEL = dpp::ll_debug;
bool SettingsManager::REGISTER_COMMAND = false;
bool SettingsManager::validateToken() {
nlohmann::json response;
if (ConsoleUtils::getResultFromCommand("which curl").size() == 0) {
std::string curl = ConsoleUtils::safe_execute_command("/usr/bin/which", {"curl"}).front();
if (curl == "") {
std::cout << "curl is unavaliable. unresolable error please install curl." << std::endl;
return false;
}
std::string stresult = ConsoleUtils::getResultFromCommand("curl -sX GET \"https://discord.com/api/v10/users/@me\" -H \"Authorization: Bot " +
TOKEN + "\"").front();
std::string stresult = ConsoleUtils::safe_execute_command(curl, {
"-sX",
"GET",
"https://discord.com/api/v10/users/@me",
"-H",
"Authorization: Bot " + TOKEN + ""
}).front();
std::stringstream ss(stresult);
ss >> response;

View File

@@ -38,8 +38,17 @@ void AsyncDownloadManager::downloadWorker() {
cluster->log(dpp::ll_info, "AsyncDownloadManager: " + query + " accepted.");
std::queue<std::string> ids =
ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() +
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
ConsoleUtils::safe_execute_command(
SettingsManager::getYTDLP_CMD(), {
"--default-search",
"ytsearch",
"--flat-playlist",
"--skip-download",
"--quiet",
"--ignore-errors",
"--print",
"id",
query});
if (ids.size() >= 2) {
cluster->log(dpp::ll_info, query + " is playlist");
@@ -56,8 +65,13 @@ void AsyncDownloadManager::downloadWorker() {
}
std::queue<std::string> urls =
ConsoleUtils::getResultFromCommand(SettingsManager::getYTDLP_CMD() +
" -f ba* --print urls https://youtu.be/" + ids.front());
ConsoleUtils::safe_execute_command(SettingsManager::getYTDLP_CMD(), {
"-f",
"ba*",
"--print",
"urls",
"https://youtu.be/" + ids.front()
});
cluster->log(dpp::ll_debug, "url: " + urls.front());
@@ -75,8 +89,11 @@ void AsyncDownloadManager::downloadWorker() {
cluster->log(dpp::ll_info, "Thread id: " + tid.str() + ": " + downloadID + " accepted.");
std::string command = std::string("./streamOpus.sh " + SettingsManager::getYTDLP_CMD() + " " + downloadID + " " + SettingsManager::getFFMPEG_CMD());
stream = popen(command.c_str(), "r");
stream = ConsoleUtils::safe_open_pipe("./streamOpus.sh", {
SettingsManager::getYTDLP_CMD(),
downloadID,
SettingsManager::getFFMPEG_CMD()
});
cluster->log(dpp::ll_info, "Thread id: " + tid.str() + " Opened stream: " + downloadID);
});

28
src/Utils/ThreadPool.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include "Utils/ThreadPool.hpp"
namespace bumbleBee {
template <typename FuncRet, typename FuncParam>
ThreadPool<FuncRet, FuncParam>::ThreadPool(std::int32_t threadCount) {
this.threadCount = threadCount;
while (threadCount--) {
threadPool.
}
}
template <typename FuncRet, typename FuncParam>
void ThreadPool<FuncRet, FuncParam>::gracefullAllStop() {
std::unique_lock<std::mutex> lock(mutex_);
for (auto& thread : threadPool_) {
terminating_[thread] = true;
condition_.notify_all();
}
for (auto& thread : threadPool_) {
if (thread.joinable()) {
thread.join();
}
}
threadPool_.clear();
terminating_.clear();
}
}

View File

@@ -2,7 +2,8 @@
#include <BumbleBee.hpp>
#include <thread>
int main() {
int main(int argc, char* argv[]) {
bumbleBee::BumbleBee bot;
bot.start();
return 0;
}

BIN
yt-dlp

Binary file not shown.