mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-28 02:25:13 +00:00
큐 완전 개혁
This commit is contained in:
@@ -7,114 +7,122 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Commands {
|
||||
Play::Play(std::shared_ptr<BumbleCeepp> Bot) {
|
||||
this->Bot = Bot;
|
||||
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: ICommand(botCluster)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
|
||||
|
||||
dpp::slashcommand Command = dpp::slashcommand("p", "노래 재생", Bot->BotCluster->me.id);
|
||||
command.add_option(
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botCluster->me.id)
|
||||
);
|
||||
|
||||
Command.add_option(
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", Bot->BotCluster->me.id)
|
||||
);
|
||||
commandObjectVector.push_back(command);
|
||||
}
|
||||
|
||||
CommandObjectVector.push_back(Command);
|
||||
}
|
||||
|
||||
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";
|
||||
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
||||
std::cout << "다운로드 완료" << "\n";
|
||||
Bot->YTDLMutex.unlock();
|
||||
|
||||
dpp::message msg(Event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
|
||||
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_sec = SongLength%60;
|
||||
t.tm_min = SongLength/60;
|
||||
t.tm_hour = SongLength/360;
|
||||
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"]),
|
||||
Event.command.guild_id,
|
||||
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
|
||||
)
|
||||
};
|
||||
Bot->enqueue(Data);
|
||||
RequestedMusic.push(Data);
|
||||
}
|
||||
idfile.close();
|
||||
//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();
|
||||
|
||||
Bot->BotCluster->message_create(followMsg);
|
||||
}
|
||||
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(); });
|
||||
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::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();
|
||||
|
||||
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);
|
||||
}
|
||||
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
|
||||
|
||||
std::cout << "다운로드 시작" << "\n";
|
||||
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
||||
std::cout << "다운로드 완료" << "\n";
|
||||
|
||||
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
|
||||
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_sec = SongLength%60;
|
||||
t.tm_min = SongLength/60;
|
||||
t.tm_hour = SongLength/360;
|
||||
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);
|
||||
}
|
||||
idfile.close();
|
||||
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);
|
||||
}
|
||||
|
||||
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(botCluster); });
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user