This commit is contained in:
2024-01-22 03:26:22 +09:00
parent c996f290db
commit b7b1018871
18 changed files with 118 additions and 134 deletions

View File

@@ -35,8 +35,6 @@ target_include_directories(${BOT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
/usr/include/opus /usr/include/opus
/usr/include
/usr/local/include
) )
target_link_libraries(${BOT_NAME} target_link_libraries(${BOT_NAME}

View File

@@ -15,4 +15,15 @@ public:
protected: protected:
std::shared_ptr<dpp::cluster> botCluster; 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;
};
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Delete : public ICommand { class Delete : public VCCommand {
public: public:
Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Leave : public ICommand { class Leave : public VCCommand {
public: public:
Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Play : public ICommand { class Play : public VCCommand {
public: public:
Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Queue : public ICommand { class Queue : public VCCommand {
public: public:
Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Repeat : public ICommand { class Repeat : public VCCommand {
public: public:
Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -4,12 +4,10 @@
#include <memory> #include <memory>
namespace commands { namespace commands {
class Skip : public ICommand { class Skip : public VCCommand {
public: public:
Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap); 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);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
}; };
} }

View File

@@ -9,7 +9,7 @@ struct FMusicQueueID {
class MusicQueue { class MusicQueue {
public: public:
MusicQueue(FMusicQueueID id); MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster);
void operator+=(FQueueElement operand); void operator+=(FQueueElement operand);
FQueueElement pop(int index); FQueueElement pop(int index);
FQueueElement peek(int index); FQueueElement peek(int index);
@@ -19,9 +19,9 @@ public:
std::list<struct FQueueElement>::iterator end(); std::list<struct FQueueElement>::iterator end();
std::size_t size(); std::size_t size();
FMusicQueueID getId(); FMusicQueueID getId();
void play(std::shared_ptr<dpp::cluster> botCluster); void play();
void markerCallback(std::shared_ptr<dpp::cluster> botCluster); void markerCallback();
bool repeat; bool repeat;
private: private:
@@ -29,5 +29,5 @@ private:
std::mutex mutex; std::mutex mutex;
std::mutex playMutex; std::mutex playMutex;
FMusicQueueID id; FMusicQueueID id;
bool queuePlaying; std::shared_ptr<dpp::cluster> botCluster;
}; };

View File

@@ -4,3 +4,16 @@ commands::ICommand::ICommand(std::shared_ptr<dpp::cluster> botCluster)
{ {
this->botCluster = 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;
}

View File

@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id); dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id);
@@ -23,25 +23,29 @@ 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();
auto findResult = queueMap->find(event.command.guild_id); std::shared_ptr<MusicQueue> queue = getQueue(event);
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); auto index = atoi(Pos.c_str());
int queueSize = queue->size();
std::cout << "queue size : " << queueSize << "\n";
if (index < 0 || (queueSize - 1) < index) {
std::cout << "invalid index : " << index << ", " + Pos + "\n";
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
return;
} }
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
auto PopedElement = queue->pop(atoi(Pos.c_str())); auto PopedElement = queue->pop(index);
dpp::embed embed = PopedElement.embed 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 (!atoi(Pos.c_str())) { 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()) {
@@ -49,6 +53,7 @@ void commands::Delete::operator()(const dpp::slashcommand_t& event)
} }
v->voiceclient->stop_audio(); v->voiceclient->stop_audio();
v->voiceclient->insert_marker("end of music");
} }
msg.add_embed(embed); msg.add_embed(embed);

View File

@@ -2,7 +2,7 @@
#include <iostream> #include <iostream>
commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id); dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id);
@@ -19,16 +19,7 @@ void commands::Leave::operator()(const dpp::slashcommand_t& event)
} }
v->voiceclient->stop_audio(); v->voiceclient->stop_audio();
auto findResult = queueMap->find(event.command.guild_id); std::shared_ptr<MusicQueue> queue = getQueue(event);
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);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
queue->clear(); queue->clear();
event.from->disconnect_voice(event.command.guild_id); event.from->disconnect_voice(event.command.guild_id);

View File

