This commit is contained in:
2024-01-22 03:26:22 +09:00
parent c996f290db
commit b7b1018871
18 changed files with 118 additions and 134 deletions

View File

@@ -4,3 +4,16 @@ 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;
}

View File

@@ -2,7 +2,7 @@
#include <iostream>
commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id);
@@ -23,25 +23,29 @@ void commands::Delete::operator()(const dpp::slashcommand_t& event)
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
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;
std::shared_ptr<MusicQueue> queue = getQueue(event);
(*queueMap)[queueID.guild_id] = std::make_shared<MusicQueue>(queueID);
auto index = atoi(Pos.c_str());
int queueSize = queue->size();
std::cout << "queue size : " << queueSize << "\n";
if (index < 0 || (queueSize - 1) < index) {
std::cout << "invalid index : " << index << ", " + Pos + "\n";
event.edit_original_response(dpp::message(event.command.channel_id, "이상한 인덱스 위치. Pos : " + Pos));
return;
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
auto PopedElement = queue->pop(atoi(Pos.c_str()));
auto PopedElement = queue->pop(index);
dpp::embed embed = PopedElement.embed
.set_timestamp(time(0));
dpp::message msg(event.command.channel_id, "다음 항목을 큐에서 삭제했습니다!:");
if (!atoi(Pos.c_str())) {
if (atoi(Pos.c_str()) == 0) {
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
@@ -49,6 +53,7 @@ void commands::Delete::operator()(const dpp::slashcommand_t& event)
}
v->voiceclient->stop_audio();
v->voiceclient->insert_marker("end of music");
}
msg.add_embed(embed);

View File

@@ -2,7 +2,7 @@
#include <iostream>
commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id);
@@ -19,16 +19,7 @@ void commands::Leave::operator()(const dpp::slashcommand_t& event)
}
v->voiceclient->stop_audio();
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::shared_ptr<MusicQueue> queue = getQueue(event);
queue->clear();
event.from->disconnect_voice(event.command.guild_id);

View File

@@ -8,7 +8,7 @@
using json = nlohmann::json;
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
@@ -20,7 +20,8 @@ commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_ma
commandObjectVector.push_back(command);
}
void commands::Play::operator()(const dpp::slashcommand_t& event) {
void commands::Play::operator()(const dpp::slashcommand_t& event)
{
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
{
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
@@ -28,25 +29,19 @@ void commands::Play::operator()(const dpp::slashcommand_t& event) {
}
/* 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))
if (!event.from->get_voice(event.command.guild_id))
{
return event.reply("노래를 재생할 음성 채팅방에 먼저 참가하고 신청해야 합니다!");
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();
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::shared_ptr<MusicQueue> queue = getQueue(event);
std::cout << "다운로드 시작" << "\n";
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
@@ -106,7 +101,8 @@ void commands::Play::operator()(const dpp::slashcommand_t& event) {
RequestedMusic.pop();
event.edit_original_response(msg);
while (!RequestedMusic.empty()) {
while (!RequestedMusic.empty())
{
dpp::message followMsg(event.command.channel_id, "");
followMsg.add_embed(RequestedMusic.front().embed);
@@ -119,10 +115,11 @@ void commands::Play::operator()(const dpp::slashcommand_t& event) {
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);
if (v && v->voiceclient && v->voiceclient->is_ready())
{
queue->play();
}
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(botCluster); });
botCluster->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(); });
return;
}

View File

@@ -54,7 +54,7 @@ dpp::embed makeEmbed(std::list<FQueueElement>::iterator& iter, std::list<FQueueE
}
commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id);
@@ -63,25 +63,24 @@ commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_
}
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
dpp::message msg(event.command.channel_id, "지금 재생 중:");
dpp::message msg;
msg.set_channel_id(event.command.channel_id);
std::shared_ptr<MusicQueue> queue = getQueue(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);
if (queue->size() < 1) {
auto iter = queue->begin();
msg.add_embed(makeEmbed(iter, queue->end(), queue->repeat));
}
else {
msg.set_content("지금 재생 중:");
msg.add_embed(queue->peek(0).embed);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
msg.add_embed(queue->peek(0).embed);
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((queue->size() - 1) / 5.0); i++) {
for (int i = 0; i < ceil(queueSize / 5.0); i++) {
dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1);
dpp::message followMsg;

View File

@@ -3,7 +3,7 @@
#include <string>
commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id);
@@ -12,16 +12,7 @@ commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordere
}
void commands::Repeat::operator()(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);
}
std::shared_ptr<MusicQueue> queue = queueMap->find(event.command.guild_id)->second;
std::shared_ptr<MusicQueue> queue = getQueue(event);
if (queue->repeat) {
event.reply("반복을 껐습니다.");

View File

@@ -3,7 +3,7 @@
#include <string>
commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
: ICommand(botCluster)
: VCCommand(botCluster)
{
this->queueMap = queueMap;
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id);
@@ -19,19 +19,9 @@ void commands::Skip::operator()(const dpp::slashcommand_t& event) {
}
v->voiceclient->stop_audio();
v->voiceclient->insert_marker("next marker");
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;
queue->play(botCluster);
std::shared_ptr<MusicQueue> queue = getQueue(event);
event.reply("스킵했습니다!");