mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
Compare commits
1 Commits
experiment
...
stable
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f2d1a57e7 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,7 +1,7 @@
|
|||||||
build/*
|
build/
|
||||||
out/
|
out/
|
||||||
.vs/
|
.vs/
|
||||||
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
tmp/
|
tmp/
|
||||||
config.json
|
config.json
|
||||||
Music
|
|
||||||
21
.vscode/c_cpp_properties.json
vendored
21
.vscode/c_cpp_properties.json
vendored
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"DDPP_CORO=on"
|
|
||||||
],
|
|
||||||
"compilerPath": "/usr/bin/gcc",
|
|
||||||
"cStandard": "c17",
|
|
||||||
"cppStandard": "c++20",
|
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
|
||||||
"compilerArgs": [
|
|
||||||
"-DDPP_CORO"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -73,8 +73,6 @@
|
|||||||
"cinttypes": "cpp",
|
"cinttypes": "cpp",
|
||||||
"bitset": "cpp",
|
"bitset": "cpp",
|
||||||
"set": "cpp",
|
"set": "cpp",
|
||||||
"regex": "cpp",
|
"regex": "cpp"
|
||||||
"format": "cpp",
|
|
||||||
"span": "cpp"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,13 +13,10 @@ string(ASCII 27 Esc)
|
|||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
set_target_properties(${BOT_NAME} PROPERTIES
|
set_target_properties(${BOT_NAME} PROPERTIES
|
||||||
CXX_STANDARD 20
|
CXX_STANDARD 17
|
||||||
CXX_STANDARD_REQUIRED ON
|
CXX_STANDARD_REQUIRED ON
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(${BOT_NAME} PUBLIC DPP_CORO)
|
|
||||||
target_compile_features(${BOT_NAME} PUBLIC cxx_std_20)
|
|
||||||
|
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(DPP)
|
find_package(DPP)
|
||||||
@@ -44,8 +41,9 @@ target_link_libraries(${BOT_NAME}
|
|||||||
dl
|
dl
|
||||||
dpp
|
dpp
|
||||||
opus
|
opus
|
||||||
|
opusfile
|
||||||
|
ogg
|
||||||
oggz
|
oggz
|
||||||
mariadbcpp
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${OPENSSL_CRYPTO_LIBRARY}
|
${OPENSSL_CRYPTO_LIBRARY}
|
||||||
${OPENSSL_SSL_LIBRARY}
|
${OPENSSL_SSL_LIBRARY}
|
||||||
@@ -78,3 +76,5 @@ else()
|
|||||||
|
|
||||||
target_link_libraries(${BOT_NAME} dpp)
|
target_link_libraries(${BOT_NAME} dpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "-g")
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.6 KiB |
38
README.md
38
README.md
@@ -1,38 +0,0 @@
|
|||||||
|
|
||||||
# 이게 뭔가요?
|
|
||||||
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": "디스코드에서 발급받은 개인 봇 토큰"}
|
|
||||||
```
|
|
||||||
2. Music 디렉터리를 만드세요
|
|
||||||
3. Music/Archive 파일을 만드세요
|
|
||||||
4. 봇을 실행시키고 초대하셔서 사용하시면 됩니다.
|
|
||||||
|
|
||||||
# 명령어
|
|
||||||
## /p
|
|
||||||
노래를 예약합니다.
|
|
||||||
사용법:
|
|
||||||
/p (노래링크 또는 노래 제목)
|
|
||||||
## /q
|
|
||||||
현재 큐의 내용물을 확인합니다.
|
|
||||||
사용법:
|
|
||||||
/q
|
|
||||||
## /d
|
|
||||||
현재 큐의 내용물을 삭제합니다.
|
|
||||||
현재 재생중인 곡은 0번입니다.
|
|
||||||
사용법:
|
|
||||||
/d (큐의 노래번호)
|
|
||||||
## /s
|
|
||||||
현재 곡을 스킵합니다.
|
|
||||||
사용법:
|
|
||||||
/s
|
|
||||||
## /l
|
|
||||||
음성 채팅을 떠납니다.
|
|
||||||
사용법:
|
|
||||||
/l
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
W8UNLOOogU4
|
|
||||||
749DIRUHhNY
|
|
||||||
o75PUTiHEXU
|
|
||||||
pS5d77DQHOI
|
|
||||||
65xX7zyr-fA
|
|
||||||
2eNEQ0cQtkI
|
|
||||||
UgS7vgquBvo
|
|
||||||
IFCDLIKSArs
|
|
||||||
yPdqcADl5U4
|
|
||||||
6aEglYFwjrA
|
|
||||||
n8F-E5f-cos
|
|
||||||
1zwaZkOXXqw
|
|
||||||
vjSrFwbwu6w
|
|
||||||
vwZAqxL8rgs
|
|
||||||
zOkIe3RcTCs
|
|
||||||
mzVbYUBo8_Y
|
|
||||||
rgNdeflYdYw
|
|
||||||
CjaM8qWzssk
|
|
||||||
kNDbaYEp0tU
|
|
||||||
smObR_8q5UQ
|
|
||||||
27NtZwyog7g
|
|
||||||
vHfAjfKVMew
|
|
||||||
b_bjtIeqIR4
|
|
||||||
YTaX7BWlk9g
|
|
||||||
BBj3SCImk_A
|
|
||||||
Yb_IhN4TGp8
|
|
||||||
-m-crWZHLi0
|
|
||||||
4ciZKNHSoUs
|
|
||||||
4tlUwgtgdZA
|
|
||||||
oPGtAA2HaS8
|
|
||||||
dLlD-dZNACM
|
|
||||||
9LW9DpmhrPE
|
|
||||||
pMTRBNMX2mw
|
|
||||||
Kt451YtL-Vs
|
|
||||||
tc0FL9JROGQ
|
|
||||||
NinLIDs9qmU
|
|
||||||
KMdTrqzEI0I
|
|
||||||
HbXaUmWaU5Q
|
|
||||||
xtFAmapbTbY
|
|
||||||
B7luArOaIl0
|
|
||||||
HMqhXxH5-RQ
|
|
||||||
mQFokUq9LYs
|
|
||||||
HyL8Z94W6es
|
|
||||||
prAnOH-q_Bo
|
|
||||||
LRPGqNeav_M
|
|
||||||
M4-XU0a2hf0
|
|
||||||
BryspbM6s3E
|
|
||||||
JVTS3fyoAEQ
|
|
||||||
KAaUyVJoNAE
|
|
||||||
@@ -2,26 +2,15 @@
|
|||||||
#include <Commands/CommandType.hpp>
|
#include <Commands/CommandType.hpp>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mariadb/conncpp.hpp>
|
|
||||||
|
|
||||||
class IBot {
|
class IBot {
|
||||||
public:
|
public:
|
||||||
IBot(std::string token, int clusterCount = 0);
|
IBot(std::string token, int totalShard);
|
||||||
virtual void start();
|
void start();
|
||||||
virtual void onCommand(const dpp::slashcommand_t &event);
|
void onCommand(const dpp::slashcommand_t &event);
|
||||||
virtual void onReady(const dpp::ready_t &event);
|
void onReady(const dpp::ready_t &event);
|
||||||
|
|
||||||
std::shared_ptr<dpp::cluster> botCluster;
|
std::shared_ptr<dpp::cluster> botCluster;
|
||||||
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
|
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
|
||||||
|
protected:
|
||||||
std::function<void(const dpp::log_t&)> logger() {
|
|
||||||
return [&](const dpp::log_t& event){
|
|
||||||
if (event.severity >= dpp::ll_error)
|
|
||||||
std::cerr << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
|
|
||||||
else if (event.severity - logLevel >= 0)
|
|
||||||
std::clog << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
dpp::loglevel logLevel = dpp::ll_debug;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,37 +2,14 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <Bot.hpp>
|
#include <Bot.hpp>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
|
#include <MusicQueue.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <FQueueElement.hpp>
|
|
||||||
|
|
||||||
class BumbleCeepp : public IBot {
|
class BumbleCeepp : public IBot {
|
||||||
public:
|
public:
|
||||||
BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount = 0);
|
BumbleCeepp(std::string token, int totalShard);
|
||||||
~BumbleCeepp();
|
|
||||||
|
|
||||||
void enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc);
|
|
||||||
std::shared_ptr<dpp::embed> findEmbed(std::string musicID);
|
|
||||||
bool insertDB(
|
|
||||||
std::string webpage_url,
|
|
||||||
std::string title,
|
|
||||||
std::string uploader,
|
|
||||||
std::string id,
|
|
||||||
std::string thumbnail,
|
|
||||||
time_t duration);
|
|
||||||
std::shared_ptr<dpp::embed> makeEmbed(
|
|
||||||
std::string webpage_url,
|
|
||||||
std::string title,
|
|
||||||
std::string uploader,
|
|
||||||
std::string id,
|
|
||||||
std::string thumbnail,
|
|
||||||
time_t duration);
|
|
||||||
|
|
||||||
bool repeat;
|
|
||||||
std::string nowPlayingMusic;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//<guild_id, queueMutex> 쌍임.
|
//<guild_id, queue> 쌍임.
|
||||||
std::unordered_map<dpp::snowflake, std::mutex> enqueuingMutexMap;
|
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> queueMap;
|
||||||
sql::Connection* conn;
|
|
||||||
};
|
};
|
||||||
@@ -2,21 +2,28 @@
|
|||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <MusicQueue.hpp>
|
||||||
class BumbleCeepp;
|
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class ICommand {
|
class ICommand {
|
||||||
public:
|
public:
|
||||||
ICommand(dpp::snowflake botID, BumbleCeepp* Bot)
|
//이 생성자를 명시적으로 호출할 것.
|
||||||
{
|
ICommand(std::shared_ptr<dpp::cluster> botCluster);
|
||||||
this->botID = botID;
|
|
||||||
this->Bot = Bot;
|
|
||||||
}
|
|
||||||
virtual void operator()(const dpp::slashcommand_t &event) = 0;
|
virtual void operator()(const dpp::slashcommand_t &event) = 0;
|
||||||
|
|
||||||
std::vector<dpp::slashcommand> commandObjectVector;
|
std::vector<dpp::slashcommand> commandObjectVector;
|
||||||
dpp::snowflake botID;
|
protected:
|
||||||
BumbleCeepp* Bot;
|
std::shared_ptr<dpp::cluster> botCluster;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace commands {
|
||||||
|
class VCCommand : public ICommand {
|
||||||
|
public:
|
||||||
|
VCCommand(std::shared_ptr<dpp::cluster> botCluster) : ICommand(botCluster) {}
|
||||||
|
|
||||||
|
std::shared_ptr<MusicQueue> getQueue(const dpp::slashcommand_t& event);
|
||||||
|
protected:
|
||||||
|
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Delete : public ICommand {
|
class Delete : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Delete(dpp::snowflake botID, BumbleCeepp* Bot);
|
Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Leave : public ICommand {
|
class Leave : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Leave(dpp::snowflake botID, BumbleCeepp* Bot);
|
Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Play : public ICommand {
|
class Play : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Play(dpp::snowflake botID, BumbleCeepp* Bot);
|
Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
void on_DLCompleted(std::string musicID, dpp::embed embed, const dpp::slashcommand_t& event);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Queue : public ICommand {
|
class Queue : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Queue(dpp::snowflake botID, BumbleCeepp* Bot);
|
Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Repeat : public ICommand {
|
class Repeat : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Repeat(dpp::snowflake botID, BumbleCeepp* Bot);
|
Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace commands {
|
namespace commands {
|
||||||
class Skip : public ICommand {
|
class Skip : public VCCommand {
|
||||||
public:
|
public:
|
||||||
Skip(dpp::snowflake botID, BumbleCeepp* Bot);
|
Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
|
||||||
|
|
||||||
void operator()(const dpp::slashcommand_t& event);
|
void operator()(const dpp::slashcommand_t& event);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
|
|
||||||
struct FQueueElement {
|
struct FQueueElement {
|
||||||
std::string ID;
|
std::string URL;
|
||||||
|
std::string title;
|
||||||
|
std::string description;
|
||||||
|
std::string fileName;
|
||||||
|
std::string thumbnail;
|
||||||
|
std::string duration;
|
||||||
dpp::embed embed;
|
dpp::embed embed;
|
||||||
bool skip = false;
|
|
||||||
};
|
};
|
||||||
33
include/MusicQueue.hpp
Normal file
33
include/MusicQueue.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <list>
|
||||||
|
#include <FQueueElement.hpp>
|
||||||
|
|
||||||
|
struct FMusicQueueID {
|
||||||
|
dpp::snowflake guild_id;
|
||||||
|
uint32_t shard_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MusicQueue {
|
||||||
|
public:
|
||||||
|
MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster);
|
||||||
|
void operator+=(FQueueElement operand);
|
||||||
|
FQueueElement pop(int index);
|
||||||
|
FQueueElement peek(int index);
|
||||||
|
bool empty();
|
||||||
|
void clear();
|
||||||
|
std::list<struct FQueueElement>::iterator begin();
|
||||||
|
std::list<struct FQueueElement>::iterator end();
|
||||||
|
std::size_t size();
|
||||||
|
FMusicQueueID getId();
|
||||||
|
void play();
|
||||||
|
|
||||||
|
void markerCallback();
|
||||||
|
|
||||||
|
bool repeat;
|
||||||
|
private:
|
||||||
|
std::list<struct FQueueElement> queue;
|
||||||
|
std::mutex mutex;
|
||||||
|
std::mutex playMutex;
|
||||||
|
FMusicQueueID id;
|
||||||
|
std::shared_ptr<dpp::cluster> botCluster;
|
||||||
|
};
|
||||||
31
src/Bot.cpp
31
src/Bot.cpp
@@ -1,22 +1,25 @@
|
|||||||
#include <Bot.hpp>
|
#include <Bot.hpp>
|
||||||
#include <Commands/CommandType.hpp>
|
#include <Commands/CommandType.hpp>
|
||||||
|
|
||||||
IBot::IBot(std::string token, int clusterCount)
|
IBot::IBot(std::string token, int totalShard)
|
||||||
{
|
{
|
||||||
botCluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents, clusterCount);
|
botCluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents, totalShard);
|
||||||
|
botCluster->on_log(dpp::utility::cout_logger());
|
||||||
|
|
||||||
botCluster->on_log(logger());
|
botCluster->on_slashcommand([this](const dpp::slashcommand_t& event){onCommand(event);});
|
||||||
botCluster->on_slashcommand([&](const dpp::slashcommand_t& event){onCommand(event);});
|
botCluster->on_ready([this](const dpp::ready_t &event){onReady(event);});
|
||||||
botCluster->on_ready([&](const dpp::ready_t &event){onReady(event);});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IBot::onCommand(const dpp::slashcommand_t &event)
|
void IBot::onCommand(const dpp::slashcommand_t &event)
|
||||||
{
|
{
|
||||||
auto _event = event;
|
auto _event = event;
|
||||||
for (auto command : commandsArray)
|
for (int i = 0; i < commandsArray.size(); i++) {
|
||||||
for (auto alias : command->commandObjectVector)
|
for (auto alias : commandsArray[i]->commandObjectVector) {
|
||||||
if (event.command.get_command_name() == alias.name)
|
if (event.command.get_command_name() == alias.name) {
|
||||||
(*command)(_event);
|
(*commandsArray[i])(_event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IBot::onReady(const dpp::ready_t &event)
|
void IBot::onReady(const dpp::ready_t &event)
|
||||||
@@ -26,11 +29,11 @@ void IBot::onReady(const dpp::ready_t &event)
|
|||||||
|
|
||||||
//BotCluster->global_bulk_command_delete();
|
//BotCluster->global_bulk_command_delete();
|
||||||
|
|
||||||
for (auto command : commandsArray)
|
for (int i = 0; i < commandsArray.size(); i++) {
|
||||||
for (auto alias : command->commandObjectVector)
|
for (auto Alias : commandsArray[i]->commandObjectVector) {
|
||||||
botCluster->global_command_create(alias);
|
botCluster->global_command_create(Alias);
|
||||||
|
}
|
||||||
botCluster->log(dpp::loglevel::ll_info, "Command added to all clusters.");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IBot::start()
|
void IBot::start()
|
||||||
|
|||||||
@@ -2,244 +2,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <FQueueElement.hpp>
|
#include <FQueueElement.hpp>
|
||||||
#include <Commands/Commands.hpp>
|
#include <Commands/Commands.hpp>
|
||||||
#include <oggz/oggz.h>
|
|
||||||
|
|
||||||
BumbleCeepp::BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount)
|
BumbleCeepp::BumbleCeepp(std::string token, int totalShard)
|
||||||
: IBot(token, clusterCount)
|
: IBot(token, totalShard)
|
||||||
{
|
{
|
||||||
sql::Properties pro({
|
commandsArray.push_back(std::make_shared<commands::Play>(botCluster, &queueMap));
|
||||||
{"user", DBID},
|
commandsArray.push_back(std::make_shared<commands::Repeat>(botCluster, &queueMap));
|
||||||
{"password", DBPassword}
|
commandsArray.push_back(std::make_shared<commands::Queue>(botCluster, &queueMap));
|
||||||
});
|
commandsArray.push_back(std::make_shared<commands::Skip>(botCluster, &queueMap));
|
||||||
|
commandsArray.push_back(std::make_shared<commands::Leave>(botCluster, &queueMap));
|
||||||
|
commandsArray.push_back(std::make_shared<commands::Delete>(botCluster, &queueMap));
|
||||||
|
|
||||||
conn = sql::mariadb::get_driver_instance()->connect(DBURL, pro);
|
std::cout << "Command added.\n";
|
||||||
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Play>(botCluster->me.id, this));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Repeat>(botCluster->me.id, this));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Queue>(botCluster->me.id, this));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Skip>(botCluster->me.id, this));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Leave>(botCluster->me.id, this));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Delete>(botCluster->me.id, this));
|
|
||||||
|
|
||||||
botCluster->on_voice_track_marker([&](const dpp::voice_track_marker_t &marker)
|
|
||||||
{
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_debug, "nowPlaying " + nowPlayingMusic);
|
|
||||||
std::shared_ptr<dpp::embed> embed;
|
|
||||||
if (nowPlayingMusic == "") {
|
|
||||||
nowPlayingMusic = marker.track_meta;
|
|
||||||
embed = findEmbed(nowPlayingMusic);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
embed = findEmbed(nowPlayingMusic);
|
|
||||||
nowPlayingMusic = marker.track_meta;
|
|
||||||
}
|
|
||||||
auto voice_members = dpp::find_guild(marker.voice_client->server_id)->voice_members;
|
|
||||||
dpp::snowflake connectedChannel = marker.voice_client->channel_id;
|
|
||||||
int memberCount = 0;
|
|
||||||
for (auto member : voice_members)
|
|
||||||
if ( member.second.channel_id == connectedChannel )
|
|
||||||
memberCount++;
|
|
||||||
|
|
||||||
if (!memberCount)
|
|
||||||
{
|
|
||||||
auto joinedShard = marker.from;
|
|
||||||
std::cout << "voicechat is empty.";
|
|
||||||
marker.voice_client->stop_audio();
|
|
||||||
joinedShard->disconnect_voice(marker.voice_client->server_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
if (!memberCount)
|
|
||||||
{
|
|
||||||
auto joinedShard = marker.from;
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_info, "voicechat is empty.");
|
|
||||||
=======
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
|
|
||||||
|
|
||||||
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_debug, "Marker count : " + std::to_string(remainingSongsCount));
|
|
||||||
|
|
||||||
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
|
|
||||||
{
|
|
||||||
auto joinedShard = marker.from;
|
|
||||||
std::cout << "Queue ended\n";
|
|
||||||
if (!joinedShard)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (repeat) {
|
|
||||||
std::shared_ptr<dpp::embed> embed = findEmbed(nowPlayingMusic);
|
|
||||||
enqueueMusic({nowPlayingMusic, *embed}, marker.voice_client);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
|
|
||||||
marker.voice_client->stop_audio();
|
|
||||||
joinedShard->disconnect_voice(marker.voice_client->server_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
|
|
||||||
|
|
||||||
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_info, "Marker count : " + remainingSongsCount);
|
|
||||||
|
|
||||||
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
|
|
||||||
{
|
|
||||||
auto joinedShard = marker.from;
|
|
||||||
marker.voice_client->log(dpp::loglevel::ll_info, "Queue ended");
|
|
||||||
if (!joinedShard)
|
|
||||||
return;
|
|
||||||
marker.voice_client->stop_audio();
|
|
||||||
joinedShard->disconnect_voice(marker.voice_client->server_id);
|
|
||||||
=======
|
|
||||||
if (repeat) {
|
|
||||||
if (!embed) {
|
|
||||||
botCluster->log(dpp::loglevel::ll_error, std::string("알 수 없는 오류 발생!"));
|
|
||||||
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
enqueueMusic({nowPlayingMusic, *embed}, marker.voice_client);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
BumbleCeepp::~BumbleCeepp()
|
|
||||||
{
|
|
||||||
conn->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BumbleCeepp::enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc)
|
|
||||||
{
|
|
||||||
vc->insert_marker(item.ID);
|
|
||||||
vc->log(dpp::loglevel::ll_debug, "Enqueueuing " + item.ID + "on channel id " + vc->channel_id.str() + ".");
|
|
||||||
std::lock_guard<std::mutex> lock(enqueuingMutexMap[vc->server_id]);
|
|
||||||
|
|
||||||
OGGZ *track_og = oggz_open(("Music/" + item.ID + ".ogg").c_str(), OGGZ_READ);
|
|
||||||
|
|
||||||
/* If there was an issue reading the file, tell the user and stop */
|
|
||||||
if (!track_og) {
|
|
||||||
fprintf(stderr, "Error opening file\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set read callback, this callback will be called on packets with the serialno,
|
|
||||||
* -1 means every packet will be handled with this callback.
|
|
||||||
*/
|
|
||||||
oggz_set_read_callback(
|
|
||||||
track_og, -1,
|
|
||||||
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
|
||||||
dpp::discord_voice_client *vc = (dpp::discord_voice_client *)user_data;
|
|
||||||
|
|
||||||
/* send the audio */
|
|
||||||
vc->send_audio_opus(packet->op.packet, packet->op.bytes);
|
|
||||||
|
|
||||||
/* make sure to always return 0 here, read more on oggz documentation */
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
/* this will be the value of void *user_data */
|
|
||||||
(void *)vc
|
|
||||||
);
|
|
||||||
|
|
||||||
// read loop
|
|
||||||
while (vc && !vc->terminating) {
|
|
||||||
/* you can tweak this to whatever. Here I use BUFSIZ, defined in
|
|
||||||
* stdio.h as 8192.
|
|
||||||
*/
|
|
||||||
static const constexpr long CHUNK_READ = BUFSIZ * 2;
|
|
||||||
|
|
||||||
const long read_bytes = oggz_read(track_og, CHUNK_READ);
|
|
||||||
|
|
||||||
/* break on eof */
|
|
||||||
if (!read_bytes) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't forget to free the memory */
|
|
||||||
oggz_close(track_og);
|
|
||||||
|
|
||||||
vc->log(dpp::loglevel::ll_debug, "Enqueued " + item.ID + "on channel id " + vc->channel_id.str() + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<dpp::embed> BumbleCeepp::findEmbed(std::string musicID)
|
|
||||||
{
|
|
||||||
sql::ResultSet* res;
|
|
||||||
std::shared_ptr<dpp::embed> returnValue;
|
|
||||||
try {
|
|
||||||
std::unique_ptr<sql::PreparedStatement> stmnt(conn->prepareStatement("SELECT * FROM songs_info WHERE ID = ?"));
|
|
||||||
stmnt->setString(1, musicID);
|
|
||||||
res = stmnt->executeQuery();
|
|
||||||
|
|
||||||
if (!res->next()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
returnValue = makeEmbed(
|
|
||||||
res->getString("webpage_url").c_str(),
|
|
||||||
res->getString("title").c_str(),
|
|
||||||
res->getString("uploader").c_str(),
|
|
||||||
musicID,
|
|
||||||
res->getString("thumbnail").c_str(),
|
|
||||||
res->getInt("duration"));
|
|
||||||
}
|
|
||||||
catch(sql::SQLException& e){
|
|
||||||
botCluster->log(dpp::loglevel::ll_error, std::string("SQLError: ") + e.what());
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BumbleCeepp::insertDB(
|
|
||||||
std::string webpage_url, std::string title, std::string uploader, std::string id, std::string thumbnail, time_t duration)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
std::unique_ptr<sql::PreparedStatement> stmnt(
|
|
||||||
conn->prepareStatement("REPLACE INTO songs_info (ID, webpage_url, title, uploader, thumbnail, duration) VALUE (?, ?, ?, ?, ?, ?)"));
|
|
||||||
stmnt->setString(1, id);
|
|
||||||
stmnt->setString(2, webpage_url);
|
|
||||||
stmnt->setString(3, title);
|
|
||||||
stmnt->setString(4, uploader);
|
|
||||||
stmnt->setString(5, thumbnail);
|
|
||||||
stmnt->setInt(6, duration);
|
|
||||||
stmnt->executeQuery();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch(sql::SQLException& e){
|
|
||||||
botCluster->log(dpp::loglevel::ll_debug, std::string("SQLError: ") + e.what());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<dpp::embed> BumbleCeepp::makeEmbed(
|
|
||||||
std::string webpage_url, std::string title, std::string uploader, std::string id, std::string thumbnail, time_t duration)
|
|
||||||
{
|
|
||||||
char SongLengthStr[10];
|
|
||||||
tm t;
|
|
||||||
t.tm_mday = duration / 86400;
|
|
||||||
t.tm_hour = (duration % 86400)/3600;
|
|
||||||
t.tm_min = (duration % 3600)/60;
|
|
||||||
t.tm_sec = duration%60;
|
|
||||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
|
||||||
|
|
||||||
dpp::embed returnValue = dpp::embed()
|
|
||||||
.set_color(dpp::colors::sti_blue)
|
|
||||||
.set_title(title)
|
|
||||||
.set_description(uploader)
|
|
||||||
.set_url(webpage_url)
|
|
||||||
.set_image(thumbnail)
|
|
||||||
.add_field(
|
|
||||||
"길이",
|
|
||||||
SongLengthStr,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
insertDB(webpage_url, title, uploader, id, thumbnail, duration);
|
|
||||||
|
|
||||||
return std::make_shared<dpp::embed>(returnValue);
|
|
||||||
}
|
}
|
||||||
19
src/Commands/CommandType.cpp
Normal file
19
src/Commands/CommandType.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <Commands/CommandType.hpp>
|
||||||
|
|
||||||
|
commands::ICommand::ICommand(std::shared_ptr<dpp::cluster> botCluster)
|
||||||
|
{
|
||||||
|
this->botCluster = botCluster;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<MusicQueue> commands::VCCommand::getQueue(const dpp::slashcommand_t& event) {
|
||||||
|
auto findResult = queueMap->find(event.command.guild_id);
|
||||||
|
if (findResult == queueMap->end())
|
||||||
|
{
|
||||||
|
FMusicQueueID queueID;
|
||||||
|
queueID.guild_id = event.command.guild_id;
|
||||||
|
queueID.shard_id = event.from->shard_id;
|
||||||
|
|
||||||
|
(*queueMap)[queueID.guild_id] = std::make_shared<MusicQueue>(queueID, botCluster);
|
||||||
|
}
|
||||||
|
return queueMap->find(event.command.guild_id)->second;
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
#include <Commands/Delete.hpp>
|
#include <Commands/Delete.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
commands::Delete::Delete(dpp::snowflake botID, BumbleCeepp* Bot)
|
commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
: ICommand(botID, Bot)
|
: VCCommand(botCluster)
|
||||||
{
|
{
|
||||||
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botID);
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id);
|
||||||
|
|
||||||
Command.add_option(
|
Command.add_option(
|
||||||
dpp::command_option(dpp::co_string, "pos", "큐 번호", botID)
|
dpp::command_option(dpp::co_string, "pos", "큐 번호", botCluster->me.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
commandObjectVector.push_back(Command);
|
commandObjectVector.push_back(Command);
|
||||||
@@ -22,34 +23,37 @@ void commands::Delete::operator()(const dpp::slashcommand_t& event)
|
|||||||
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
|
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
|
||||||
event.thinking();
|
event.thinking();
|
||||||
|
|
||||||
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
|
|
||||||
auto index = atoi(Pos.c_str());
|
auto index = atoi(Pos.c_str());
|
||||||
|
|
||||||
auto vc = event.from->connecting_voice_channels.find(event.command.guild_id)->second->voiceclient;
|
int queueSize = queue->size();
|
||||||
int remainingSongsCount = vc->get_tracks_remaining() - 1;
|
|
||||||
std::vector<std::string> queuedSongs = vc->get_marker_metadata();
|
|
||||||
|
|
||||||
vc->log(dpp::loglevel::ll_info, "Queue size : " + remainingSongsCount);
|
std::cout << "queue size : " << queueSize << "\n";
|
||||||
|
|
||||||
if (index < 0 || remainingSongsCount+1 < index || (!vc->is_playing() && index == 0)) {
|
if (index < 0 || (queueSize - 1) < index) {
|
||||||
std::cout << "invalid index : " << index << ", " + Pos + "\n";
|
std::cout << "invalid index : " << index << ", " + Pos + "\n";
|
||||||
|
|
||||||
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
|
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dpp::embed embed = (*Bot->findEmbed(queuedSongs[index - 1]))
|
auto PopedElement = queue->pop(index);
|
||||||
|
|
||||||
|
dpp::embed embed = PopedElement.embed
|
||||||
.set_timestamp(time(0));
|
.set_timestamp(time(0));
|
||||||
|
|
||||||
dpp::message msg(event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:");
|
dpp::message msg(event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:");
|
||||||
|
|
||||||
if (index == 0) {
|
if (atoi(Pos.c_str()) == 0) {
|
||||||
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()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
v->voiceclient->skip_to_next_marker();
|
v->voiceclient->stop_audio();
|
||||||
|
v->voiceclient->insert_marker("end of music");
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.add_embed(embed);
|
msg.add_embed(embed);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include <Commands/Leave.hpp>
|
#include <Commands/Leave.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
commands::Leave::Leave(dpp::snowflake botID, BumbleCeepp* Bot)
|
commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
: ICommand(botID, Bot)
|
: VCCommand(botCluster)
|
||||||
{
|
{
|
||||||
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botID);
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id);
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
commandObjectVector.push_back(command);
|
||||||
}
|
}
|
||||||
@@ -17,6 +18,10 @@ void commands::Leave::operator()(const dpp::slashcommand_t& event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v->voiceclient->stop_audio();
|
v->voiceclient->stop_audio();
|
||||||
|
|
||||||
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
|
|
||||||
|
queue->clear();
|
||||||
event.from->disconnect_voice(event.command.guild_id);
|
event.from->disconnect_voice(event.command.guild_id);
|
||||||
|
|
||||||
dpp::message msg(event.command.channel_id, "음성 채팅방을 떠납니다!");
|
dpp::message msg(event.command.channel_id, "음성 채팅방을 떠납니다!");
|
||||||
|
|||||||
@@ -4,179 +4,22 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
std::string getResultFromCommand(std::string cmd) {
|
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
std::string result;
|
: VCCommand(botCluster)
|
||||||
FILE* stream;
|
|
||||||
const int maxBuffer = 256; // 버퍼의 크기는 적당하게
|
|
||||||
char buffer[maxBuffer];
|
|
||||||
cmd.append(" 2>&1"); // 표준에러를 표준출력으로 redirect
|
|
||||||
|
|
||||||
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); // 파이프 닫는 것 잊지 마시고요!
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
commands::Play::Play(dpp::snowflake botID, BumbleCeepp* Bot)
|
|
||||||
: ICommand(botID, Bot)
|
|
||||||
{
|
{
|
||||||
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botID);
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
|
||||||
|
|
||||||
command.add_option(
|
command.add_option(
|
||||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botID)
|
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botCluster->me.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
commandObjectVector.push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
static void _Internal_Enqueue_Func(const dpp::slashcommand_t& event, BumbleCeepp* Bot){
|
|
||||||
std::string Query = std::get<std::string>(event.get_parameter("query"));
|
|
||||||
|
|
||||||
event.from->log(dpp::loglevel::ll_info, "음악 다운로드 시작");
|
|
||||||
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
|
||||||
event.from->log(dpp::loglevel::ll_info, "음악 다운로드 완료");
|
|
||||||
=======
|
|
||||||
void commands::Play::operator()(const dpp::slashcommand_t& event)
|
|
||||||
{
|
|
||||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
|
||||||
{
|
|
||||||
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
|
|
||||||
if (!event.from->get_voice(event.command.guild_id))
|
|
||||||
{
|
|
||||||
dpp::guild* g = dpp::find_guild(event.command.guild_id);
|
|
||||||
bool memberIsInVoice = g->connect_member_voice(event.command.get_issuing_user().id);
|
|
||||||
if (!memberIsInVoice)
|
|
||||||
{
|
|
||||||
event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Query = std::get<std::string>(event.get_parameter("query"));
|
|
||||||
|
|
||||||
event.thinking();
|
|
||||||
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "음악 ID 쿼리: " + Query);
|
|
||||||
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
|
|
||||||
|
|
||||||
std::string musicIDs = getResultFromCommand(("python3 youtube-search.py \"" + Query + "\" & wait").c_str());
|
|
||||||
|
|
||||||
if (!musicIDs.length())
|
|
||||||
{
|
|
||||||
<<<<<<< HEAD
|
|
||||||
event.from->log(dpp::loglevel::ll_info, "Red ID : " + ID);
|
|
||||||
infofile.open("Music/" + ID + ".info.json");
|
|
||||||
infofile >> document;
|
|
||||||
infofile.close();
|
|
||||||
|
|
||||||
FQueueElement Data = {
|
|
||||||
ID,
|
|
||||||
Bot->makeEmbed(
|
|
||||||
document["webpage_url"],
|
|
||||||
document["title"],
|
|
||||||
document["uploader"],
|
|
||||||
document["id"],
|
|
||||||
document["thumbnail"],
|
|
||||||
int(document["duration"]))
|
|
||||||
};
|
|
||||||
|
|
||||||
RequestedMusic.push(Data);
|
|
||||||
=======
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "유튜브 검색 결과 없음");
|
|
||||||
event.edit_response("검색 결과가 없습니다.");
|
|
||||||
return;
|
|
||||||
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
|
|
||||||
}
|
|
||||||
|
|
||||||
std::stringstream sstream(musicIDs);
|
|
||||||
std::string musicID;
|
|
||||||
while (getline(sstream, musicID, '\n')) {
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "musicID: " + musicID);
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 시도..");
|
|
||||||
std::shared_ptr<dpp::embed> embed = Bot->findEmbed(musicID);
|
|
||||||
|
|
||||||
if (embed == nullptr) {
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 실패");
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "다운로드 시작");
|
|
||||||
std::system(("python3 yt-download.py \"" + musicID + "\" & wait").c_str());
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
if (v && v->voiceclient && v->voiceclient->is_ready())
|
|
||||||
{
|
|
||||||
auto _copiedQueue = RequestedMusic;
|
|
||||||
while (!_copiedQueue.empty())
|
|
||||||
{
|
|
||||||
Bot->enqueueMusic(_copiedQueue.front(), v->voiceclient);
|
|
||||||
_copiedQueue.pop();
|
|
||||||
=======
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "musicID: " + musicID);
|
|
||||||
std::ifstream infofile;
|
|
||||||
infofile.open((std::string("Music/") + musicID + ".info.json").c_str());
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, std::string("json file name: ") + "Music/" + musicID + ".info.json");
|
|
||||||
json document;
|
|
||||||
infofile >> document;
|
|
||||||
infofile.close();
|
|
||||||
|
|
||||||
embed = Bot->makeEmbed(
|
|
||||||
document["webpage_url"],
|
|
||||||
document["title"],
|
|
||||||
document["uploader"],
|
|
||||||
document["id"],
|
|
||||||
document["thumbnail"],
|
|
||||||
int(document["duration"]));
|
|
||||||
|
|
||||||
on_DLCompleted(musicID, *embed, event);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
event.from->log(dpp::loglevel::ll_debug, "DB쿼리 완료");
|
|
||||||
on_DLCompleted(musicID, *embed, event);
|
|
||||||
>>>>>>> 68b6105ac3ddf1c27f40e0e552780171352e734d
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Play::on_DLCompleted(std::string musicID, dpp::embed embed, const dpp::slashcommand_t& event)
|
|
||||||
{
|
|
||||||
static std::string raw_event;
|
|
||||||
if (raw_event != event.raw_event){
|
|
||||||
raw_event = event.raw_event;
|
|
||||||
|
|
||||||
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
|
||||||
msg.add_embed(embed);
|
|
||||||
event.edit_response(msg);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dpp::message followMsg(event.command.channel_id, "");
|
|
||||||
|
|
||||||
dpp::embed followEmbed = dpp::embed()
|
|
||||||
.add_field(
|
|
||||||
embed.title,
|
|
||||||
embed.description,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
.add_field(
|
|
||||||
"",
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
followMsg.add_embed(followEmbed);
|
|
||||||
|
|
||||||
event.from->creator->message_create(followMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Play::operator()(const dpp::slashcommand_t& event)
|
void commands::Play::operator()(const dpp::slashcommand_t& event)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
||||||
@@ -194,19 +37,90 @@ void commands::Play::operator()(const dpp::slashcommand_t& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Query = std::get<std::string>(event.get_parameter("query"));
|
||||||
|
|
||||||
event.thinking();
|
event.thinking();
|
||||||
|
|
||||||
std::thread t1(_Internal_Enqueue_Func, event, Bot);
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
t1.detach();
|
|
||||||
|
|
||||||
auto voiceconn = event.from->get_voice(event.command.guild_id);
|
std::cout << "다운로드 시작" << "\n";
|
||||||
|
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
||||||
|
std::cout << "다운로드 완료" << "\n";
|
||||||
|
|
||||||
if (!voiceconn || !voiceconn->voiceclient || !voiceconn->voiceclient->is_ready()) {
|
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||||
event.from->creator->on_voice_ready([this, musicID, embed](const dpp::voice_ready_t& Voice){
|
|
||||||
this->Bot->enqueueMusic({musicID, embed}, Voice.voice_client);
|
std::ifstream infofile, idfile;
|
||||||
});
|
json document;
|
||||||
|
std::string ID;
|
||||||
|
std::queue<FQueueElement> RequestedMusic;
|
||||||
|
idfile.open("Temp/CurMusic");
|
||||||
|
while (std::getline(idfile, ID))
|
||||||
|
{
|
||||||
|
std::cout << ID << "\n";
|
||||||
|
infofile.open("Music/" + ID + ".info.json");
|
||||||
|
infofile >> document;
|
||||||
|
infofile.close();
|
||||||
|
|
||||||
|
time_t SongLength = int(document["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);
|
||||||
|
|
||||||
|
FQueueElement Data = {
|
||||||
|
std::string(document["webpage_url"]),
|
||||||
|
std::string(document["title"]),
|
||||||
|
std::string(document["uploader"]),
|
||||||
|
std::string(document["id"]),
|
||||||
|
std::string(document["thumbnail"]),
|
||||||
|
to_string(document["duration"]),
|
||||||
|
dpp::embed()
|
||||||
|
.set_color(dpp::colors::sti_blue)
|
||||||
|
.set_title(Data.title)
|
||||||
|
.set_description(Data.description)
|
||||||
|
.set_url(Data.URL)
|
||||||
|
.set_image(Data.thumbnail)
|
||||||
|
.add_field(
|
||||||
|
"길이",
|
||||||
|
SongLengthStr,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
(*queue) += Data;
|
||||||
|
|
||||||
|
RequestedMusic.push(Data);
|
||||||
}
|
}
|
||||||
else {
|
idfile.close();
|
||||||
Bot->enqueueMusic({musicID, embed}, voiceconn->voiceclient);
|
std::system("rm -f Temp/CurMusic");
|
||||||
|
std::cout << "queued\n";
|
||||||
|
|
||||||
|
msg.add_embed(RequestedMusic.front().embed);
|
||||||
|
RequestedMusic.pop();
|
||||||
|
event.edit_original_response(msg);
|
||||||
|
|
||||||
|
while (!RequestedMusic.empty())
|
||||||
|
{
|
||||||
|
dpp::message followMsg(event.command.channel_id, "");
|
||||||
|
|
||||||
|
followMsg.add_embed(RequestedMusic.front().embed);
|
||||||
|
RequestedMusic.pop();
|
||||||
|
|
||||||
|
botCluster->message_create(followMsg);
|
||||||
}
|
}
|
||||||
|
std::cout << "replied\n";
|
||||||
|
|
||||||
|
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
||||||
|
|
||||||
|
/* If the voice channel was invalid, or there is an issue with it, then tell the user. */
|
||||||
|
if (v && v->voiceclient && v->voiceclient->is_ready())
|
||||||
|
{
|
||||||
|
queue->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(); });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
@@ -3,68 +3,38 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
commands::Queue::Queue(dpp::snowflake botID, BumbleCeepp* Bot)
|
namespace commands {
|
||||||
: ICommand(botID, Bot)
|
dpp::embed makeEmbed(std::list<FQueueElement>::iterator& iter, std::list<FQueueElement>::iterator end, bool Repeat = false, int Index = 0)
|
||||||
{
|
{
|
||||||
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botID);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
|
|
||||||
dpp::message msg;
|
|
||||||
msg.set_channel_id(event.command.channel_id);
|
|
||||||
|
|
||||||
auto voiceconn = event.from->get_voice(event.command.guild_id);
|
|
||||||
|
|
||||||
if (!voiceconn || !voiceconn->voiceclient) {
|
|
||||||
event.reply("음성 채팅방에 참가하지 않은 상태입니다.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto vc = voiceconn->voiceclient;
|
|
||||||
|
|
||||||
int remainingSongsCount = vc->get_tracks_remaining() - 1;
|
|
||||||
if (remainingSongsCount <= 0 && !vc->is_playing()) {
|
|
||||||
//재생 중인 노래가 없고 큐에 노래가 없는 상황
|
|
||||||
dpp::embed embed = dpp::embed()
|
dpp::embed embed = dpp::embed()
|
||||||
.set_color(dpp::colors::sti_blue)
|
.set_color(dpp::colors::sti_blue);
|
||||||
|
|
||||||
|
if (iter == end) {
|
||||||
|
embed
|
||||||
.set_title("큐가 비었습니다!")
|
.set_title("큐가 비었습니다!")
|
||||||
.set_timestamp(time(0));
|
.set_timestamp(time(0));
|
||||||
|
|
||||||
if (Bot->repeat)
|
if (Repeat)
|
||||||
embed.add_field(":repeat:","");
|
embed.add_field(":repeat:","");
|
||||||
|
|
||||||
msg.add_embed(embed);
|
return embed;
|
||||||
}
|
|
||||||
else {
|
|
||||||
msg.set_content("지금 재생 중:");
|
|
||||||
dpp::embed curMusicEmbed = *Bot->findEmbed(Bot->nowPlayingMusic);
|
|
||||||
msg.add_embed(curMusicEmbed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event.reply(msg, [&](const dpp::confirmation_callback_t& _event) {
|
std::ostringstream Number;
|
||||||
auto shard_id = dpp::find_guild(event.command.guild_id)->shard_id;
|
int Start = Index;
|
||||||
dpp::cluster* cluster = const_cast<dpp::cluster *>(_event.bot);
|
|
||||||
auto shard = cluster->get_shard(shard_id);
|
|
||||||
auto iter = shard->connecting_voice_channels.find(event.command.guild_id);
|
|
||||||
std::vector<std::string> queuedSongs = iter->second->voiceclient->get_marker_metadata();
|
|
||||||
|
|
||||||
int j;
|
for (; (Index < Start + 5) && (iter != end); iter++, Index++) {
|
||||||
for (int i = 0; i < (queuedSongs.size()+4) / 5; i++)
|
Number.clear();
|
||||||
{
|
Number.str("");
|
||||||
dpp::embed followEmbed = dpp::embed();
|
Number << Index;
|
||||||
for (j = i * 5; j < i * 5 + 5 && j < queuedSongs.size(); j++)
|
embed.add_field(
|
||||||
{
|
Number.str(),
|
||||||
dpp::embed originalEmbed = *Bot->findEmbed(queuedSongs[j]);
|
|
||||||
|
|
||||||
followEmbed.add_field(
|
|
||||||
std::to_string(j + 1),
|
|
||||||
"",
|
"",
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
.add_field(
|
.add_field(
|
||||||
originalEmbed.title,
|
iter->title,
|
||||||
originalEmbed.description,
|
iter->description,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
.add_field(
|
.add_field(
|
||||||
@@ -73,18 +43,55 @@ void commands::Queue::operator()(const dpp::slashcommand_t& event) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j >= queuedSongs.size())
|
if (iter == end) {
|
||||||
{
|
embed.set_timestamp(time(0));
|
||||||
followEmbed.set_timestamp(time(0));
|
if (Repeat)
|
||||||
if (Bot->repeat)
|
embed.add_field(":repeat:","");
|
||||||
followEmbed.add_field(":repeat:","");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
|
: VCCommand(botCluster)
|
||||||
|
{
|
||||||
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id);
|
||||||
|
|
||||||
|
commandObjectVector.push_back(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
|
||||||
|
dpp::message msg;
|
||||||
|
msg.set_channel_id(event.command.channel_id);
|
||||||
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
|
|
||||||
|
if (queue->size() < 1) {
|
||||||
|
auto iter = queue->begin();
|
||||||
|
msg.add_embed(makeEmbed(iter, queue->end(), queue->repeat));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msg.set_content("지금 재생 중:");
|
||||||
|
msg.add_embed(queue->peek(0).embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.reply(msg, [this, queue, event](const dpp::confirmation_callback_t &_event) {
|
||||||
|
auto iter = queue->begin();
|
||||||
|
int queueSize = queue->size();
|
||||||
|
iter++;
|
||||||
|
for (int i = 0; i < ceil(queueSize / 5.0); i++) {
|
||||||
|
dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1);
|
||||||
|
|
||||||
dpp::message followMsg;
|
dpp::message followMsg;
|
||||||
followMsg.channel_id = event.command.channel_id;
|
followMsg.channel_id = event.command.channel_id;
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
followMsg.content = "현재 큐에 있는 항목:";
|
||||||
|
}
|
||||||
followMsg.add_embed(followEmbed);
|
followMsg.add_embed(followEmbed);
|
||||||
event.from->creator->message_create(followMsg);
|
|
||||||
|
botCluster->message_create(followMsg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2,23 +2,25 @@
|
|||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
commands::Repeat::Repeat(dpp::snowflake botID, BumbleCeepp* Bot)
|
commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
: ICommand(botID, Bot)
|
: VCCommand(botCluster)
|
||||||
{
|
{
|
||||||
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botID);
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id);
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
commandObjectVector.push_back(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
|
void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
|
||||||
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
|
|
||||||
if (Bot->repeat) {
|
if (queue->repeat) {
|
||||||
event.reply("반복을 껐습니다.");
|
event.reply("반복을 껐습니다.");
|
||||||
Bot->repeat = false;
|
queue->repeat = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
event.reply("반복을 켰습니다.");
|
event.reply("반복을 켰습니다.");
|
||||||
Bot->repeat = true;
|
queue->repeat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
commands::Skip::Skip(dpp::snowflake botID, BumbleCeepp* Bot)
|
commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||||
: ICommand(botID, Bot)
|
: VCCommand(botCluster)
|
||||||
{
|
{
|
||||||
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botID);
|
this->queueMap = queueMap;
|
||||||
|
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id);
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
commandObjectVector.push_back(command);
|
||||||
}
|
}
|
||||||
@@ -16,7 +17,11 @@ void commands::Skip::operator()(const dpp::slashcommand_t& event) {
|
|||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v->voiceclient->skip_to_next_marker();
|
|
||||||
|
v->voiceclient->stop_audio();
|
||||||
|
v->voiceclient->insert_marker("next marker");
|
||||||
|
|
||||||
|
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||||
|
|
||||||
event.reply("스킵했습니다!");
|
event.reply("스킵했습니다!");
|
||||||
|
|
||||||
|
|||||||
1
src/Music/Archive
Normal file
1
src/Music/Archive
Normal file
@@ -0,0 +1 @@
|
|||||||
|
OSeStDEAZJQ
|
||||||
1
src/Music/OSeStDEAZJQ.info.json
Normal file
1
src/Music/OSeStDEAZJQ.info.json
Normal file
File diff suppressed because one or more lines are too long
BIN
src/Music/OSeStDEAZJQ.ogg
Normal file
BIN
src/Music/OSeStDEAZJQ.ogg
Normal file
Binary file not shown.
216
src/MusicQueue.cpp
Normal file
216
src/MusicQueue.cpp
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
#include <MusicQueue.hpp>
|
||||||
|
#include <ogg/ogg.h>
|
||||||
|
#include <oggz/oggz.h>
|
||||||
|
#include <opus/opusfile.h>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
MusicQueue::MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster)
|
||||||
|
{
|
||||||
|
this->id = id;
|
||||||
|
repeat = false;
|
||||||
|
this->botCluster = botCluster;
|
||||||
|
|
||||||
|
botCluster->on_voice_track_marker([this, botCluster](const dpp::voice_track_marker_t &marker)
|
||||||
|
{
|
||||||
|
std::cout << marker.track_meta << " Marker reached.\n";
|
||||||
|
|
||||||
|
if (empty())
|
||||||
|
{
|
||||||
|
std::cout << "Queue ended\n";
|
||||||
|
playMutex.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto music = pop(0);
|
||||||
|
if (repeat)
|
||||||
|
{
|
||||||
|
(*this) += music;
|
||||||
|
}
|
||||||
|
|
||||||
|
markerCallback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicQueue::operator+=(FQueueElement operand)
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
queue.push_back(operand);
|
||||||
|
mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
FQueueElement MusicQueue::pop(int index)
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
auto iter = queue.begin();
|
||||||
|
std::advance(iter, index);
|
||||||
|
auto returnValue = *iter;
|
||||||
|
queue.erase(iter);
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FQueueElement MusicQueue::peek(int index)
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
auto iter = queue.begin();
|
||||||
|
std::advance(iter, index);
|
||||||
|
auto returnValue = *iter;
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MusicQueue::empty()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
bool empty = queue.empty();
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicQueue::clear()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
queue.clear();
|
||||||
|
mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<struct FQueueElement>::iterator MusicQueue::begin()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
auto returnValue = queue.begin();
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<struct FQueueElement>::iterator MusicQueue::end()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
auto returnValue = queue.end();
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t MusicQueue::size()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
auto returnValue = queue.size();
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FMusicQueueID MusicQueue::getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicQueue::markerCallback()
|
||||||
|
{
|
||||||
|
std::cout << "Music play started\n";
|
||||||
|
|
||||||
|
dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id);
|
||||||
|
if (!joinedShard)
|
||||||
|
{
|
||||||
|
std::cout << "No shard\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty())
|
||||||
|
{
|
||||||
|
std::cout << "Queue ended\n";
|
||||||
|
playMutex.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FQueueElement music = peek(0);
|
||||||
|
|
||||||
|
dpp::voiceconn* v = joinedShard->get_voice(id.guild_id);
|
||||||
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready())
|
||||||
|
{
|
||||||
|
std::cout << "not in voicechat. quit musicplay";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//v->voiceclient->error(4014);
|
||||||
|
|
||||||
|
/* load the audio file with oggz */
|
||||||
|
OGGZ *track_og = oggz_open(("Music/" + music.fileName + ".ogg").c_str(), OGGZ_READ);
|
||||||
|
|
||||||
|
/* If there was an issue reading the file, tell the user and stop */
|
||||||
|
if (!track_og) {
|
||||||
|
fprintf(stderr, "Error opening file\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set read callback, this callback will be called on packets with the serialno,
|
||||||
|
* -1 means every packet will be handled with this callback.
|
||||||
|
*/
|
||||||
|
oggz_set_read_callback(
|
||||||
|
track_og, -1,
|
||||||
|
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
||||||
|
dpp::voiceconn *voiceconn = (dpp::voiceconn *)user_data;
|
||||||
|
|
||||||
|
/* send the audio */
|
||||||
|
voiceconn->voiceclient->send_audio_opus(packet->op.packet, packet->op.bytes);
|
||||||
|
|
||||||
|
/* make sure to always return 0 here, read more on oggz documentation */
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
/* this will be the value of void *user_data */
|
||||||
|
(void *)v
|
||||||
|
);
|
||||||
|
|
||||||
|
// read loop
|
||||||
|
while (v && v->voiceclient && !v->voiceclient->terminating) {
|
||||||
|
/* you can tweak this to whatever. Here I use BUFSIZ, defined in
|
||||||
|
* stdio.h as 8192.
|
||||||
|
*/
|
||||||
|
static const constexpr long CHUNK_READ = BUFSIZ * 2;
|
||||||
|
|
||||||
|
const long read_bytes = oggz_read(track_og, CHUNK_READ);
|
||||||
|
|
||||||
|
/* break on eof */
|
||||||
|
if (!read_bytes) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't forget to free the memory */
|
||||||
|
oggz_close(track_og);
|
||||||
|
|
||||||
|
v->voiceclient->insert_marker(music.fileName + " end");
|
||||||
|
|
||||||
|
std::cout << "audio sending complete\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MusicQueue::play()
|
||||||
|
{
|
||||||
|
if (!playMutex.try_lock())
|
||||||
|
{
|
||||||
|
std::cout << "Already playing\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id);
|
||||||
|
if (!joinedShard)
|
||||||
|
{
|
||||||
|
std::cout << "No shard\n";
|
||||||
|
playMutex.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpp::voiceconn* v = joinedShard->get_voice(id.guild_id);
|
||||||
|
if (!v || !v->voiceclient || !v->voiceclient->is_ready())
|
||||||
|
{
|
||||||
|
std::cout << "not in voicechat. quit musicplay";
|
||||||
|
playMutex.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
markerCallback();
|
||||||
|
}
|
||||||
@@ -10,8 +10,7 @@ int main()
|
|||||||
std::ifstream configfile("config.json");
|
std::ifstream configfile("config.json");
|
||||||
configfile >> configdocument;
|
configfile >> configdocument;
|
||||||
|
|
||||||
std::shared_ptr<BumbleCeepp> bumbleBee = std::make_shared<BumbleCeepp>(
|
std::shared_ptr<BumbleCeepp> bumbleBee = std::make_shared<BumbleCeepp>(configdocument["token"], 1);
|
||||||
configdocument["token"], configdocument["dbURL"], configdocument["user"], configdocument["password"]);
|
|
||||||
|
|
||||||
bumbleBee->start();
|
bumbleBee->start();
|
||||||
|
|
||||||
|
|||||||
20
src/test.py
20
src/test.py
@@ -1,20 +0,0 @@
|
|||||||
import yt_dlp
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
ydl_opts = {
|
|
||||||
'quiet': True,
|
|
||||||
'clean_infojson': False,
|
|
||||||
'default_search': 'ytsearch',
|
|
||||||
'format': '251',
|
|
||||||
'outtmpl': {'default': 'Temp/%(id)s.temp'},
|
|
||||||
'overwrites': False,
|
|
||||||
'writeinfojson': True }
|
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
||||||
info = ydl.extract_info(sys.argv[1], download=False)
|
|
||||||
with open("out", "w") as f:
|
|
||||||
f.write(json.dumps(ydl.sanitize_info(info)))
|
|
||||||
BIN
src/yt-dlp
Executable file
BIN
src/yt-dlp
Executable file
Binary file not shown.
@@ -1,54 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
def uri_validator(x):
|
|
||||||
try:
|
|
||||||
result = urllib.parse.urlparse(x)
|
|
||||||
return all([result.scheme, result.netloc])
|
|
||||||
except AttributeError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
#URL인 경우
|
|
||||||
if uri_validator(sys.argv[1]) == True:
|
|
||||||
result = urllib.parse.urlparse(sys.argv[1])
|
|
||||||
|
|
||||||
#youtu.be짧은 주소인 경우
|
|
||||||
if (result.netloc == 'youtu.be'):
|
|
||||||
print(result.path[1:13])
|
|
||||||
|
|
||||||
#플레이리스트인 경우
|
|
||||||
if result.path == '/playlist':
|
|
||||||
import re, requests
|
|
||||||
|
|
||||||
response = requests.get("https://www.youtube.com/playlist?" + result.query)
|
|
||||||
|
|
||||||
pattern = re.compile('"videoId":"(.{11})"')
|
|
||||||
|
|
||||||
IDlist = set(pattern.findall(response.text))
|
|
||||||
|
|
||||||
# list_to_return = list()
|
|
||||||
# list_to_return.append(IDlist[0])
|
|
||||||
# list_to_return_count = 0
|
|
||||||
# for it in range(0, len(list_to_return)):
|
|
||||||
# if (list_to_return[list_to_return_count] == IDlist[it]):
|
|
||||||
# continue
|
|
||||||
# else:
|
|
||||||
# list_to_return[list_to_return_count] = IDlist[it]
|
|
||||||
# list_to_return_count += 1
|
|
||||||
|
|
||||||
for it in IDlist:
|
|
||||||
print(it)
|
|
||||||
#영상인 경우
|
|
||||||
elif result.path == '/watch':
|
|
||||||
print(result.query[2:13])
|
|
||||||
else:
|
|
||||||
from youtube_search import YoutubeSearch
|
|
||||||
|
|
||||||
results = YoutubeSearch(sys.argv[1], max_results=10).to_dict()
|
|
||||||
|
|
||||||
#검색 결과가 없는 경우 확인 불가
|
|
||||||
print(results[0]["id"])
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import yt_dlp
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
ydl_opts = {
|
|
||||||
'quiet': True,
|
|
||||||
'format': '251',
|
|
||||||
'outtmpl': {'default': 'Temp/' + sys.argv[1]},
|
|
||||||
'writeinfojson': True
|
|
||||||
}
|
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
||||||
info = ydl.extract_info("https://www.youtube.com/watch?v=" + sys.argv[1])
|
|
||||||
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + sys.argv[1] + "\" -c copy Music/" + sys.argv[1] + ".ogg > /dev/null 2> /dev/null")
|
|
||||||
os.system("mv Temp/" + sys.argv[1] + ".info.json Music/" + sys.argv[1] + ".info.json > /dev/null 2> /dev/null")
|
|
||||||
os.system("rm -rf Temp/ > /dev/null 2> /dev/null")
|
|
||||||
Reference in New Issue
Block a user