@@ -8,7 +8,7 @@
using json = nlohmann::json; using json = nlohmann::json;
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id); dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
@@ -20,7 +20,8 @@ commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_ma
commandObjectVector.push_back(command); commandObjectVector.push_back(command);
} }
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")))
{ {
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오."); event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
@@ -28,25 +29,19 @@ void commands::Play::operator()(const dpp::slashcommand_t& event) {
} }
/* Attempt to connect to a voice channel, returns false if we fail to connect. */ /* Attempt to connect to a voice channel, returns false if we fail to connect. */
if (event.from->get_voice(event.command.guild_id) || !dpp::find_guild(event.command.guild_id)->connect_member_voice(event.command.get_issuing_user().id)) if (!event.from->get_voice(event.command.guild_id))
{ {
return event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!"); if (!dpp::find_guild(event.command.guild_id)->connect_member_voice(event.command.get_issuing_user().id))
{
return event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!");
}
} }
std::string Query = std::get<std::string>(event.get_parameter("query")); std::string Query = std::get<std::string>(event.get_parameter("query"));
event.thinking(); event.thinking();
auto findResult = queueMap->find(event.command.guild_id); std::shared_ptr<MusicQueue> queue = getQueue(event);
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);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
std::cout << "다운로드 시작" << "\n"; std::cout << "다운로드 시작" << "\n";
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str()); std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
@@ -106,7 +101,8 @@ void commands::Play::operator()(const dpp::slashcommand_t& event) {
RequestedMusic.pop(); RequestedMusic.pop();
event.edit_original_response(msg); event.edit_original_response(msg);
while (!RequestedMusic.empty()) { while (!RequestedMusic.empty())
{
dpp::message followMsg(event.command.channel_id, ""); dpp::message followMsg(event.command.channel_id, "");
followMsg.add_embed(RequestedMusic.front().embed); followMsg.add_embed(RequestedMusic.front().embed);
@@ -119,10 +115,11 @@ void commands::Play::operator()(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 the voice channel was invalid, or there is an issue with it, then tell the user. */ /* 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()) { if (v && v->voiceclient && v->voiceclient->is_ready())
queue->play(botCluster); {
queue->play();
} }
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(botCluster); }); botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(); });
return; return;
} }

View File

@@ -54,7 +54,7 @@ dpp::embed makeEmbed(std::list<FQueueElement>::iterator& iter, std::list<FQueueE
} }
commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id); dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id);
@@ -63,25 +63,24 @@ commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_
} }
void commands::Queue::operator()(const dpp::slashcommand_t& event) { void commands::Queue::operator()(const dpp::slashcommand_t& event) {
dpp::message msg(event.command.channel_id, "지금 재생 중:"); dpp::message msg;
msg.set_channel_id(event.command.channel_id);
std::shared_ptr<MusicQueue> queue = getQueue(event);
auto findResult = queueMap->find(event.command.guild_id); if (queue->size() < 1) {
if (findResult == queueMap->end()) auto iter = queue->begin();
{ msg.add_embed(makeEmbed(iter, queue->end(), queue->repeat));
FMusicQueueID queueID; }
queueID.guild_id = event.command.guild_id; else {
queueID.shard_id = event.from->shard_id; msg.set_content("지금 재생 중:");
msg.add_embed(queue->peek(0).embed);
(*queueMap)[queueID.guild_id] = std::make_shared<MusicQueue>(queueID);
} }
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
msg.add_embed(queue->peek(0).embed);
event.reply(msg, [this, queue, event](const dpp::confirmation_callback_t &_event) { event.reply(msg, [this, queue, event](const dpp::confirmation_callback_t &_event) {
auto iter = queue->begin(); auto iter = queue->begin();
int queueSize = queue->size();
iter++; iter++;
for (int i = 0; i < ceil((queue->size() - 1) / 5.0); i++) { for (int i = 0; i < ceil(queueSize / 5.0); i++) {
dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1); dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1);
dpp::message followMsg; dpp::message followMsg;

View File

@@ -3,7 +3,7 @@
#include <string> #include <string>
commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id); dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id);
@@ -12,16 +12,7 @@ commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordere
} }
void commands::Repeat::operator()(const dpp::slashcommand_t& event) { void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
auto findResult = queueMap->find(event.command.guild_id); std::shared_ptr<MusicQueue> queue = getQueue(event);
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);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
if (queue->repeat) { if (queue->repeat) {
event.reply("반복을 껐습니다."); event.reply("반복을 껐습니다.");

View File

@@ -3,7 +3,7 @@
#include <string> #include <string>
commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap) commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster) : VCCommand(botCluster)
{ {
this->queueMap = queueMap; this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id); dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id);
@@ -19,19 +19,9 @@ void commands::Skip::operator()(const dpp::slashcommand_t& event) {
} }
v->voiceclient->stop_audio(); v->voiceclient->stop_audio();
v->voiceclient->insert_marker("next marker");
auto findResult = queueMap->find(event.command.guild_id); std::shared_ptr<MusicQueue> queue = getQueue(event);
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);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
queue->play(botCluster);
event.reply("스킵했습니다!"); event.reply("스킵했습니다!");

View File

@@ -4,11 +4,31 @@
#include <opus/opusfile.h> #include <opus/opusfile.h>
#include <thread> #include <thread>
MusicQueue::MusicQueue(FMusicQueueID id) MusicQueue::MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster)
{ {
this->id = id; this->id = id;
repeat = false; repeat = false;
queuePlaying = 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) void MusicQueue::operator+=(FQueueElement operand)
@@ -89,7 +109,7 @@ FMusicQueueID MusicQueue::getId()
return id; return id;
} }
void MusicQueue::markerCallback(std::shared_ptr<dpp::cluster> botCluster) void MusicQueue::markerCallback()
{ {
std::cout << "Music play started\n"; std::cout << "Music play started\n";
@@ -97,14 +117,13 @@ void MusicQueue::markerCallback(std::shared_ptr<dpp::cluster> botCluster)
if (!joinedShard) if (!joinedShard)
{ {
std::cout << "No shard\n"; std::cout << "No shard\n";
queuePlaying = false;
return; return;
} }
if (empty()) if (empty())
{ {
std::cout << "Queue ended\n"; std::cout << "Queue ended\n";
queuePlaying = false; playMutex.unlock();
return; return;
} }
@@ -114,7 +133,6 @@ void MusicQueue::markerCallback(std::shared_ptr<dpp::cluster> botCluster)
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) if (!v || !v->voiceclient || !v->voiceclient->is_ready())
{ {
std::cout << "not in voicechat. quit musicplay"; std::cout << "not in voicechat. quit musicplay";
queuePlaying = false;
return; return;
} }
@@ -124,7 +142,6 @@ void MusicQueue::markerCallback(std::shared_ptr<dpp::cluster> botCluster)
/* If there was an issue reading the file, tell the user and stop */ /* If there was an issue reading the file, tell the user and stop */
if (!track_og) { if (!track_og) {
fprintf(stderr, "Error opening file\n"); fprintf(stderr, "Error opening file\n");
queuePlaying = false;
return; return;
} }
@@ -169,23 +186,19 @@ void MusicQueue::markerCallback(std::shared_ptr<dpp::cluster> botCluster)
std::cout << "audio sending complete\n"; std::cout << "audio sending complete\n";
} }
void MusicQueue::play(std::shared_ptr<dpp::cluster> botCluster) void MusicQueue::play()
{ {
playMutex.lock(); if (!playMutex.try_lock())
if (queuePlaying)
{ {
std::cout << "Already Playing\n"; std::cout << "Already playing\n";
playMutex.unlock();
return; return;
} }
queuePlaying = true;
playMutex.unlock();
dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id); dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id);
if (!joinedShard) if (!joinedShard)
{ {
std::cout << "No shard\n"; std::cout << "No shard\n";
queuePlaying = false; playMutex.unlock();
return; return;
} }
@@ -193,22 +206,9 @@ void MusicQueue::play(std::shared_ptr<dpp::cluster> botCluster)
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) if (!v || !v->voiceclient || !v->voiceclient->is_ready())
{ {
std::cout << "not in voicechat. quit musicplay"; std::cout << "not in voicechat. quit musicplay";
queuePlaying = false; playMutex.unlock();
return; return;
} }
botCluster->on_voice_track_marker([this, botCluster, v](const dpp::voice_track_marker_t &marker) markerCallback();
{
std::cout << marker.track_meta << " Marker reached.\n";
auto music = pop(0);
if (repeat)
{
(*this) += music;
}
markerCallback(botCluster);
});
markerCallback(botCluster);
} }

View File

@@ -4,7 +4,8 @@
using json = nlohmann::json; using json = nlohmann::json;
int main() { int main()
{
json configdocument; json configdocument;
std::ifstream configfile("config.json"); std::ifstream configfile("config.json");
configfile >> configdocument; configfile >> configdocument;