logger 연결 완료

This commit is contained in:
2024-08-14 10:28:48 +09:00
parent 51f9b25bd8
commit 8607c4a8a5
11 changed files with 120 additions and 92 deletions

View File

@@ -1,7 +1,7 @@
#include <Bot.hpp>
#include <Commands/CommandType.hpp>
IBot::IBot(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword)
IBot::IBot(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount)
{
this->DBURL = std::make_shared<sql::SQLString>(DBURL);
sql::Properties pro({
@@ -11,15 +11,11 @@ IBot::IBot(std::string token, int clusterCount, std::string DBURL, std::string D
this->DBProperties = std::make_shared<sql::Properties>(pro);
DBDriver = sql::mariadb::get_driver_instance();
for (int i = 0; i<clusterCount; i++)
{
std::shared_ptr<dpp::cluster> cluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents);
botCluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents, clusterCount);
cluster->on_log(dpp::utility::cout_logger());
cluster->on_slashcommand([&](const dpp::slashcommand_t& event){onCommand(event);});
cluster->on_ready([&](const dpp::ready_t &event){onReady(event);});
botClusters.push_back(cluster);
}
botCluster->on_log(logger());
botCluster->on_slashcommand([&](const dpp::slashcommand_t& event){onCommand(event);});
botCluster->on_ready([&](const dpp::ready_t &event){onReady(event);});
}
void IBot::onCommand(const dpp::slashcommand_t &event)
@@ -40,23 +36,12 @@ void IBot::onReady(const dpp::ready_t &event)
for (auto command : commandsArray)
for (auto alias : command->commandObjectVector)
for (auto cluster : botClusters)
cluster->global_command_create(alias);
botCluster->global_command_create(alias);
botClusters[0]->log(dpp::loglevel::ll_info, "Command added to all clusters.");
botCluster->log(dpp::loglevel::ll_info, "Command added to all clusters.");
}
void IBot::start()
{
if (botClusters.size() == 1)
{
botClusters[0]->start(dpp::st_wait);
return;
}
for (int i = 0; i < botClusters.size() - 1; i++)
{
botClusters[i]->start(dpp::st_return);
}
botClusters[botClusters.size() - 1]->start(dpp::st_wait);
botCluster->start(dpp::st_wait);
}

View File

@@ -4,60 +4,57 @@
#include <Commands/Commands.hpp>
#include <oggz/oggz.h>
BumbleCeepp::BumbleCeepp(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword)
: IBot(token, clusterCount, DBURL, DBID, DBPassword)
BumbleCeepp::BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount)
: IBot(token, DBURL, DBID, DBPassword, clusterCount)
{
commandsArray.push_back(std::make_shared<commands::Play>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Repeat>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Queue>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Skip>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Leave>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Delete>(botClusters[0]->me.id, this));
commandsArray.push_back(std::make_shared<commands::Play>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Repeat>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Queue>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Skip>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Leave>(botCluster->me.id, this));
commandsArray.push_back(std::make_shared<commands::Delete>(botCluster->me.id, this));
for (auto cluster : botClusters)
botCluster->on_voice_track_marker([&](const dpp::voice_track_marker_t &marker)
{
cluster->on_voice_track_marker([&](const dpp::voice_track_marker_t &marker)
auto voice_members = dpp::find_guild(marker.voice_client->server_id)->voice_members;
dpp::snowflake connectedChannel = marker.voice_client->channel_id;
int memberCount = 0;
for (auto member : voice_members)
if ( member.second.channel_id == connectedChannel )
memberCount++;
if (!memberCount)
{
auto voice_members = dpp::find_guild(marker.voice_client->server_id)->voice_members;
dpp::snowflake connectedChannel = marker.voice_client->channel_id;
int memberCount = 0;
for (auto member : voice_members)
if ( member.second.channel_id == connectedChannel )
memberCount++;
auto joinedShard = marker.from;
std::cout << "voicechat is empty.";
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
return;
}
if (!memberCount)
{
auto joinedShard = marker.from;
std::cout << "voicechat is empty.";
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
marker.voice_client->log(dpp::loglevel::ll_trace, "Marker count : " + remainingSongsCount);
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
{
auto joinedShard = marker.from;
std::cout << "Queue ended\n";
if (!joinedShard)
return;
}
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
return;
}
if (repeat)
enqueueMusic({nowPlayingMusic, findEmbed(nowPlayingMusic)}, marker.voice_client);
});
marker.voice_client->log(dpp::loglevel::ll_debug, "Playing " + marker.track_meta + "on channel id " + marker.voice_client->channel_id.str() + ".");
int remainingSongsCount = marker.voice_client->get_tracks_remaining();
marker.voice_client->log(dpp::loglevel::ll_trace, "Marker count : " + remainingSongsCount);
if (remainingSongsCount <= 1 && !marker.voice_client->is_playing())
{
auto joinedShard = marker.from;
std::cout << "Queue ended\n";
if (!joinedShard)
return;
marker.voice_client->stop_audio();
joinedShard->disconnect_voice(marker.voice_client->server_id);
return;
}
if (repeat)
enqueueMusic({nowPlayingMusic, findEmbed(nowPlayingMusic)}, marker.voice_client);
});
// cluster->on_voice_ready([&](const dpp::voice_ready_t& Voice){ queue->play(); });
}
// cluster->on_voice_ready([&](const dpp::voice_ready_t& Voice){ queue->play(); });
}

View File

@@ -38,11 +38,22 @@ void commands::Play::operator()(const dpp::slashcommand_t& event)
std::string Query = std::get<std::string>(event.get_parameter("query"));
event.thinking();
dpp::detail::co_await_resolve(event.co_thinking());
event.from->log(dpp::loglevel::ll_trace, "음악 다운로드 시작");
event.from->log(dpp::loglevel::ll_debug, "음악 ID 쿼리");
dpp::utility::exec("python3 youtube-search.py", {Query}, [&](const std::string& output) -> void
{
if (!output.length())
{
event.from->log(dpp::loglevel::ll_debug, "검색 결과 없음");
event.edit_response("검색 결과가 없습니다.");
}
});
std::system(("python3 youtube-search.py \"" + Query + "\" & wait").c_str());
event.from->log(dpp::loglevel::ll_debug, "음악 다운로드 시작");
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
event.from->log(dpp::loglevel::ll_trace, "음악 다운로드 완료");
event.from->log(dpp::loglevel::ll_debug, "음악 다운로드 완료");
std::ifstream infofile, idfile;
json document;

View File

@@ -10,12 +10,12 @@ int main()
std::ifstream configfile("config.json");
configfile >> configdocument;
// setvbuf(stdout, NULL, _IONBF, 0);
std::shared_ptr<BumbleCeepp> bumbleBee = std::make_shared<BumbleCeepp>(
configdocument["token"], 1, configdocument["dbURL"], configdocument["user"], configdocument["password"]);
configdocument["token"], configdocument["dbURL"], configdocument["user"], configdocument["password"]);
bumbleBee->start();
return 0;
}

Binary file not shown.