diff --git a/include/BumbleCeepp.hpp b/include/BumbleCeepp.hpp index ad449f0..da9d30f 100644 --- a/include/BumbleCeepp.hpp +++ b/include/BumbleCeepp.hpp @@ -13,6 +13,7 @@ public: return &Instance; } void enqueue(struct FQueueElement Element); + struct FQueueElement QueueDelete(int Index); void QueuePlay(); diff --git a/include/Commands.hpp b/include/Commands.hpp index 4455f6f..b72482f 100644 --- a/include/Commands.hpp +++ b/include/Commands.hpp @@ -6,5 +6,6 @@ #include #include #include +#include #endif \ No newline at end of file diff --git a/include/Commands/Delete.hpp b/include/Commands/Delete.hpp new file mode 100644 index 0000000..e7061da --- /dev/null +++ b/include/Commands/Delete.hpp @@ -0,0 +1,19 @@ +#ifndef _DELETE_HPP_ +#define _DELETE_HPP_ +#include +#include +#include + +namespace Commands { + class Delete : public ICommand { + public: + Delete(std::shared_ptr Bot); + + void operator()(const dpp::slashcommand_t& Event) {} + void operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event); + private: + std::shared_ptr Bot; + }; +} + +#endif \ No newline at end of file diff --git a/src/Bot.cpp b/src/Bot.cpp index 7aec4cb..8e348d4 100644 --- a/src/Bot.cpp +++ b/src/Bot.cpp @@ -20,7 +20,7 @@ void IBot::OnReady(const dpp::ready_t& Event) { if (!dpp::run_once()) return; - //bot->global_bulk_command_delete(); + //BotCluster->global_bulk_command_delete(); for (auto command : CommandsArray) { for (auto Alias : command->CommandObjectVector) { diff --git a/src/BumbleCeepp.cpp b/src/BumbleCeepp.cpp index 1885913..6cb0954 100644 --- a/src/BumbleCeepp.cpp +++ b/src/BumbleCeepp.cpp @@ -16,6 +16,17 @@ void BumbleCeepp::enqueue(struct FQueueElement Element) { QueueMutex.unlock(); } +struct FQueueElement BumbleCeepp::QueueDelete(int Index) { + QueueMutex.lock(); + auto iter = MusicQueue.begin(); + std::advance(iter, Index); + auto ReturnValue = *iter; + MusicQueue.erase(iter); + QueueMutex.unlock(); + + return ReturnValue; +} + void BumbleCeepp::QueuePlay(){ if (QueuePlaying) { return; @@ -33,11 +44,6 @@ void BumbleCeepp::QueuePlay(){ FQueueElement Music = MusicQueue.front(); QueueMutex.unlock(); - std::cout << "Queue:\n"; - for (auto iter = MusicQueue.begin(); iter != MusicQueue.end(); iter++) { - std::cout << iter->title << "\n"; - } - dpp::voiceconn* v = JoinedShared->get_voice(Music.guild_id); if (!v || !v->voiceclient || !v->voiceclient->is_ready()) { return; @@ -95,6 +101,10 @@ void BumbleCeepp::QueuePlay(){ while(v->voiceclient->is_playing()) {} QueueMutex.lock(); + if (MusicQueue.empty()) { + QueueMutex.unlock(); + break; + } MusicQueue.pop_front(); QueueMutex.unlock(); diff --git a/src/Commands/Delete.cpp b/src/Commands/Delete.cpp new file mode 100644 index 0000000..c39142f --- /dev/null +++ b/src/Commands/Delete.cpp @@ -0,0 +1,39 @@ +#include +#include + +namespace Commands { + Delete::Delete(std::shared_ptr Bot) { + this->Bot = Bot; + + dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", Bot->BotCluster->me.id); + + Command.add_option( + dpp::command_option(dpp::co_string, "pos", "큐 번호", Bot->BotCluster->me.id) + ); + + CommandObjectVector.push_back(Command); + } + + void Delete::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { + std::string Pos = std::get(Event.get_parameter("pos")); + if (!atoi(Pos.c_str())) { + dpp::message msg(Event.command.channel_id, "현재 재생중인 곡은 삭제할 수 없습니다!"); + Event.reply(msg); + return; + } + + auto PopedElement = Bot->QueueDelete(atoi(Pos.c_str())); + + dpp::embed embed = dpp::embed() + .set_title(PopedElement.title) + .set_description(PopedElement.description) + .set_color(dpp::colors::sti_blue) + .set_image(PopedElement.thumbnail) + .set_timestamp(time(0)); + + dpp::message msg(Event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:"); + msg.add_embed(embed); + + Event.reply(msg); + } +} \ No newline at end of file diff --git a/src/Commands/Leave.cpp b/src/Commands/Leave.cpp index 4f29765..43eec8f 100644 --- a/src/Commands/Leave.cpp +++ b/src/Commands/Leave.cpp @@ -5,11 +5,9 @@ namespace Commands { Leave::Leave(std::shared_ptr Bot) { this->Bot = Bot; - dpp::slashcommand Command = dpp::slashcommand("leave", "음챗을 떠납니다", Bot->BotCluster->me.id); - dpp::slashcommand Alias = dpp::slashcommand("l", "음챗을 떠납니다", Bot->BotCluster->me.id); + dpp::slashcommand Command = dpp::slashcommand("l", "음챗을 떠납니다", Bot->BotCluster->me.id); CommandObjectVector.push_back(Command); - CommandObjectVector.push_back(Alias); } void Leave::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { diff --git a/src/Commands/Play.cpp b/src/Commands/Play.cpp index 1a639c5..c61b7cb 100644 --- a/src/Commands/Play.cpp +++ b/src/Commands/Play.cpp @@ -1,4 +1,3 @@ -// #include #include #include #include @@ -11,20 +10,13 @@ namespace Commands { Play::Play(std::shared_ptr Bot) { this->Bot = Bot; - dpp::slashcommand Command = dpp::slashcommand("play", "노래 재생", Bot->BotCluster->me.id); + dpp::slashcommand Command = dpp::slashcommand("p", "노래 재생", Bot->BotCluster->me.id); Command.add_option( dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", Bot->BotCluster->me.id) ); - dpp::slashcommand Alias = dpp::slashcommand("p", "노래 재생", Bot->BotCluster->me.id); - - Alias.add_option( - dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", Bot->BotCluster->me.id) - ); - CommandObjectVector.push_back(Command); - CommandObjectVector.push_back(Alias); } void Play::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { diff --git a/src/Commands/Queue.cpp b/src/Commands/Queue.cpp index be0ae2f..9c16f01 100644 --- a/src/Commands/Queue.cpp +++ b/src/Commands/Queue.cpp @@ -5,26 +5,69 @@ namespace Commands { Queue::Queue(std::shared_ptr Bot) { this->Bot = Bot; - dpp::slashcommand Command = dpp::slashcommand("queue", "노래 예약 큐 확인", Bot->BotCluster->me.id); - dpp::slashcommand Alias = dpp::slashcommand("q", "노래 예약 큐 확인", Bot->BotCluster->me.id); + dpp::slashcommand Command = dpp::slashcommand("q", "노래 예약 큐 확인", Bot->BotCluster->me.id); CommandObjectVector.push_back(Command); - CommandObjectVector.push_back(Alias); } void Queue::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { + if (MusicQueue.empty()) { + dpp::embed embed = dpp::embed() + .set_title("큐가 비었습니다!") + .set_color(dpp::colors::sti_blue) + .set_timestamp(time(0)); + + if (Bot->Repeat) + embed.add_field(":repeat:",""); + + dpp::message msg(Event.command.channel_id, "현재 큐에 있는 항목:"); + msg.add_embed(embed); + + Event.reply(msg); + return; + } + dpp::embed embed = dpp::embed() .set_title("큐 항목:") .set_color(dpp::colors::sti_blue) .set_timestamp(time(0)); + int i = 0; + char number[30] = {0, }; + for (auto iter = MusicQueue.begin(); iter != MusicQueue.end(); iter++) { + if (!i) { + embed.add_field( + "현재 재생 중", + "", + true + ); + } + else { + sprintf(number, "%d", i); + embed.add_field( + number, + "", + true + ); + } + embed.add_field( iter->title, - iter->description + iter->description, + true + ) + .add_field( + "", + "" ); + + i++; } + if (Bot->Repeat) + embed.add_field(":repeat:",""); + dpp::message msg(Event.command.channel_id, "현재 큐에 있는 항목:"); msg.add_embed(embed); diff --git a/src/Commands/Repeat.cpp b/src/Commands/Repeat.cpp index 519bdf7..4abf086 100644 --- a/src/Commands/Repeat.cpp +++ b/src/Commands/Repeat.cpp @@ -6,11 +6,9 @@ namespace Commands { Repeat::Repeat(std::shared_ptr Bot) { this->Bot = Bot; - dpp::slashcommand Command = dpp::slashcommand("repeat", "반복 켜기/끄기", Bot->BotCluster->me.id); - dpp::slashcommand Alias = dpp::slashcommand("r", "반복 켜기/끄기", Bot->BotCluster->me.id); + dpp::slashcommand Command = dpp::slashcommand("r", "반복 켜기/끄기", Bot->BotCluster->me.id); CommandObjectVector.push_back(Command); - CommandObjectVector.push_back(Alias); } void Repeat::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { diff --git a/src/Commands/Skip.cpp b/src/Commands/Skip.cpp index 9b58c14..22c223c 100644 --- a/src/Commands/Skip.cpp +++ b/src/Commands/Skip.cpp @@ -6,11 +6,9 @@ namespace Commands { Skip::Skip(std::shared_ptr Bot) { this->Bot = Bot; - dpp::slashcommand Command = dpp::slashcommand("skip", "현재곡 스킵", Bot->BotCluster->me.id); - dpp::slashcommand Alias = dpp::slashcommand("s", "현재곡 스킵", Bot->BotCluster->me.id); + dpp::slashcommand Command = dpp::slashcommand("s", "현재곡 스킵", Bot->BotCluster->me.id); CommandObjectVector.push_back(Command); - CommandObjectVector.push_back(Alias); } void Skip::operator()(std::list& MusicQueue, const dpp::slashcommand_t& Event) { diff --git a/src/main.cpp b/src/main.cpp index 1fd3595..3483743 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,12 +16,14 @@ int main() { Commands::Queue Command3(BumbleBee); Commands::Skip Command4(BumbleBee); Commands::Leave Command5(BumbleBee); + Commands::Delete Command6(BumbleBee); BumbleBee->AddCommand(Command1); BumbleBee->AddCommand(Command2); BumbleBee->AddCommand(Command3); BumbleBee->AddCommand(Command4); BumbleBee->AddCommand(Command5); + BumbleBee->AddCommand(Command6); BumbleBee->Start();