코드 갈어엎기(사용성 개박살났으니 빌드는 이전 것으로 할 것.)

This commit is contained in:
2024-05-12 03:54:44 +09:00
parent ba56fe015f
commit 3f1edbbf16
29 changed files with 437 additions and 518 deletions

View File

@@ -2,15 +2,20 @@
#include <Commands/CommandType.hpp>
#include <dpp/dpp.h>
#include <memory>
#include <mariadb/conncpp.hpp>
class IBot {
public:
IBot(std::string token, int totalShard);
void start();
void onCommand(const dpp::slashcommand_t &event);
void onReady(const dpp::ready_t &event);
IBot(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword);
virtual void start();
virtual void onCommand(const dpp::slashcommand_t &event);
virtual void onReady(const dpp::ready_t &event);
std::shared_ptr<dpp::cluster> botCluster;
std::vector<std::shared_ptr<dpp::cluster>> botClusters;
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
protected:
sql::Driver* DBDriver;
std::shared_ptr<sql::SQLString> DBURL;
std::shared_ptr<sql::Properties> DBProperties;
};

View File

@@ -2,14 +2,29 @@
#include <string>
#include <Bot.hpp>
#include <dpp/dpp.h>
#include <MusicQueue.hpp>
#include <memory>
#include <unordered_map>
#include <FQueueElement.hpp>
class BumbleCeepp : public IBot {
public:
BumbleCeepp(std::string token, int totalShard);
BumbleCeepp(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword);
void enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc);
dpp::embed findEmbed(std::string musicID);
dpp::embed makeEmbed(
std::string webpage_url,
std::string title,
std::string uploader,
std::string id,
std::string thumbnail,
time_t duration);
bool repeat;
std::string nowPlayingMusic;
private:
//<guild_id, queue> 쌍임.
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> queueMap;
//<guild_id, queueMutex> 쌍임.
std::unordered_map<dpp::snowflake, std::mutex> enqueuingMutexMap;
std::unordered_map<std::string, dpp::embed> musicEmbedMap;
};

View File

@@ -2,28 +2,21 @@
#include <dpp/dpp.h>
#include <vector>
#include <list>
#include <MusicQueue.hpp>
class BumbleCeepp;
namespace commands {
class ICommand {
public:
//이 생성자를 명시적으로 호출할 것.
ICommand(std::shared_ptr<dpp::cluster> botCluster);
ICommand(dpp::snowflake botID, BumbleCeepp* Bot)
{
this->botID = botID;
this->Bot = Bot;
}
virtual void operator()(const dpp::slashcommand_t &event) = 0;
std::vector<dpp::slashcommand> commandObjectVector;
protected:
std::shared_ptr<dpp::cluster> botCluster;
};
}
namespace commands {
class VCCommand : public ICommand {
public:
VCCommand(std::shared_ptr<dpp::cluster> botCluster) : ICommand(botCluster) {}
std::shared_ptr<MusicQueue> getQueue(const dpp::slashcommand_t& event);
protected:
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap;
dpp::snowflake botID;
BumbleCeepp* Bot;
};
}

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Delete : public VCCommand {
class Delete : public ICommand {
public:
Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Delete(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Leave : public VCCommand {
class Leave : public ICommand {
public:
Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Leave(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Play : public VCCommand {
class Play : public ICommand {
public:
Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Play(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Queue : public VCCommand {
class Queue : public ICommand {
public:
Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Queue(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Repeat : public VCCommand {
class Repeat : public ICommand {
public:
Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Repeat(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -4,9 +4,9 @@
#include <memory>
namespace commands {
class Skip : public VCCommand {
class Skip : public ICommand {
public:
Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap);
Skip(dpp::snowflake botID, BumbleCeepp* Bot);
void operator()(const dpp::slashcommand_t& event);
};

View File

@@ -3,11 +3,7 @@
#include <dpp/dpp.h>
struct FQueueElement {
std::string URL;
std::string title;
std::string description;
std::string fileName;
std::string thumbnail;
std::string duration;
std::string ID;
dpp::embed embed;
bool skip = false;
};

View File

@@ -1,33 +0,0 @@
#pragma once
#include <list>
#include <FQueueElement.hpp>
struct FMusicQueueID {
dpp::snowflake guild_id;
uint32_t shard_id;
};
class MusicQueue {
public:
MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster);
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();
void markerCallback();
bool repeat;
private:
std::list<struct FQueueElement> queue;
std::mutex mutex;
std::mutex playMutex;
FMusicQueueID id;
std::shared_ptr<dpp::cluster> botCluster;
};