mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-25 17:35:58 +00:00
logger 연결 완료
This commit is contained in:
14
.vscode/c_cpp_properties.json
vendored
14
.vscode/c_cpp_properties.json
vendored
@@ -3,14 +3,18 @@
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/include/opus"
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"DDPP_CORO=on"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "gnu++17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
"cppStandard": "c++20",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
"-DDPP_CORO"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -73,6 +73,8 @@
|
||||
"cinttypes": "cpp",
|
||||
"bitset": "cpp",
|
||||
"set": "cpp",
|
||||
"regex": "cpp"
|
||||
"regex": "cpp",
|
||||
"format": "cpp",
|
||||
"span": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,13 @@ string(ASCII 27 Esc)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
set_target_properties(${BOT_NAME} PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD 20
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
target_compile_definitions(${BOT_NAME} PUBLIC DPP_CORO)
|
||||
target_compile_features(${BOT_NAME} PUBLIC cxx_std_20)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(DPP)
|
||||
@@ -34,15 +37,11 @@ endif()
|
||||
target_include_directories(${BOT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${OPENSSL_INCLUDE_DIR}
|
||||
/usr/include/opus
|
||||
)
|
||||
|
||||
target_link_libraries(${BOT_NAME}
|
||||
dl
|
||||
dpp
|
||||
opus
|
||||
opusfile
|
||||
ogg
|
||||
oggz
|
||||
mariadbcpp
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
@@ -76,7 +75,4 @@ else()
|
||||
endif()
|
||||
|
||||
target_link_libraries(${BOT_NAME} dpp)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-g")
|
||||
set(VMAKE_CXX_FLAGS "-lmariadbcpp")
|
||||
endif()
|
||||
@@ -6,14 +6,25 @@
|
||||
|
||||
class IBot {
|
||||
public:
|
||||
IBot(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword);
|
||||
IBot(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount = 0);
|
||||
virtual void start();
|
||||
virtual void onCommand(const dpp::slashcommand_t &event);
|
||||
virtual void onReady(const dpp::ready_t &event);
|
||||
|
||||
std::vector<std::shared_ptr<dpp::cluster>> botClusters;
|
||||
std::shared_ptr<dpp::cluster> botCluster;
|
||||
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
|
||||
|
||||
std::function<void(const dpp::log_t&)> logger() {
|
||||
return [&](const dpp::log_t& event){
|
||||
if (event.severity >= dpp::ll_error)
|
||||
std::cerr << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
|
||||
else if (event.severity - logLevel >= 0)
|
||||
std::clog << "[" << dpp::utility::current_date_time() << "] " << dpp::utility::loglevel(event.severity) << ": " << event.message << std::endl;
|
||||
};
|
||||
};
|
||||
|
||||
dpp::loglevel logLevel = dpp::ll_debug;
|
||||
|
||||
protected:
|
||||
sql::Driver* DBDriver;
|
||||
std::shared_ptr<sql::SQLString> DBURL;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
class BumbleCeepp : public IBot {
|
||||
public:
|
||||
BumbleCeepp(std::string token, int clusterCount, std::string DBURL, std::string DBID, std::string DBPassword);
|
||||
BumbleCeepp(std::string token, std::string DBURL, std::string DBID, std::string DBPassword, int clusterCount = 0);
|
||||
|
||||
void enqueueMusic(FQueueElement item, dpp::discord_voice_client* vc);
|
||||
dpp::embed findEmbed(std::string musicID);
|
||||
|
||||
31
src/Bot.cpp
31
src/Bot.cpp
@@ -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);
|
||||
}
|
||||
@@ -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(); });
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
22
youtube-search.py
Normal file
22
youtube-search.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
sys.exit()
|
||||
|
||||
import urllib.parse
|
||||
|
||||
def uri_validator(x):
|
||||
try:
|
||||
result = urllib.parse.urlparse(x)
|
||||
return all([result.scheme, result.netloc])
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
if uri_validator(sys.argv[1]) == True:
|
||||
exit()
|
||||
|
||||
from youtube_search import YoutubeSearch
|
||||
|
||||
results = YoutubeSearch(sys.argv[1], max_results=10).to_dict()
|
||||
|
||||
print(results[0]["id"])
|
||||
Reference in New Issue
Block a user