mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-12-17 04:53:27 +00:00
코드 갈어엎기(사용성 개박살났으니 빌드는 이전 것으로 할 것.)
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
#include <Commands/CommandType.hpp>
|
||||
|
||||
commands::ICommand::ICommand(std::shared_ptr<dpp::cluster> 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;
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
#include <Commands/Delete.hpp>
|
||||
#include <iostream>
|
||||
|
||||
commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
commands::Delete::Delete(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id);
|
||||
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botID);
|
||||
|
||||
Command.add_option(
|
||||
dpp::command_option(dpp::co_string, "pos", "큐 번호", botCluster->me.id)
|
||||
dpp::command_option(dpp::co_string, "pos", "큐 번호", botID)
|
||||
);
|
||||
|
||||
commandObjectVector.push_back(Command);
|
||||
@@ -23,37 +22,34 @@ void commands::Delete::operator()(const dpp::slashcommand_t& event)
|
||||
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
|
||||
event.thinking();
|
||||
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
|
||||
auto index = atoi(Pos.c_str());
|
||||
|
||||
int queueSize = queue->size();
|
||||
auto vc = event.from->connecting_voice_channels.find(event.command.guild_id)->second->voiceclient;
|
||||
int remainingSongsCount = vc->get_tracks_remaining() - 1;
|
||||
std::vector<std::string> queuedSongs = vc->get_marker_metadata();
|
||||
|
||||
std::cout << "queue size : " << queueSize << "\n";
|
||||
vc->log(dpp::loglevel::ll_trace, "Queue size : " + remainingSongsCount);
|
||||
|
||||
if (index < 0 || (queueSize - 1) < index) {
|
||||
if (index < 0 || remainingSongsCount+1 < index || (!vc->is_playing() && index == 0)) {
|
||||
std::cout << "invalid index : " << index << ", " + Pos + "\n";
|
||||
|
||||
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
|
||||
return;
|
||||
}
|
||||
|
||||
auto PopedElement = queue->pop(index);
|
||||
|
||||
dpp::embed embed = PopedElement.embed
|
||||
dpp::embed embed = Bot->findEmbed(queuedSongs[index - 1])
|
||||
.set_timestamp(time(0));
|
||||
|
||||
dpp::message msg(event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:");
|
||||
|
||||
if (atoi(Pos.c_str()) == 0) {
|
||||
if (index == 0) {
|
||||
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
||||
|
||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||
return;
|
||||
}
|
||||
|
||||
v->voiceclient->stop_audio();
|
||||
v->voiceclient->insert_marker("end of music");
|
||||
v->voiceclient->skip_to_next_marker();
|
||||
}
|
||||
|
||||
msg.add_embed(embed);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#include <Commands/Leave.hpp>
|
||||
#include <iostream>
|
||||
|
||||
commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
commands::Leave::Leave(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id);
|
||||
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botID);
|
||||
|
||||
commandObjectVector.push_back(command);
|
||||
}
|
||||
@@ -18,10 +17,6 @@ void commands::Leave::operator()(const dpp::slashcommand_t& event)
|
||||
return;
|
||||
}
|
||||
v->voiceclient->stop_audio();
|
||||
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
|
||||
queue->clear();
|
||||
event.from->disconnect_voice(event.command.guild_id);
|
||||
|
||||
dpp::message msg(event.command.channel_id, "음성 채팅방을 떠납니다!");
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
commands::Play::Play(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
|
||||
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botID);
|
||||
|
||||
command.add_option(
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botCluster->me.id)
|
||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botID)
|
||||
);
|
||||
|
||||
commandObjectVector.push_back(command);
|
||||
@@ -41,13 +40,9 @@ void commands::Play::operator()(const dpp::slashcommand_t& event)
|
||||
|
||||
event.thinking();
|
||||
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
|
||||
std::cout << "다운로드 시작" << "\n";
|
||||
event.from->log(dpp::loglevel::ll_trace, "음악 다운로드 시작");
|
||||
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
||||
std::cout << "다운로드 완료" << "\n";
|
||||
|
||||
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
event.from->log(dpp::loglevel::ll_trace, "음악 다운로드 완료");
|
||||
|
||||
std::ifstream infofile, idfile;
|
||||
json document;
|
||||
@@ -56,48 +51,54 @@ void commands::Play::operator()(const dpp::slashcommand_t& event)
|
||||
idfile.open("Temp/CurMusic");
|
||||
while (std::getline(idfile, ID))
|
||||
{
|
||||
std::cout << ID << "\n";
|
||||
event.from->log(dpp::loglevel::ll_trace, "Red ID : " + ID);
|
||||
infofile.open("Music/" + ID + ".info.json");
|
||||
infofile >> document;
|
||||
infofile.close();
|
||||
|
||||
time_t SongLength = int(document["duration"]);
|
||||
char SongLengthStr[10];
|
||||
tm t;
|
||||
t.tm_mday = SongLength / 86400;
|
||||
t.tm_hour = (SongLength % 86400)/3600;
|
||||
t.tm_min = (SongLength % 3600)/60;
|
||||
t.tm_sec = SongLength%60;
|
||||
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
|
||||
)
|
||||
ID,
|
||||
Bot->makeEmbed(
|
||||
document["webpage_url"],
|
||||
document["title"],
|
||||
document["uploader"],
|
||||
document["id"],
|
||||
document["thumbnail"],
|
||||
int(document["duration"]))
|
||||
};
|
||||
|
||||
(*queue) += Data;
|
||||
|
||||
RequestedMusic.push(Data);
|
||||
}
|
||||
idfile.close();
|
||||
std::system("rm -f Temp/CurMusic");
|
||||
std::cout << "queued\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())
|
||||
{
|
||||
auto _copiedQueue = RequestedMusic;
|
||||
while (!_copiedQueue.empty())
|
||||
{
|
||||
Bot->enqueueMusic(_copiedQueue.front(), v->voiceclient);
|
||||
_copiedQueue.pop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto _copiedQueue = RequestedMusic;
|
||||
event.from->creator->on_voice_ready([&](const dpp::voice_ready_t& Voice)
|
||||
{
|
||||
while (!_copiedQueue.empty())
|
||||
{
|
||||
auto item = _copiedQueue.front();
|
||||
Bot->enqueueMusic(item, Voice.voice_client);
|
||||
_copiedQueue.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
||||
msg.add_embed(RequestedMusic.front().embed);
|
||||
RequestedMusic.pop();
|
||||
event.edit_original_response(msg);
|
||||
@@ -109,18 +110,8 @@ void commands::Play::operator()(const dpp::slashcommand_t& event)
|
||||
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();
|
||||
event.from->creator->message_create(followMsg);
|
||||
}
|
||||
|
||||
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(); });
|
||||
return;
|
||||
}
|
||||
@@ -3,61 +3,10 @@
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
namespace commands {
|
||||
dpp::embed makeEmbed(std::list<FQueueElement>::iterator& iter, std::list<FQueueElement>::iterator end, bool Repeat = false, int Index = 0)
|
||||
commands::Queue::Queue(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue);
|
||||
|
||||
if (iter == end) {
|
||||
embed
|
||||
.set_title("큐가 비었습니다!")
|
||||
.set_timestamp(time(0));
|
||||
|
||||
if (Repeat)
|
||||
embed.add_field(":repeat:","");
|
||||
|
||||
return embed;
|
||||
}
|
||||
|
||||
std::ostringstream Number;
|
||||
int Start = Index;
|
||||
|
||||
for (; (Index < Start + 5) && (iter != end); iter++, Index++) {
|
||||
Number.clear();
|
||||
Number.str("");
|
||||
Number << Index;
|
||||
embed.add_field(
|
||||
Number.str(),
|
||||
"",
|
||||
true
|
||||
)
|
||||
.add_field(
|
||||
iter->title,
|
||||
iter->description,
|
||||
true
|
||||
)
|
||||
.add_field(
|
||||
"",
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
if (iter == end) {
|
||||
embed.set_timestamp(time(0));
|
||||
if (Repeat)
|
||||
embed.add_field(":repeat:","");
|
||||
}
|
||||
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
|
||||
commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id);
|
||||
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botID);
|
||||
|
||||
commandObjectVector.push_back(command);
|
||||
}
|
||||
@@ -65,33 +14,65 @@ commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_
|
||||
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
|
||||
dpp::message msg;
|
||||
msg.set_channel_id(event.command.channel_id);
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
|
||||
if (queue->size() < 1) {
|
||||
auto iter = queue->begin();
|
||||
msg.add_embed(makeEmbed(iter, queue->end(), queue->repeat));
|
||||
auto vc = event.from->connecting_voice_channels.find(event.command.guild_id)->second->voiceclient;
|
||||
std::vector<std::string> queuedSongs = vc->get_marker_metadata();
|
||||
|
||||
int remainingSongsCount = vc->get_tracks_remaining() - 1;
|
||||
if (remainingSongsCount <= 0 && !vc->is_playing()) {
|
||||
//재생 중인 노래가 없고 큐에 노래가 없는 상황
|
||||
dpp::embed embed = dpp::embed()
|
||||
.set_color(dpp::colors::sti_blue)
|
||||
.set_title("큐가 비었습니다!")
|
||||
.set_timestamp(time(0));
|
||||
|
||||
if (Bot->repeat)
|
||||
embed.add_field(":repeat:","");
|
||||
|
||||
msg.add_embed(embed);
|
||||
}
|
||||
else {
|
||||
msg.set_content("지금 재생 중:");
|
||||
msg.add_embed(queue->peek(0).embed);
|
||||
dpp::embed curMusicEmbed = Bot->findEmbed(Bot->nowPlayingMusic);
|
||||
msg.add_embed(curMusicEmbed);
|
||||
}
|
||||
|
||||
event.reply(msg, [this, queue, event](const dpp::confirmation_callback_t &_event) {
|
||||
auto iter = queue->begin();
|
||||
int queueSize = queue->size();
|
||||
iter++;
|
||||
for (int i = 0; i < ceil(queueSize / 5.0); i++) {
|
||||
dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1);
|
||||
event.reply(msg, [&](const dpp::confirmation_callback_t &_event) {
|
||||
for (int i = 0; i < (queuedSongs.size()+4) / 5; i++)
|
||||
{
|
||||
dpp::embed followEmbed = dpp::embed();
|
||||
int j;
|
||||
for (j = i; j < i + 5 && j < queuedSongs.size(); j++)
|
||||
{
|
||||
dpp::embed originalEmbed = Bot->findEmbed(queuedSongs[j]);
|
||||
|
||||
followEmbed.add_field(
|
||||
std::to_string(j + 1),
|
||||
"",
|
||||
true
|
||||
)
|
||||
.add_field(
|
||||
originalEmbed.title,
|
||||
originalEmbed.description,
|
||||
true
|
||||
)
|
||||
.add_field(
|
||||
"",
|
||||
""
|
||||
);
|
||||
}
|
||||
if (j == queuedSongs.size())
|
||||
{
|
||||
followEmbed.set_timestamp(time(0));
|
||||
if (Bot->repeat)
|
||||
followEmbed.add_field(":repeat:","");
|
||||
}
|
||||
|
||||
dpp::message followMsg;
|
||||
followMsg.channel_id = event.command.channel_id;
|
||||
|
||||
if (i == 0) {
|
||||
followMsg.content = "현재 큐에 있는 항목:";
|
||||
}
|
||||
followMsg.add_embed(followEmbed);
|
||||
|
||||
botCluster->message_create(followMsg);
|
||||
event.from->creator->message_create(followMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2,25 +2,23 @@
|
||||
#include <dpp/dpp.h>
|
||||
#include <string>
|
||||
|
||||
commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
commands::Repeat::Repeat(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id);
|
||||
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botID);
|
||||
|
||||
commandObjectVector.push_back(command);
|
||||
}
|
||||
|
||||
void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
|
||||
if (queue->repeat) {
|
||||
|
||||
if (Bot->repeat) {
|
||||
event.reply("반복을 껐습니다.");
|
||||
queue->repeat = false;
|
||||
Bot->repeat = false;
|
||||
}
|
||||
else {
|
||||
event.reply("반복을 켰습니다.");
|
||||
queue->repeat = true;
|
||||
Bot->repeat = true;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
#include <dpp/dpp.h>
|
||||
#include <string>
|
||||
|
||||
commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
||||
: VCCommand(botCluster)
|
||||
commands::Skip::Skip(dpp::snowflake botID, BumbleCeepp* Bot)
|
||||
: ICommand(botID, Bot)
|
||||
{
|
||||
this->queueMap = queueMap;
|
||||
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id);
|
||||
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botID);
|
||||
|
||||
commandObjectVector.push_back(command);
|
||||
}
|
||||
@@ -17,11 +16,7 @@ void commands::Skip::operator()(const dpp::slashcommand_t& event) {
|
||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
||||
return;
|
||||
}
|
||||
|
||||
v->voiceclient->stop_audio();
|
||||
v->voiceclient->insert_marker("next marker");
|
||||
|
||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
||||
v->voiceclient->skip_to_next_marker();
|
||||
|
||||
event.reply("스킵했습니다!");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user