mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 01:45:15 +00:00
큐 출력 스타일 변경
This commit is contained in:
@@ -6,38 +6,30 @@
|
|||||||
namespace bumbleBee {
|
namespace bumbleBee {
|
||||||
class QueuedMusicListEmbedProvider {
|
class QueuedMusicListEmbedProvider {
|
||||||
public:
|
public:
|
||||||
static std::queue<dpp::embed> makeEmbed(std::list<std::shared_ptr<MusicQueueElement>> queue, std::list<std::shared_ptr<MusicQueueElement>>::iterator np, bool repeat) {
|
static std::queue<dpp::embed> makeEmbed(std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue, std::list<std::shared_ptr<MusicQueueElement>>::iterator np, bool repeat) {
|
||||||
std::queue<dpp::embed> returnValue;
|
std::queue<dpp::embed> returnValue;
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator it = queue.begin();
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator it = queue->begin();
|
||||||
if (queue.size() == 0) {
|
if (queue->size() == 0) {
|
||||||
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
|
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
|
||||||
returnValue.push(embed);
|
returnValue.push(embed);
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < std::ceil(queue.size() / 5.0); i++) {
|
for (int i = 0; i < std::ceil(queue->size() / 5.0) && it != queue->end(); i++) {
|
||||||
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
|
dpp::embed embed = makeEmbedPart(queue, np, repeat, it);
|
||||||
returnValue.push(embed);
|
returnValue.push(embed);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int distance(const std::list<std::shared_ptr<MusicQueueElement>>::iterator a, const std::list<std::shared_ptr<MusicQueueElement>>::iterator b) {
|
|
||||||
int i = 0;
|
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator mutatea = a;
|
|
||||||
while (mutatea++ == b)
|
|
||||||
i++;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
static dpp::embed makeEmbedPart(
|
static dpp::embed makeEmbedPart(
|
||||||
std::list<std::shared_ptr<MusicQueueElement>> queue,
|
std::shared_ptr<std::list<std::shared_ptr<MusicQueueElement>>> queue,
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator np,
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator np,
|
||||||
bool repeat,
|
bool repeat,
|
||||||
std::list<std::shared_ptr<MusicQueueElement>>::iterator startIter) {
|
std::list<std::shared_ptr<MusicQueueElement>>::iterator &startIter) {
|
||||||
dpp::embed embed = dpp::embed()
|
dpp::embed embed = dpp::embed()
|
||||||
.set_color(dpp::colors::sti_blue);
|
.set_color(dpp::colors::sti_blue);
|
||||||
|
|
||||||
if (queue.begin() == queue.end()) {
|
if (queue->begin() == queue->end()) {
|
||||||
embed
|
embed
|
||||||
.set_title("큐가 비었습니다!")
|
.set_title("큐가 비었습니다!")
|
||||||
.set_timestamp(time(0));
|
.set_timestamp(time(0));
|
||||||
@@ -48,10 +40,10 @@ private:
|
|||||||
return embed;
|
return embed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int startIndex = distance(queue.begin(), startIter) + 1;
|
int startIndex = std::distance(queue->begin(), startIter) + 1;
|
||||||
int index = startIndex;
|
int index = startIndex;
|
||||||
|
|
||||||
for (; (index < startIndex + 5) && startIter != queue.end() && index < queue.size()+1; startIter++, index++) { //iter로 순회하면 왠지 모르게 이상한 값을 읽을 때가 있음 이유는 나도 몰?루
|
for (; (index < startIndex + 5) && startIter != queue->end() && index < queue->size()+1; startIter++, index++) { //iter로 순회하면 왠지 모르게 이상한 값을 읽을 때가 있음 이유는 나도 몰?루
|
||||||
if (*startIter == *np)
|
if (*startIter == *np)
|
||||||
embed.add_field (
|
embed.add_field (
|
||||||
"np",
|
"np",
|
||||||
@@ -72,7 +64,7 @@ private:
|
|||||||
.add_field("","");
|
.add_field("","");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startIter == queue.end() || index >= queue.size()+1) {
|
if (startIter == queue->end() || index >= queue->size()+1) {
|
||||||
embed.set_timestamp(time(0));
|
embed.set_timestamp(time(0));
|
||||||
if (repeat)
|
if (repeat)
|
||||||
embed.add_field(":repeat:","");
|
embed.add_field(":repeat:","");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <Utils/ConsoleUtils.hpp>
|
#include <Utils/ConsoleUtils.hpp>
|
||||||
#include <Settings/SettingsManager.hpp>
|
#include <Settings/SettingsManager.hpp>
|
||||||
#include <dpp/nlohmann/json.hpp>
|
#include <dpp/nlohmann/json.hpp>
|
||||||
|
#include <Utils/QueuedMusicListEmbedProvider.hpp>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace bumbleBee::commands {
|
namespace bumbleBee::commands {
|
||||||
@@ -40,10 +41,9 @@ namespace bumbleBee::commands {
|
|||||||
else
|
else
|
||||||
msg.content = "큐에 다음 곡을 추가했습니다:";
|
msg.content = "큐에 다음 곡을 추가했습니다:";
|
||||||
|
|
||||||
while (!ids.empty()) {
|
if (!ids.empty()) {
|
||||||
if (ids.front() == "") {
|
if (ids.front() == "") {
|
||||||
ids.pop();
|
ids.pop();
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* file = popen((SettingsManager::getYTDLP_CMD() +
|
FILE* file = popen((SettingsManager::getYTDLP_CMD() +
|
||||||
@@ -92,6 +92,115 @@ namespace bumbleBee::commands {
|
|||||||
ids.pop();
|
ids.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ids.empty()) {
|
||||||
|
std::thread t([](
|
||||||
|
std::queue<std::string> ids,
|
||||||
|
dpp::snowflake guildId,
|
||||||
|
dpp::snowflake channelId,
|
||||||
|
std::string query,
|
||||||
|
dpp::user user,
|
||||||
|
dpp::cluster* cluster,
|
||||||
|
std::shared_ptr<MusicPlayManager> manager
|
||||||
|
) {
|
||||||
|
while (!ids.empty()) {
|
||||||
|
if (ids.front() == "") {
|
||||||
|
ids.pop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* file = popen((SettingsManager::getYTDLP_CMD() +
|
||||||
|
" --default-search ytsearch --flat-playlist --skip-download --quiet --ignore-errors -J http://youtu.be/" + ids.front()).c_str(), "r");
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
char buffer[1024];
|
||||||
|
size_t bytesRead;
|
||||||
|
|
||||||
|
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
|
||||||
|
oss.write(buffer, bytesRead);
|
||||||
|
}
|
||||||
|
pclose(file);
|
||||||
|
|
||||||
|
std::istringstream iss(oss.str());
|
||||||
|
nlohmann::json videoDataJson;
|
||||||
|
iss >> videoDataJson;
|
||||||
|
|
||||||
|
time_t SongLength = int(videoDataJson["duration"]);
|
||||||
|
char SongLengthStr[13];
|
||||||
|
tm t;
|
||||||
|
t.tm_mday = SongLength / 86400;
|
||||||
|
t.tm_hour = (SongLength % 86400)/3600;
|
||||||
|
t.tm_min = (SongLength % 3600)/60;
|
||||||
|
t.tm_sec = SongLength%60;
|
||||||
|
if (t.tm_mday > 0)
|
||||||
|
strftime(SongLengthStr, sizeof(SongLengthStr), "%d:%H:%M:%S", &t);
|
||||||
|
else if (t.tm_hour > 0)
|
||||||
|
strftime(SongLengthStr, sizeof(SongLengthStr), "%H:%M:%S", &t);
|
||||||
|
else
|
||||||
|
strftime(SongLengthStr, sizeof(SongLengthStr), "%M:%S", &t);
|
||||||
|
|
||||||
|
dpp::embed embed = dpp::embed()
|
||||||
|
.set_color(dpp::colors::sti_blue)
|
||||||
|
.set_title(std::string(videoDataJson["title"]))
|
||||||
|
.set_description(std::string(videoDataJson["uploader"]))
|
||||||
|
.set_url(std::string(videoDataJson["webpage_url"]))
|
||||||
|
.set_image(std::string(videoDataJson["thumbnail"]))
|
||||||
|
.add_field(
|
||||||
|
"길이",
|
||||||
|
SongLengthStr,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
auto music = std::make_shared<MusicQueueElement>(ids.front(), query, user, embed);
|
||||||
|
|
||||||
|
cluster->log(dpp::ll_info, "Enqueuing " + music->embed.title + " - " + music->id);
|
||||||
|
manager->queue_music(guildId, music);
|
||||||
|
ids.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::mutex messageorder;
|
||||||
|
std::unique_lock lock(messageorder);
|
||||||
|
std::condition_variable messageSentCondition; // 개씨발 코드 개더러워 ;;
|
||||||
|
bool messagesent = false;
|
||||||
|
auto queue = manager->getQueue(guildId);
|
||||||
|
auto queued = QueuedMusicListEmbedProvider::makeEmbed(queue.first, queue.second, manager->getRepeat(guildId));
|
||||||
|
if (!queued.empty()) {
|
||||||
|
dpp::message followMsg(channelId, "현재 큐에 있는 항목:");
|
||||||
|
|
||||||
|
followMsg.add_embed(queued.front());
|
||||||
|
messagesent = false;
|
||||||
|
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
|
||||||
|
messagesent = true;
|
||||||
|
messageSentCondition.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
messageSentCondition.wait(lock, [&](){ return messagesent; });
|
||||||
|
queued.pop();
|
||||||
|
}
|
||||||
|
while (!queued.empty()) {
|
||||||
|
dpp::message followMsg(channelId, "");
|
||||||
|
|
||||||
|
followMsg.add_embed(queued.front());
|
||||||
|
messagesent = false;
|
||||||
|
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
|
||||||
|
messagesent = true;
|
||||||
|
messageSentCondition.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
messageSentCondition.wait(lock, [&](){ return messagesent; });
|
||||||
|
queued.pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ids,
|
||||||
|
event.command.guild_id,
|
||||||
|
event.command.channel_id,
|
||||||
|
query,
|
||||||
|
event.command.usr,
|
||||||
|
event.from->creator,
|
||||||
|
musicManager);
|
||||||
|
|
||||||
|
t.detach();
|
||||||
|
}
|
||||||
|
|
||||||
if (!musics.empty()) {
|
if (!musics.empty()) {
|
||||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->embed.title + " - " + musics.front()->id);
|
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->embed.title + " - " + musics.front()->id);
|
||||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
musicManager->queue_music(event.command.guild_id, musics.front());
|
||||||
@@ -100,17 +209,6 @@ namespace bumbleBee::commands {
|
|||||||
|
|
||||||
event.edit_original_response(msg);
|
event.edit_original_response(msg);
|
||||||
musicManager->queuedCondition.notify_all();
|
musicManager->queuedCondition.notify_all();
|
||||||
|
|
||||||
while (!musics.empty()) {
|
|
||||||
event.from->creator->log(dpp::ll_info, "Enqueuing " + musics.front()->embed.title + " - " + musics.front()->id);
|
|
||||||
dpp::message followMsg(event.command.channel_id, "");
|
|
||||||
|
|
||||||
followMsg.add_embed(musics.front()->embed);
|
|
||||||
event.from->creator->message_create(followMsg); // 어차피 원래 메시지를 지정해서 수정할 것이기 때문에 먼저 팔로잉 메시지를 작성해도 상관없음.
|
|
||||||
|
|
||||||
musicManager->queue_music(event.command.guild_id, musics.front());
|
|
||||||
musics.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg.content = "검색 결과가 없습니다";
|
msg.content = "검색 결과가 없습니다";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace bumbleBee::commands {
|
|||||||
dpp::message msg;
|
dpp::message msg;
|
||||||
dpp::embed embed;
|
dpp::embed embed;
|
||||||
|
|
||||||
auto queued = QueuedMusicListEmbedProvider::makeEmbed(*queue.first, queue.second, musicManager->getRepeat(event.command.guild_id));
|
auto queued = QueuedMusicListEmbedProvider::makeEmbed(queue.first, queue.second, musicManager->getRepeat(event.command.guild_id));
|
||||||
|
|
||||||
// if (queue.first.size() == 0) {
|
// if (queue.first.size() == 0) {
|
||||||
// msg.add_embed(queued.front());
|
// msg.add_embed(queued.front());
|
||||||
@@ -32,12 +32,38 @@ namespace bumbleBee::commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::thread t([](std::queue<dpp::embed> queued, dpp::snowflake channel_id, dpp::cluster* cluster) {
|
std::thread t([](std::queue<dpp::embed> queued, dpp::snowflake channel_id, dpp::cluster* cluster) {
|
||||||
for (; !queued.empty(); queued.pop()) {
|
std::mutex messageorder;
|
||||||
dpp::message followMsg(channel_id, "현재 큐에 있는 항목:");
|
std::unique_lock lock(messageorder);
|
||||||
|
std::condition_variable messageSentCondition;
|
||||||
|
bool messagesent = false;
|
||||||
|
if (!queued.empty()) {
|
||||||
|
dpp::message followMsg(channel_id, "현재 큐에 있는 항목:");
|
||||||
|
|
||||||
followMsg.add_embed(queued.front());
|
followMsg.add_embed(queued.front());
|
||||||
cluster->message_create(followMsg);
|
messagesent = false;
|
||||||
}
|
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
|
||||||
|
messagesent = true;
|
||||||
|
messageSentCondition.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
messageSentCondition.wait(lock, [&](){ return messagesent; });
|
||||||
|
|
||||||
|
queued.pop();
|
||||||
|
}
|
||||||
|
while (!queued.empty()) {
|
||||||
|
dpp::message followMsg(channel_id, "");
|
||||||
|
|
||||||
|
followMsg.add_embed(queued.front());
|
||||||
|
|
||||||
|
messagesent = false;
|
||||||
|
cluster->message_create(followMsg, [&](const dpp::confirmation_callback_t &callback){
|
||||||
|
messagesent = true;
|
||||||
|
messageSentCondition.notify_all();
|
||||||
|
});
|
||||||
|
|
||||||
|
messageSentCondition.wait(lock, [&](){ return messagesent; });
|
||||||
|
queued.pop();
|
||||||
|
}
|
||||||
}, queued, event.command.channel_id, event.from->creator);
|
}, queued, event.command.channel_id, event.from->creator);
|
||||||
t.detach();
|
t.detach();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user