큐 완전 개혁

This commit is contained in:
2024-01-02 14:41:24 +09:00
parent 70c70eee93
commit c996f290db
30 changed files with 771 additions and 576 deletions

View File

@@ -1,22 +1,16 @@
#ifndef _BOT_HPP_
#define _BOT_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <dpp/dpp.h>
#include <memory>
class IBot {
private:
public:
IBot(std::string Token, int TotalShard);
void AddCommand(ICommand &Command);
void Start();
IBot(std::string token, int totalShard);
void start();
void onCommand(const dpp::slashcommand_t &event);
void onReady(const dpp::ready_t &event);
std::shared_ptr<dpp::cluster> BotCluster;
std::shared_ptr<dpp::cluster> botCluster;
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
protected:
virtual void OnReady(const dpp::ready_t& event);
virtual void OnCommand(const dpp::slashcommand_t& event);
std::vector<ICommand*> CommandsArray;
};
#endif

View File

@@ -1,28 +1,15 @@
#ifndef _BUMBLECEEPP_HPP_
#define _BUMBLECEEPP_HPP_
#pragma once
#include <string>
#include <list>
#include <mutex>
#include <Bot.hpp>
#include <dpp/dpp.h>
#include <MusicQueue.hpp>
#include <memory>
#include <unordered_map>
class BumbleCeepp : public IBot {
public:
BumbleCeepp(std::string Token, int TotalShard);
void enqueue(struct FQueueElement Element);
struct FQueueElement QueueDelete(int Index);
void QueuePlay();
uint32_t VoiceJoinedShardId;
bool Repeat;
std::mutex YTDLMutex;
std::list<struct FQueueElement> MusicQueue;
protected:
BumbleCeepp(std::string token, int totalShard);
private:
void OnCommand(const dpp::slashcommand_t& Event);
std::mutex QueueMutex;
bool QueuePlaying;
};
#endif
//<guild_id, queue> 쌍임.
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> queueMap;
};

View File

@@ -1,16 +0,0 @@
#ifndef _COMMANDTYPE_HPP_
#define _COMMANDTYPE_HPP_
#include <dpp/dpp.h>
#include <vector>
#include <list>
#include <FQueueElement.hpp>
class ICommand {
public:
virtual void operator() (const dpp::slashcommand_t& Event) = 0;
virtual void operator() (std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event) = 0;
std::vector<dpp::slashcommand> CommandObjectVector;
};
#endif

View File

@@ -0,0 +1,18 @@
#pragma once
#include <dpp/dpp.h>
#include <vector>
#include <list>
#include <MusicQueue.hpp>
namespace commands {
class ICommand {
public:
//이 생성자를 명시적으로 호출할 것.
ICommand(std::shared_ptr<dpp::cluster> botCluster);
virtual void operator()(const dpp::slashcommand_t &event) = 0;
std::vector<dpp::slashcommand> commandObjectVector;
protected:
std::shared_ptr<dpp::cluster> botCluster;
};
}

View File

@@ -1,11 +1,7 @@
#ifndef _COMMANDS_HPP_
#define _COMMANDS_HPP_
#pragma once
#include <Commands/Play.hpp>
#include <Commands/Repeat.hpp>
#include <Commands/Queue.hpp>
#include <Commands/Skip.hpp>
#include <Commands/Leave.hpp>
#include <Commands/Delete.hpp>
#endif
#include <Commands/Delete.hpp>

View File

@@ -1,19 +1,15 @@
#ifndef _DELETE_HPP_
#define _DELETE_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Delete : public ICommand {
public:
Delete(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Delete : public ICommand {
public:
Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,19 +1,15 @@
#ifndef _LEAVE_HPP_
#define _LEAVE_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Leave : public ICommand {
public:
Leave(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Leave : public ICommand {
public:
Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,19 +1,15 @@
#ifndef _PLAY_HPP_
#define _PLAY_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Play : public ICommand {
public:
Play(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Play : public ICommand {
public:
Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,19 +1,15 @@
#ifndef _QUEUE_HPP_
#define _QUEUE_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Queue : public ICommand {
public:
Queue(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Queue : public ICommand {
public:
Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,19 +1,15 @@
#ifndef _REPEAT_HPP_
#define _REPEAT_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Repeat : public ICommand {
public:
Repeat(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Repeat : public ICommand {
public:
Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,19 +1,15 @@
#ifndef _SKIP_HPP_
#define _SKIP_HPP_
#include <CommandType.hpp>
#pragma once
#include <Commands/CommandType.hpp>
#include <BumbleCeepp.hpp>
#include <memory>
namespace Commands {
class Skip : public ICommand {
public:
Skip(std::shared_ptr<BumbleCeepp> Bot);
namespace commands {
class Skip : public ICommand {
public:
Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
void operator()(const dpp::slashcommand_t& Event) {}
void operator()(std::list<FQueueElement>& MusicQueue, const dpp::slashcommand_t& Event);
private:
std::shared_ptr<BumbleCeepp> Bot;
};
}
#endif
void operator()(const dpp::slashcommand_t& event);
private:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
};
}

View File

@@ -1,5 +1,4 @@
#ifndef _FQUEUEELEMENT_HPP_
#define _FQUEUEELEMENT_HPP_
#pragma once
#include <string>
#include <dpp/dpp.h>
@@ -7,11 +6,8 @@ struct FQueueElement {
std::string URL;
std::string title;
std::string description;
std::string FileName;
std::string fileName;
std::string thumbnail;
std::string duration;
dpp::snowflake guild_id;
dpp::embed embed;
};
#endif
};

33
include/MusicQueue.hpp Normal file
View File

@@ -0,0 +1,33 @@
#pragma once
#include <list>
#include <FQueueElement.hpp>
struct FMusicQueueID {
dpp::snowflake guild_id;
uint32_t shard_id;
};
class MusicQueue {
public:
MusicQueue(FMusicQueueID id);
void operator+=(FQueueElement operand);
FQueueElement pop(int index);
FQueueElement peek(int index);
bool empty();
void clear();
std::list<struct FQueueElement>::iterator begin();
std::list<struct FQueueElement>::iterator end();
std::size_t size();
FMusicQueueID getId();
void play(std::shared_ptr<dpp::cluster> botCluster);
void markerCallback(std::shared_ptr<dpp::cluster> botCluster);
bool repeat;
private:
std::list<struct FQueueElement> queue;
std::mutex mutex;
std::mutex playMutex;
FMusicQueueID id;
bool queuePlaying;
};