mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
음챗 나가기 구현 완료
This commit is contained in:
@@ -21,7 +21,6 @@ void BumbleCeepp::QueuePlay(){
|
||||
return;
|
||||
}
|
||||
QueuePlaying = true;
|
||||
QueuePlayMutex.lock();
|
||||
|
||||
std::thread T1([this] (){
|
||||
dpp::discord_client* JoinedShared = BotCluster->get_shard(VoiceJoinedShardId);
|
||||
@@ -34,13 +33,18 @@ 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;
|
||||
}
|
||||
|
||||
/* load the audio file with oggz */
|
||||
OGGZ *track_og = oggz_open((std::string(Music.FileName.c_str()) + ".ogg").c_str(), OGGZ_READ);
|
||||
OGGZ *track_og = oggz_open(("Music/" + std::string(Music.FileName.c_str()) + ".ogg").c_str(), OGGZ_READ);
|
||||
|
||||
/* If there was an issue reading the file, tell the user and stop */
|
||||
if (!track_og) {
|
||||
@@ -100,8 +104,6 @@ void BumbleCeepp::QueuePlay(){
|
||||
QueueMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
QueuePlayMutex.unlock();
|
||||
QueuePlaying = false;
|
||||
|
||||
std::cout << "Queue ended\n";
|
||||
|
||||
Binary file not shown.
31
src/Commands/Leave.cpp
Normal file
31
src/Commands/Leave.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <Commands/Leave.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace Commands {
|
||||
Leave::Leave(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
|
||||
dpp::slashcommand Command = dpp::slashcommand("leave", "음챗을 떠납니다", Bot->BotCluster->me.id);
|
||||
dpp::slashcommand Alias = dpp::slashcommand("l", "음챗을 떠납니다", Bot->BotCluster->me.id);
|
||||
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
void Leave::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
std::cout << "disconnecting..";
|
||||
|
||||
dpp::voiceconn* v = Event.from->get_voice(Event.command.guild_id);
|
||||
|
||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||
return;
|
||||
}
|
||||
|
||||
v->voiceclient->stop_audio();
|
||||
Event.from->disconnect_voice(Event.command.guild_id);
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "음성 채팅방을 떠납니다!");
|
||||
|
||||
Event.reply(msg);
|
||||
}
|
||||
}
|
||||
@@ -7,97 +7,105 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
Play::Play(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
namespace Commands {
|
||||
Play::Play(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
|
||||
dpp::slashcommand Command = dpp::slashcommand("play", "노래 재생", Bot->BotCluster->me.id);
|
||||
dpp::slashcommand Command = dpp::slashcommand("play", "노래 재생", Bot->BotCluster->me.id);
|
||||
|
||||
Command.add_option(
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", 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);
|
||||
dpp::slashcommand Alias = dpp::slashcommand("p", "노래 재생", Bot->BotCluster->me.id);
|
||||
|
||||
Alias.add_option(
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", 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);
|
||||
}
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
void Play::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
if (std::holds_alternative<std::monostate>(Event.get_parameter("query"))) {
|
||||
Event.reply("노래를 재생하려면 좀 노래를 넣고 재생시켜라 게이야");
|
||||
void Play::operator()(std::list<FQueueElement>& MusicQueue, 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 (!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::cout << "query: " << Query << "\n";
|
||||
|
||||
Event.thinking();
|
||||
|
||||
Bot->YTDLMutex.lock();
|
||||
std::cout << "다운로드 시작" << "\n";
|
||||
system(("./yt-dlp -o temp -w --write-info-json -f 251 " + Query + " & wait").c_str());
|
||||
std::cout << "다운로드 완료" << "\n";
|
||||
|
||||
json document;
|
||||
std::ifstream infofile("temp.info.json");
|
||||
infofile >> document;
|
||||
infofile.close();
|
||||
system("rm -f temp.info.json");
|
||||
|
||||
system(("yes n 2>/dev/null | ffmpeg -hide_banner -i temp -c copy Music/" + std::string(to_string(document["id"])) + ".ogg").c_str());
|
||||
system("rm -f temp");
|
||||
|
||||
Bot->YTDLMutex.unlock();
|
||||
|
||||
FQueueElement Data = {std::string(document["title"]),
|
||||
std::string(document["uploader"]),
|
||||
std::string(document["id"]),
|
||||
std::string(document["thumbnail"]),
|
||||
to_string(document["duration"]),
|
||||
Event.command.guild_id};
|
||||
|
||||
Bot->enqueue(Data);
|
||||
std::cout << "queued\n";
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
|
||||
time_t SongLength = int(document["duration"]);
|
||||
char SongLengthStr[10];
|
||||
tm t;
|
||||
t.tm_sec = SongLength%60;
|
||||
t.tm_min = SongLength/60;
|
||||
t.tm_hour = SongLength/360;
|
||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
||||
|
||||
msg.add_embed(dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_title(document["title"])
|
||||
.set_description(document["uploader"])
|
||||
.set_url(Query)
|
||||
.set_image(document["thumbnail"])
|
||||
.add_field(
|
||||
"길이",
|
||||
SongLengthStr,
|
||||
true
|
||||
));
|
||||
|
||||
Event.edit_original_response(msg);
|
||||
|
||||
std::cout << "replied\n";
|
||||
|
||||
dpp::voiceconn* v = Event.from->get_voice(Event.command.guild_id);
|
||||
|
||||
Bot->VoiceJoinedShardId = Event.from->shard_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()) {
|
||||
return Bot->QueuePlay();
|
||||
}
|
||||
|
||||
Bot->BotCluster->on_voice_ready([this](const dpp::voice_ready_t& Voice){ Bot->QueuePlay(); });
|
||||
return;
|
||||
}
|
||||
|
||||
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
|
||||
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"));
|
||||
|
||||
// Event.thinking(false, [](const dpp::confirmation_callback_t &Callback) {
|
||||
// return dpp::confirmation();
|
||||
// });
|
||||
|
||||
system(("./yt-dlp -o temp --write-info-json -f 251 " + Query).c_str());
|
||||
|
||||
json document;
|
||||
std::ifstream infofile("temp.info.json");
|
||||
infofile >> document;
|
||||
system("rm -f temp.info.json");
|
||||
|
||||
system(("ffmpeg -y -i temp -c copy " + std::string(to_string(document["id"])) + ".ogg").c_str());
|
||||
system("rm -f temp");
|
||||
|
||||
FQueueElement Data = {std::string(document["title"]),
|
||||
std::string(document["uploader"]),
|
||||
std::string(document["id"]),
|
||||
std::string(document["thumbnail"]),
|
||||
to_string(document["duration"]),
|
||||
Event.command.guild_id};
|
||||
|
||||
Bot->enqueue(Data);
|
||||
std::cout << "queued\n";
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
|
||||
time_t SongLength = int(document["duration"]);
|
||||
char SongLengthStr[10];
|
||||
tm t;
|
||||
t.tm_sec = SongLength%60;
|
||||
t.tm_min = SongLength/60;
|
||||
t.tm_hour = SongLength/360;
|
||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
||||
|
||||
msg.add_embed(dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_title(document["title"])
|
||||
.set_description(document["uploader"])
|
||||
.set_url(Query)
|
||||
.set_image(document["thumbnail"])
|
||||
.add_field(
|
||||
"길이",
|
||||
SongLengthStr,
|
||||
true
|
||||
));
|
||||
|
||||
Event.reply(msg);
|
||||
|
||||
std::cout << "replied\n";
|
||||
|
||||
dpp::voiceconn* v = Event.from->get_voice(Event.command.guild_id);
|
||||
|
||||
Bot->VoiceJoinedShardId = Event.from->shard_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()) {
|
||||
return Bot->QueuePlay();
|
||||
}
|
||||
|
||||
Bot->BotCluster->on_voice_ready([this](const dpp::voice_ready_t& Voice){ Bot->QueuePlay(); });
|
||||
return;
|
||||
}
|
||||
@@ -1,31 +1,33 @@
|
||||
#include <Commands/Queue.hpp>
|
||||
#include <iostream>
|
||||
|
||||
Queue::Queue(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
namespace Commands {
|
||||
Queue::Queue(std::shared_ptr<BumbleCeepp> 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("queue", "노래 예약 큐 확인", Bot->BotCluster->me.id);
|
||||
dpp::slashcommand Alias = dpp::slashcommand("q", "노래 예약 큐 확인", Bot->BotCluster->me.id);
|
||||
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
void Queue::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_title("큐 항목:")
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_timestamp(time(0));
|
||||
|
||||
for (auto iter = MusicQueue.begin(); iter != MusicQueue.end(); iter++) {
|
||||
embed.add_field(
|
||||
iter->title,
|
||||
iter->description
|
||||
);
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "현재 큐에 있는 항목:");
|
||||
msg.add_embed(embed);
|
||||
void Queue::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_title("큐 항목:")
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_timestamp(time(0));
|
||||
|
||||
Event.reply(msg);
|
||||
for (auto iter = MusicQueue.begin(); iter != MusicQueue.end(); iter++) {
|
||||
embed.add_field(
|
||||
iter->title,
|
||||
iter->description
|
||||
);
|
||||
}
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "현재 큐에 있는 항목:");
|
||||
msg.add_embed(embed);
|
||||
|
||||
Event.reply(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,28 @@
|
||||
#include <Commands/Repeat.hpp>
|
||||
#include <dpp/dpp.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
using json = nlohmann::json;
|
||||
namespace Commands {
|
||||
Repeat::Repeat(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
|
||||
Repeat::Repeat(std::shared_ptr<BumbleCeepp> 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("repeat", "반복 켜기/끄기", Bot->BotCluster->me.id);
|
||||
dpp::slashcommand Alias = dpp::slashcommand("r", "반복 켜기/끄기", Bot->BotCluster->me.id);
|
||||
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
void Repeat::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
if (Bot->Repeat) {
|
||||
Event.reply("반복을 껐습니다.");
|
||||
Bot->Repeat = false;
|
||||
}
|
||||
else {
|
||||
Event.reply("반복을 켰습니다.");
|
||||
Bot->Repeat = true;
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
return;
|
||||
void Repeat::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
if (Bot->Repeat) {
|
||||
Event.reply("반복을 껐습니다.");
|
||||
Bot->Repeat = false;
|
||||
}
|
||||
else {
|
||||
Event.reply("반복을 켰습니다.");
|
||||
Bot->Repeat = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,29 @@
|
||||
#include <Commands/Skip.hpp>
|
||||
#include <dpp/dpp.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
using json = nlohmann::json;
|
||||
namespace Commands {
|
||||
Skip::Skip(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
|
||||
Skip::Skip(std::shared_ptr<BumbleCeepp> 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("skip", "현재곡 스킵", Bot->BotCluster->me.id);
|
||||
dpp::slashcommand Alias = dpp::slashcommand("s", "현재곡 스킵", Bot->BotCluster->me.id);
|
||||
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
void Skip::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
dpp::voiceconn* v = Event.from->get_voice(Event.command.guild_id);
|
||||
|
||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||
return;
|
||||
CommandObjectVector.push_back(Command);
|
||||
CommandObjectVector.push_back(Alias);
|
||||
}
|
||||
|
||||
v->voiceclient->stop_audio();
|
||||
void Skip::operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) {
|
||||
dpp::voiceconn* v = Event.from->get_voice(Event.command.guild_id);
|
||||
|
||||
Event.reply("스킵했습니다!");
|
||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
v->voiceclient->stop_audio();
|
||||
|
||||
Event.reply("스킵했습니다!");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
10
src/main.cpp
10
src/main.cpp
@@ -11,15 +11,17 @@ int main() {
|
||||
|
||||
std::shared_ptr<BumbleCeepp> BumbleBee(BumbleCeepp::GetInstance(configdocument["token"]));
|
||||
|
||||
Play Command1(BumbleBee);
|
||||
Repeat Command2(BumbleBee);
|
||||
Queue Command3(BumbleBee);
|
||||
Skip Command4(BumbleBee);
|
||||
Commands::Play Command1(BumbleBee);
|
||||
Commands::Repeat Command2(BumbleBee);
|
||||
Commands::Queue Command3(BumbleBee);
|
||||
Commands::Skip Command4(BumbleBee);
|
||||
Commands::Leave Command5(BumbleBee);
|
||||
|
||||
BumbleBee->AddCommand(Command1);
|
||||
BumbleBee->AddCommand(Command2);
|
||||
BumbleBee->AddCommand(Command3);
|
||||
BumbleBee->AddCommand(Command4);
|
||||
BumbleBee->AddCommand(Command5);
|
||||
|
||||
BumbleBee->Start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user