mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb6cd89f51 | |||
| 2a238f804d | |||
| ea7d42638e | |||
| 30f97e3dfb | |||
| 17236f32b5 | |||
| 00134ee7b1 | |||
| 52146c1f6a | |||
| bf0268c1e9 | |||
| 2f5185e0c3 | |||
| 96a4096971 | |||
| ec65b550e6 | |||
| 14db2a31e8 | |||
| 1af829c711 | |||
| 46c59d40de | |||
| b08641f87e | |||
| 1ca928c4df | |||
| 2935a844a0 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@ Temp/
|
|||||||
Music
|
Music
|
||||||
*.json
|
*.json
|
||||||
yt-dlp
|
yt-dlp
|
||||||
ffmpeg
|
ffmpeg
|
||||||
|
password
|
||||||
8
BuildDockerAndUpload.sh
Executable file
8
BuildDockerAndUpload.sh
Executable 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
|
||||||
20
Dockerfile
20
Dockerfile
@@ -1 +1,19 @@
|
|||||||
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/
|
||||||
|
RUN dpkg -i dpp.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"]
|
||||||
18
README.md
18
README.md
@@ -1,18 +1,25 @@
|
|||||||
|
|
||||||
# 이게 뭔가요?
|
# 이게 뭔가요?
|
||||||
|
[](https://www.codefactor.io/repository/github/happytanuki/bumblecee)
|
||||||
|
|
||||||
C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악봇입니다!
|
C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악봇입니다!
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<a href="https://github.com/brainboxdotcc/DPP" alt="DPP"> <img src="DPP-markdown-logo.png" /> </a>
|
<a href="https://github.com/brainboxdotcc/DPP" alt="DPP"> <img src="DPP-markdown-logo.png" /> </a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
# 어떻게 써요?
|
# 어떻게 써요?
|
||||||
1. 실행파일 경로에 config.json 파일을 만들고 다음과 같이 입력하세요:
|
1. 실행파일 경로에 config.json 파일을 만들고 다음과 같이 입력하세요:
|
||||||
```
|
```
|
||||||
{"token": "디스코드에서 발급받은 개인 봇 토큰"}
|
{
|
||||||
|
"CLEAR_PREVIOUS_COMMAND": true,
|
||||||
|
"FFMPEG_CMD": "ffmpeg",
|
||||||
|
"LOGLEVEL": "debug",
|
||||||
|
"TOKEN": "발급받은 토큰",
|
||||||
|
"YTDLP_CMD": "./yt-dlp"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
2. Music 디렉터리를 만드세요
|
2. 봇을 초대하시고 사용하시면 됩니다.
|
||||||
3. Music/Archive 파일을 만드세요
|
|
||||||
4. 봇을 실행시키고 초대하셔서 사용하시면 됩니다.
|
|
||||||
|
|
||||||
# 명령어
|
# 명령어
|
||||||
## /p
|
## /p
|
||||||
@@ -36,3 +43,6 @@ C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악
|
|||||||
음성 채팅을 떠납니다.
|
음성 채팅을 떠납니다.
|
||||||
사용법:
|
사용법:
|
||||||
/l
|
/l
|
||||||
|
|
||||||
|
# docker
|
||||||
|
happytanuki12/bumblebee:latest
|
||||||
|
|||||||
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
bumblebee:
|
||||||
|
image: happytanuki12/bumblebee:latest
|
||||||
|
container_name: BumbleBee
|
||||||
|
volumes:
|
||||||
|
- ./config.json:/config.json
|
||||||
|
restart: unless-stopped
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _MUSICPLAYMANAGER_HPP_
|
|
||||||
#define _MUSICPLAYMANAGER_HPP_
|
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <Queue/MusicQueue.hpp>
|
#include <Queue/MusicQueue.hpp>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
@@ -50,10 +48,11 @@ public:
|
|||||||
void setRepeat(const dpp::snowflake guildId, const bool value);
|
void setRepeat(const dpp::snowflake guildId, const bool value);
|
||||||
bool getRepeat(const dpp::snowflake guildId);
|
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);
|
MusicQueueElement getNowPlaying(const dpp::snowflake guildId);
|
||||||
|
|
||||||
std::condition_variable queuedCondition;
|
std::condition_variable queuedCondition;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<dpp::cluster> cluster;
|
std::shared_ptr<dpp::cluster> cluster;
|
||||||
|
|
||||||
@@ -63,7 +62,6 @@ private:
|
|||||||
|
|
||||||
std::unordered_map<dpp::snowflake, std::shared_ptr<std::mutex>> queueEmptyMutex;
|
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
|
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _BUMBLEBEECOMMAND_HPP_
|
|
||||||
#define _BUMBLEBEECOMMAND_HPP_
|
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <Audio/MusicPlayManager.hpp>
|
#include <Audio/MusicPlayManager.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -25,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;
|
||||||
@@ -53,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; \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +66,4 @@ _DECLARE_BUMBLEBEE_COMMAND(Play, p, "노래 재생")
|
|||||||
_DECLARE_BUMBLEBEE_COMMAND(Queue, q, "노래 예약 큐를 확인합니다")
|
_DECLARE_BUMBLEBEE_COMMAND(Queue, q, "노래 예약 큐를 확인합니다")
|
||||||
_DECLARE_BUMBLEBEE_COMMAND(Repeat, r, "반복을 켜거나 끕니다")
|
_DECLARE_BUMBLEBEE_COMMAND(Repeat, r, "반복을 켜거나 끕니다")
|
||||||
_DECLARE_BUMBLEBEE_COMMAND(Skip, s, "현재 재생중인 곡을 스킵합니다")
|
_DECLARE_BUMBLEBEE_COMMAND(Skip, s, "현재 재생중인 곡을 스킵합니다")
|
||||||
_DECLARE_BUMBLEBEE_COMMAND(Shuffle, shuffle, "큐를 섞습니다")
|
_DECLARE_BUMBLEBEE_COMMAND(Shuffle, shuffle, "큐를 섞습니다")
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _MUSICQUEUE_HPP_
|
|
||||||
#define _MUSICQUEUE_HPP_
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
@@ -17,25 +15,37 @@ 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::list<std::shared_ptr<MusicQueueElement>> getQueueCopy();
|
nowplaying();
|
||||||
int size();
|
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;
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _MUSICQUEUEELEMENT_HPP_
|
|
||||||
#define _MUSICQUEUEELEMENT_HPP_
|
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
|
|
||||||
namespace bumbleBee {
|
namespace bumbleBee {
|
||||||
@@ -19,5 +17,4 @@ public:
|
|||||||
const dpp::user issuingUser;
|
const dpp::user issuingUser;
|
||||||
const dpp::embed embed;
|
const dpp::embed embed;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _SETTINGSMANAGER_HPP_
|
|
||||||
#define _SETTINGSMANAGER_HPP_
|
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
|
|
||||||
#define _DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(type, name, Name)\
|
#define _DECLARE_DEFAULT_ACCESSER_STATIC_VARIABLE(type, name, Name)\
|
||||||
@@ -33,5 +31,4 @@ public:
|
|||||||
/// @return 유효한 토큰이면 true, 아니면 false를 반환합니다.
|
/// @return 유효한 토큰이면 true, 아니면 false를 반환합니다.
|
||||||
static bool validateToken();
|
static bool validateToken();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _ASYNCDOWNLOADMANAGER_HPP_
|
|
||||||
#define _ASYNCDOWNLOADMANAGER_HPP_
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -55,6 +53,4 @@ private:
|
|||||||
std::vector<std::thread> worker_thread;
|
std::vector<std::thread> worker_thread;
|
||||||
bool terminate;
|
bool terminate;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _CONSOLEUTILS_HPP_
|
|
||||||
#define _CONSOLEUTILS_HPP_
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -35,6 +33,4 @@ public:
|
|||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
77
include/Utils/QueuedMusicListEmbedProvider.hpp
Normal file
77
include/Utils/QueuedMusicListEmbedProvider.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _VERSIONCHECKUTILS_HPP_
|
|
||||||
#define _VERSIONCHECKUTILS_HPP_
|
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include "ConsoleUtils.hpp"
|
#include "ConsoleUtils.hpp"
|
||||||
#include "../Settings/SettingsManager.hpp"
|
#include "../Settings/SettingsManager.hpp"
|
||||||
@@ -17,8 +15,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validateYTDLPFFMPEGBinary(std::shared_ptr<dpp::cluster> cluster) {
|
static void validateFFMPEG(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();
|
std::string front = result.front();
|
||||||
if (front[0] != 'f' ||
|
if (front[0] != '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("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("tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||||
system("rm ffmpeg-master-latest-linux64-gpl.tar.xz");
|
system("rm ffmpeg-master-latest-linux64-gpl.tar.xz");
|
||||||
system("mv ffmpeg-master-latest-linux64-gpl ffmpeg");
|
system("mv ffmpeg-master-latest-linux64-gpl/bin/ffmpeg .");
|
||||||
SettingsManager::setFFMPEG_CMD("./ffmpeg/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::getResultFromCommand(SettingsManager::getYTDLP_CMD() + " --version");
|
||||||
|
std::string front = result.front();
|
||||||
if ((front[0]-'0' < 0 || front[0]-'0' > 9) ||
|
if ((front[0]-'0' < 0 || front[0]-'0' > 9) ||
|
||||||
(front[1]-'0' < 0 || front[1]-'0' > 9) ||
|
(front[1]-'0' < 0 || front[1]-'0' > 9) ||
|
||||||
(front[2]-'0' < 0 || front[2]-'0' > 9) ||
|
(front[2]-'0' < 0 || front[2]-'0' > 9) ||
|
||||||
@@ -63,6 +64,12 @@ 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) {
|
static void updateytdlp(std::shared_ptr<dpp::cluster> cluster) {
|
||||||
cluster->log(dpp::ll_info, "Checking if yt-dlp update is available...");
|
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::getResultFromCommand("./yt-dlp -U");
|
||||||
@@ -73,5 +80,4 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <ogg/ogg.h>
|
#include <ogg/ogg.h>
|
||||||
#include <oggz/oggz.h>
|
#include <oggz/oggz.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <Settings/SettingsManager.hpp>
|
||||||
|
|
||||||
namespace bumbleBee {
|
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) {
|
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();
|
||||||
play(event.voice_client);
|
play(event.voice_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayManager::on_voice_client_disconnect(const dpp::voice_client_disconnect_t& event) { // 안 불리는 듯?
|
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;
|
// dpp::snowflake gid = dpp::find_channel(event.voice_client->channel_id)->guild_id;
|
||||||
event.voice_client->stop_audio();
|
// event.voice_client->stop_audio();
|
||||||
queueMap[gid]->clear();
|
// queueMap[gid]->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayManager::play(dpp::discord_voice_client* client) {
|
void MusicPlayManager::play(dpp::discord_voice_client* client) {
|
||||||
std::thread t([&](dpp::discord_voice_client* client){
|
std::thread t([&](dpp::discord_voice_client* client){
|
||||||
dpp::snowflake gid = dpp::find_channel(client->channel_id)->guild_id;
|
dpp::snowflake gid = dpp::find_channel(client->channel_id)->guild_id;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> queueEmptyLock(*queueEmptyMutex[gid]);
|
std::unique_lock<std::mutex> queueEmptyLock(*queueEmptyMutex[gid]);
|
||||||
queuedCondition.wait(queueEmptyLock, [&]{ return queueMap[gid]->size() != 0; });
|
|
||||||
|
|
||||||
auto np = queueMap[gid]->next_music();
|
queuedCondition.wait(queueEmptyLock, [&]{
|
||||||
auto music = **np;
|
return queueMap[gid]->size() != 0 && queueMap[gid]->currentPlayingPosition != queueMap[gid]->end();
|
||||||
send_audio_to_voice(music, client);
|
});
|
||||||
|
|
||||||
|
auto next = queueMap[gid]->currentPlayingPosition;
|
||||||
|
send_audio_to_voice(*next, client);
|
||||||
}, client);
|
}, client);
|
||||||
t.detach();
|
t.detach();
|
||||||
}
|
}
|
||||||
@@ -68,58 +72,67 @@ bool MusicPlayManager::getRepeat(const dpp::snowflake guildId) {
|
|||||||
return queueMap[guildId]->repeat;
|
return queueMap[guildId]->repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<MusicQueueElement> MusicPlayManager::getQueue(const dpp::snowflake guildId){
|
std::pair<std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>>, std::list<std::shared_ptr<MusicQueueElement>>::iterator>
|
||||||
std::list<std::shared_ptr<MusicQueueElement>> queue = queueMap[guildId]->getQueueCopy();
|
MusicPlayManager::getQueue(const dpp::snowflake guildId){
|
||||||
std::list<MusicQueueElement> returnValue;
|
auto returnValue = queueMap[guildId]->getQueueCopy();
|
||||||
|
|
||||||
for (auto iter = queue.begin(); iter != queue.end(); iter++)
|
|
||||||
returnValue.push_back(**iter);
|
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId) {
|
MusicQueueElement MusicPlayManager::getNowPlaying(const dpp::snowflake guildId) {
|
||||||
std::shared_ptr<MusicQueueElement> nowplaying = queueMap[guildId]->nowplaying();
|
std::shared_ptr<MusicQueueElement> nowplaying = queueMap[guildId]->nowplaying();
|
||||||
|
if (nowplaying == nullptr)
|
||||||
|
return MusicQueueElement("", "", dpp::user(), dpp::embed());
|
||||||
MusicQueueElement returnValue(*nowplaying);
|
MusicQueueElement returnValue(*nowplaying);
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayManager::send_audio_to_voice(const 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 ./yt-dlp ffmpeg https://youtu.be/";
|
std::thread t([](std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client) {
|
||||||
command += music.id;
|
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(
|
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) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ BumbleBee::BumbleBee() {
|
|||||||
|
|
||||||
cluster->on_log([](const dpp::log_t& event) {
|
cluster->on_log([](const dpp::log_t& event) {
|
||||||
if (event.severity >= SettingsManager::getLOGLEVEL()) {
|
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);});
|
cluster->on_slashcommand([this](const dpp::slashcommand_t& event){on_slashcommand(event);});
|
||||||
|
|||||||
@@ -3,17 +3,10 @@
|
|||||||
|
|
||||||
namespace bumbleBee::commands {
|
namespace bumbleBee::commands {
|
||||||
void Delete::execute(const dpp::slashcommand_t &event) {
|
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"));
|
int pos = std::get<std::int64_t>(event.get_parameter("pos"));
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
#include <Commands/BumbleBeeCommand.hpp>
|
#include <Commands/BumbleBeeCommand.hpp>
|
||||||
|
|
||||||
namespace bumbleBee::commands {
|
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);
|
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
||||||
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||||
|
event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
musicManager->clear(event.command.guild_id);
|
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.from->disconnect_voice(event.command.guild_id);
|
||||||
|
|
||||||
event.edit_original_response(dpp::message("음성 채팅방을 떠납니다!"));
|
event.edit_original_response(dpp::message("음성 채팅방을 떠납니다!"));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <Utils/ConsoleUtils.hpp>
|
#include <Utils/ConsoleUtils.hpp>
|
||||||
#include <Settings/SettingsManager.hpp>
|
#include <Settings/SettingsManager.hpp>
|
||||||
#include <dpp/nlohmann/json.hpp>
|
#include <dpp/nlohmann/json.hpp>
|
||||||
|
#include <Utils/QueuedMusicListEmbedProvider.hpp>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace bumbleBee::commands {
|
namespace bumbleBee::commands {
|
||||||
@@ -22,8 +23,12 @@ namespace bumbleBee::commands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string query = std::get<std::string>(event.get_parameter("query"));
|
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::getResultFromCommand(
|
||||||
|
SettingsManager::getYTDLP_CMD() +
|
||||||
|
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors --print id " + query);
|
||||||
|
|
||||||
std::queue<std::shared_ptr<MusicQueueElement>> musics;
|
std::queue<std::shared_ptr<MusicQueueElement>> musics;
|
||||||
|
|
||||||
@@ -36,60 +41,14 @@ namespace bumbleBee::commands {
|
|||||||
else
|
else
|
||||||
msg.content = "큐에 다음 곡을 추가했습니다:";
|
msg.content = "큐에 다음 곡을 추가했습니다:";
|
||||||
|
|
||||||
if (ids.size() >= 2) {
|
if (!ids.empty()) {
|
||||||
event.from->creator->log(dpp::ll_info, "Playlist detected.");
|
if (ids.front() == "") {
|
||||||
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));
|
|
||||||
ids.pop();
|
ids.pop();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!ids.empty()) {
|
FILE* file = popen((SettingsManager::getYTDLP_CMD() +
|
||||||
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");
|
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors -J http://youtu.be/" + ids.front()).c_str(), "r");
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
size_t bytesRead;
|
size_t bytesRead;
|
||||||
@@ -97,20 +56,25 @@ namespace bumbleBee::commands {
|
|||||||
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||||
oss.write(buffer, bytesRead);
|
oss.write(buffer, bytesRead);
|
||||||
}
|
}
|
||||||
fclose(file);
|
pclose(file);
|
||||||
|
|
||||||
std::istringstream iss(oss.str());
|
std::istringstream iss(oss.str());
|
||||||
nlohmann::json videoDataJson;
|
nlohmann::json videoDataJson;
|
||||||
iss >> videoDataJson;
|
iss >> videoDataJson;
|
||||||
|
|
||||||
time_t SongLength = int(videoDataJson["duration"]);
|
time_t SongLength = int(videoDataJson["duration"]);
|
||||||
char SongLengthStr[10];
|
char SongLengthStr[13];
|
||||||
tm t;
|
tm t;
|
||||||
t.tm_mday = SongLength / 86400;
|
t.tm_mday = SongLength / 86400;
|
||||||
t.tm_hour = (SongLength % 86400)/3600;
|
t.tm_hour = (SongLength % 86400)/3600;
|
||||||
t.tm_min = (SongLength % 3600)/60;
|
t.tm_min = (SongLength % 3600)/60;
|
||||||
t.tm_sec = SongLength%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()
|
dpp::embed embed = dpp::embed()
|
||||||
.set_color(dpp::colors::sti_blue)
|
.set_color(dpp::colors::sti_blue)
|
||||||
@@ -125,39 +89,141 @@ namespace bumbleBee::commands {
|
|||||||
);
|
);
|
||||||
|
|
||||||
musics.push(std::make_shared<MusicQueueElement>(ids.front(), query, event.command.usr, embed));
|
musics.push(std::make_shared<MusicQueueElement>(ids.front(), query, event.command.usr, embed));
|
||||||
|
ids.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (musics.size() == 1) {
|
if (!ids.empty()) {
|
||||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
|
std::thread t([](
|
||||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
std::queue<std::string> ids,
|
||||||
msg.add_embed(musics.front()->embed);
|
dpp::snowflake guildId,
|
||||||
musics.pop();
|
dpp::snowflake channelId,
|
||||||
|
std::string query,
|
||||||
event.edit_original_response(msg);
|
dpp::user user,
|
||||||
musicManager->queuedCondition.notify_all();
|
dpp::cluster* cluster,
|
||||||
|
std::shared_ptr<MusicPlayManager> manager
|
||||||
|
) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
pclose(file);
|
||||||
|
|
||||||
|
std::istringstream iss(oss.str());
|
||||||
|
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());
|
musicManager->queue_music(event.command.guild_id, musics.front());
|
||||||
msg.add_embed(musics.front()->embed);
|
msg.add_embed(musics.front()->embed);
|
||||||
musics.pop();
|
musics.pop();
|
||||||
|
|
||||||
event.edit_original_response(msg);
|
event.edit_original_response(msg);
|
||||||
musicManager->queuedCondition.notify_all();
|
musicManager->queuedCondition.notify_all();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg.content = "검색 결과가 없습니다";
|
||||||
|
event.edit_original_response(msg);
|
||||||
|
}
|
||||||
|
|
||||||
while (!musics.empty()) {
|
if (musicManager->getNowPlaying(event.command.guild_id).id == "") {
|
||||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->id);
|
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
||||||
dpp::message followMsg(event.command.channel_id, "");
|
|
||||||
|
|
||||||
followMsg.add_embed(musics.front()->embed);
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||||
event.from->creator->message_create(followMsg); // 어차피 원래 메시지를 지정해서 수정할 것이기 때문에 먼저 팔로잉 메시지를 작성해도 상관없음.
|
event.edit_original_response(dpp::message("현재 음성 채팅방에 있는 상태가 아닙니다!"));
|
||||||
|
return;
|
||||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
|
||||||
musics.pop();
|
|
||||||
}
|
}
|
||||||
}
|
v->voiceclient->insert_marker();
|
||||||
else { // ??
|
v->voiceclient->pause_audio(false);
|
||||||
event.from->creator->log(dpp::ll_error, "??? not queueed any music");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,71 @@
|
|||||||
#include <Commands/BumbleBeeCommand.hpp>
|
#include <Commands/BumbleBeeCommand.hpp>
|
||||||
|
#include <Utils/QueuedMusicListEmbedProvider.hpp>
|
||||||
|
|
||||||
namespace bumbleBee::commands {
|
namespace bumbleBee::commands {
|
||||||
void Queue::execute(const dpp::slashcommand_t &event) {
|
void Queue::execute(const dpp::slashcommand_t &event) {
|
||||||
auto queue = musicManager->getQueue(event.command.guild_id);
|
auto queue = musicManager->getQueue(event.command.guild_id);
|
||||||
auto nowplaying = musicManager->getNowPlaying(event.command.guild_id);
|
|
||||||
|
|
||||||
dpp::message msg;
|
dpp::message msg;
|
||||||
dpp::embed embed;
|
dpp::embed embed;
|
||||||
|
|
||||||
if (queue.size() == 0) {
|
auto queued = QueuedMusicListEmbedProvider::makeEmbed(queue.first, queue.second, musicManager->getRepeat(event.command.guild_id));
|
||||||
embed
|
|
||||||
.set_title("큐가 비었습니다!")
|
// if (queue.first.size() == 0) {
|
||||||
.set_timestamp(time(0));
|
// msg.add_embed(queued.front());
|
||||||
msg.add_embed(embed);
|
// 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);
|
event.edit_original_response(msg);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
msg.content = "지금 재생 중:";
|
else {
|
||||||
msg.add_embed(nowplaying.embed);
|
msg.content = "재생 중인 노래가 없습니다";
|
||||||
|
event.edit_original_response(msg);
|
||||||
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); // 어차피 원래 메시지를 지정해서 수정할 것이기 때문에 먼저 팔로잉 메시지를 작성해도 상관없음.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
void Queue::init() {
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ namespace bumbleBee::commands {
|
|||||||
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
||||||
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||||
|
event.edit_original_response(dpp::message("스킵하려면 음악을 재생중이어야 합니다!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v->voiceclient->pause_audio(true);
|
|
||||||
v->voiceclient->stop_audio();
|
v->voiceclient->stop_audio();
|
||||||
v->voiceclient->pause_audio(false);
|
v->voiceclient->insert_marker();
|
||||||
v->voiceclient->insert_marker("end");
|
|
||||||
|
|
||||||
event.edit_original_response(dpp::message("스킵했습니다!"));
|
event.edit_original_response(dpp::message("스킵했습니다!"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <Queue/MusicQueue.hpp>
|
#include <Queue/MusicQueue.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <Utils/QueuedMusicListEmbedProvider.hpp>
|
||||||
|
|
||||||
namespace bumbleBee {
|
namespace bumbleBee {
|
||||||
|
|
||||||
@@ -36,14 +37,19 @@ std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::findByIndex(
|
|||||||
}
|
}
|
||||||
std::shared_ptr<MusicQueueElement> MusicQueue::nowplaying() {
|
std::shared_ptr<MusicQueueElement> MusicQueue::nowplaying() {
|
||||||
std::lock_guard<std::mutex> lock(queueMutex);
|
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::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)
|
|
||||||
return queue.end();
|
|
||||||
if (currentPlayingPosition == --queue.end() && repeat)
|
if (currentPlayingPosition == --queue.end() && repeat)
|
||||||
currentPlayingPosition = queue.begin();
|
currentPlayingPosition = queue.begin();
|
||||||
|
else if (currentPlayingPosition == --queue.end() && !repeat) // 반복이 꺼져있을 때 큐 재생이 끝난 경우
|
||||||
|
currentPlayingPosition = queue.end();
|
||||||
|
else if (currentPlayingPosition == queue.end() && !repeat) // 반복이 꺼져있고 현재 재생 곡이 없는데 새 곡이 들어왔을 경우
|
||||||
|
currentPlayingPosition = --queue.end();
|
||||||
else
|
else
|
||||||
++currentPlayingPosition;
|
++currentPlayingPosition;
|
||||||
return currentPlayingPosition;
|
return currentPlayingPosition;
|
||||||
@@ -82,16 +88,28 @@ std::shared_ptr<MusicQueueElement> MusicQueue::erase(std::list<std::shared_ptr<M
|
|||||||
return removedValue;
|
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::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() {
|
int MusicQueue::size() {
|
||||||
std::lock_guard<std::mutex> lock(queueMutex);
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
return queue.size();
|
return queue.size();
|
||||||
}
|
}
|
||||||
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator MusicQueue::end() {
|
||||||
|
std::lock_guard<std::mutex> lock(queueMutex);
|
||||||
|
return queue.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace bumbleBee {
|
|||||||
|
|
||||||
std::string SettingsManager::TOKEN = "";
|
std::string SettingsManager::TOKEN = "";
|
||||||
std::string SettingsManager::YTDLP_CMD = "./yt-dlp";
|
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;
|
dpp::loglevel SettingsManager::LOGLEVEL = dpp::ll_debug;
|
||||||
bool SettingsManager::REGISTER_COMMAND = false;
|
bool SettingsManager::REGISTER_COMMAND = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user