mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
Compare commits
52 Commits
Stable
...
b123b2ecdb
| Author | SHA1 | Date | |
|---|---|---|---|
| b123b2ecdb | |||
| e26d20a869 | |||
| f3974bb86f | |||
| f846dd7195 | |||
| 0bff043d6e | |||
| 7b75fc8861 | |||
| 177221bf73 | |||
| 51a49a4470 | |||
| a2821394bd | |||
| a03ed2dc78 | |||
| c59fef1d0b | |||
| 125fbcc49c | |||
| 4915a5c3b8 | |||
| 4435337f40 | |||
| 77d16c1cdb | |||
| 5760f1afdc | |||
| bb6cd89f51 | |||
| 2a238f804d | |||
| ea7d42638e | |||
| 30f97e3dfb | |||
| 17236f32b5 | |||
| 00134ee7b1 | |||
| 52146c1f6a | |||
| bf0268c1e9 | |||
| 2f5185e0c3 | |||
| 96a4096971 | |||
| ec65b550e6 | |||
| 14db2a31e8 | |||
| 1af829c711 | |||
| 46c59d40de | |||
| b08641f87e | |||
| 1ca928c4df | |||
| 2935a844a0 | |||
| 0cb7ea8225 | |||
| 7e43900f22 | |||
| c2cb16c6d7 | |||
| 3186561818 | |||
| 30569f4472 | |||
| b4476c68d7 | |||
| c276065a65 | |||
| 68b6105ac3 | |||
| 0633855374 | |||
| b9ab9ac60f | |||
| 8607c4a8a5 | |||
| 51f9b25bd8 | |||
| 3f1edbbf16 | |||
| ba56fe015f | |||
| 5c99d42fe3 | |||
| e0e4b17675 | |||
| e62a862e42 | |||
| 75a34d12b6 | |||
| 4e4856e961 |
8
.clang-format
Normal file
8
.clang-format
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Google C/C++ Code Style Settings
|
||||||
|
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: Google
|
||||||
|
Standard: c++20
|
||||||
|
IndentWidth: 2
|
||||||
|
UseTab: Never
|
||||||
|
ColumnLimit: 80
|
||||||
16
.gitignore
vendored
16
.gitignore
vendored
@@ -1,7 +1,9 @@
|
|||||||
build/
|
build/*
|
||||||
out/
|
Temp/
|
||||||
.vs/
|
Music
|
||||||
.vscode/
|
*.json
|
||||||
.idea/
|
yt-dlp
|
||||||
tmp/
|
ffmpeg
|
||||||
config.json
|
password
|
||||||
|
.vs
|
||||||
|
out
|
||||||
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@@ -1,11 +1,15 @@
|
|||||||
{
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Debug",
|
"name": "(gdb) Launch",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/BumbleCee",
|
"program": "${workspaceFolder}/build/Debug Clang 18.1.3 x86_64-pc-linux-gnu/tests/${fileBasenameNoExtension}",
|
||||||
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${fileDirname}",
|
"cwd": "${fileDirname}",
|
||||||
"environment": [],
|
"environment": [],
|
||||||
@@ -22,8 +26,7 @@
|
|||||||
"text": "-gdb-set disassembly-flavor intel",
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
"ignoreFailures": true
|
"ignoreFailures": true
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"preLaunchTask": "${defaultBuildTask}"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
140
.vscode/settings.json
vendored
140
.vscode/settings.json
vendored
@@ -1,78 +1,112 @@
|
|||||||
{
|
{
|
||||||
|
"editor.rulers": [
|
||||||
|
{
|
||||||
|
"column": 80
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cmake.generator": "Ninja",
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"iostream": "cpp",
|
|
||||||
"any": "cpp",
|
|
||||||
"chrono": "cpp",
|
|
||||||
"codecvt": "cpp",
|
|
||||||
"compare": "cpp",
|
|
||||||
"condition_variable": "cpp",
|
|
||||||
"deque": "cpp",
|
|
||||||
"forward_list": "cpp",
|
|
||||||
"list": "cpp",
|
|
||||||
"string": "cpp",
|
|
||||||
"unordered_map": "cpp",
|
|
||||||
"vector": "cpp",
|
|
||||||
"exception": "cpp",
|
|
||||||
"functional": "cpp",
|
|
||||||
"iterator": "cpp",
|
|
||||||
"memory": "cpp",
|
|
||||||
"memory_resource": "cpp",
|
|
||||||
"optional": "cpp",
|
|
||||||
"string_view": "cpp",
|
|
||||||
"random": "cpp",
|
|
||||||
"*.tcc": "cpp",
|
|
||||||
"fstream": "cpp",
|
|
||||||
"future": "cpp",
|
|
||||||
"initializer_list": "cpp",
|
|
||||||
"istream": "cpp",
|
|
||||||
"mutex": "cpp",
|
|
||||||
"new": "cpp",
|
|
||||||
"ostream": "cpp",
|
|
||||||
"ranges": "cpp",
|
|
||||||
"semaphore": "cpp",
|
|
||||||
"shared_mutex": "cpp",
|
|
||||||
"sstream": "cpp",
|
|
||||||
"stdexcept": "cpp",
|
|
||||||
"stop_token": "cpp",
|
|
||||||
"streambuf": "cpp",
|
|
||||||
"system_error": "cpp",
|
|
||||||
"thread": "cpp",
|
|
||||||
"tuple": "cpp",
|
|
||||||
"type_traits": "cpp",
|
|
||||||
"typeinfo": "cpp",
|
|
||||||
"valarray": "cpp",
|
|
||||||
"variant": "cpp",
|
|
||||||
"array": "cpp",
|
|
||||||
"atomic": "cpp",
|
|
||||||
"bit": "cpp",
|
|
||||||
"cctype": "cpp",
|
"cctype": "cpp",
|
||||||
"charconv": "cpp",
|
|
||||||
"clocale": "cpp",
|
"clocale": "cpp",
|
||||||
"cmath": "cpp",
|
"cmath": "cpp",
|
||||||
"concepts": "cpp",
|
"csetjmp": "cpp",
|
||||||
"coroutine": "cpp",
|
|
||||||
"csignal": "cpp",
|
"csignal": "cpp",
|
||||||
"cstdarg": "cpp",
|
"cstdarg": "cpp",
|
||||||
"cstddef": "cpp",
|
"cstddef": "cpp",
|
||||||
"cstdint": "cpp",
|
|
||||||
"cstdio": "cpp",
|
"cstdio": "cpp",
|
||||||
"cstdlib": "cpp",
|
"cstdlib": "cpp",
|
||||||
"cstring": "cpp",
|
"cstring": "cpp",
|
||||||
"ctime": "cpp",
|
"ctime": "cpp",
|
||||||
"cwchar": "cpp",
|
"cwchar": "cpp",
|
||||||
"cwctype": "cpp",
|
"cwctype": "cpp",
|
||||||
|
"any": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"atomic": "cpp",
|
||||||
|
"strstream": "cpp",
|
||||||
|
"barrier": "cpp",
|
||||||
|
"bit": "cpp",
|
||||||
|
"bitset": "cpp",
|
||||||
|
"cfenv": "cpp",
|
||||||
|
"charconv": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"cinttypes": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"compare": "cpp",
|
||||||
|
"complex": "cpp",
|
||||||
|
"concepts": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"coroutine": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"forward_list": "cpp",
|
||||||
|
"list": "cpp",
|
||||||
"map": "cpp",
|
"map": "cpp",
|
||||||
|
"set": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"unordered_map": "cpp",
|
||||||
|
"unordered_set": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"expected": "cpp",
|
||||||
"algorithm": "cpp",
|
"algorithm": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"iterator": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"memory_resource": "cpp",
|
||||||
"numeric": "cpp",
|
"numeric": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"random": "cpp",
|
||||||
"ratio": "cpp",
|
"ratio": "cpp",
|
||||||
|
"regex": "cpp",
|
||||||
|
"source_location": "cpp",
|
||||||
|
"string_view": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
"utility": "cpp",
|
"utility": "cpp",
|
||||||
|
"rope": "cpp",
|
||||||
|
"slist": "cpp",
|
||||||
|
"format": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"future": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
"iomanip": "cpp",
|
"iomanip": "cpp",
|
||||||
"iosfwd": "cpp",
|
"iosfwd": "cpp",
|
||||||
|
"iostream": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"latch": "cpp",
|
||||||
"limits": "cpp",
|
"limits": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
"numbers": "cpp",
|
"numbers": "cpp",
|
||||||
"cinttypes": "cpp",
|
"ostream": "cpp",
|
||||||
"bitset": "cpp",
|
"ranges": "cpp",
|
||||||
"set": "cpp",
|
"scoped_allocator": "cpp",
|
||||||
"regex": "cpp"
|
"semaphore": "cpp",
|
||||||
|
"shared_mutex": "cpp",
|
||||||
|
"span": "cpp",
|
||||||
|
"spanstream": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stacktrace": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"stdfloat": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"syncstream": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"typeindex": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"valarray": "cpp",
|
||||||
|
"variant": "cpp",
|
||||||
|
"__locale": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"print": "cpp"
|
||||||
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"**/*.rpyc": true,
|
||||||
|
"**/*.rpa": true,
|
||||||
|
"**/*.rpymc": true,
|
||||||
|
"**/cache/": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
35
.vscode/tasks.json
vendored
35
.vscode/tasks.json
vendored
@@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "cppbuild",
|
|
||||||
"label": "make",
|
|
||||||
"command": "make",
|
|
||||||
"args": [],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${fileDirname}/../build"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
},
|
|
||||||
"dependsOn": ["cmake"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "shell",
|
|
||||||
"label": "cmake",
|
|
||||||
"command": "cmake",
|
|
||||||
"args": [
|
|
||||||
".."
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${fileDirname}/../build"
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
8
BuildDockerAndUpload.sh
Executable file
8
BuildDockerAndUpload.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
(
|
||||||
|
cd build
|
||||||
|
cmake .. && make
|
||||||
|
)
|
||||||
|
docker login -u happytanuki12 --password-stdin < password
|
||||||
|
docker build --tag happytanuki12/bumblebee:latest .
|
||||||
|
docker push happytanuki12/bumblebee:latest
|
||||||
205
CMakeLists.txt
205
CMakeLists.txt
@@ -1,80 +1,163 @@
|
|||||||
cmake_minimum_required (VERSION 3.6)
|
cmake_minimum_required (VERSION 3.16)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|
||||||
set(BOT_NAME "BumbleCee")
|
set(BOT_NAME "BumbleCee")
|
||||||
|
project(${BOT_NAME} LANGUAGES CXX)
|
||||||
|
|
||||||
project(${BOT_NAME})
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
aux_source_directory("src" coresrc)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
aux_source_directory("src/Commands" commands)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
add_executable(${BOT_NAME} ${coresrc} ${commands})
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
string(ASCII 27 Esc)
|
set(BOOST_EXCLUDE_LIBRARIES nowide)
|
||||||
|
set(BUILD_TESTING ON)
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(DPP_BUILD_TEST OFF)
|
||||||
|
|
||||||
set_target_properties(${BOT_NAME} PROPERTIES
|
enable_testing()
|
||||||
CXX_STANDARD 17
|
|
||||||
CXX_STANDARD_REQUIRED ON
|
|
||||||
)
|
|
||||||
|
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
if(WIN32)
|
||||||
find_package(Threads REQUIRED)
|
set(OPENSSL_ROOT_DIR "C:/Program Files/OpenSSL-Win64")
|
||||||
find_package(DPP)
|
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
|
||||||
if(APPLE)
|
|
||||||
if(CMAKE_APPLE_SILICON_PROCESSOR)
|
if(CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||||
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl")
|
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libcrypto.lib")
|
||||||
|
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MTd/libssl.lib")
|
||||||
else()
|
else()
|
||||||
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
|
set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libcrypto.lib")
|
||||||
|
set(OPENSSL_SSL_LIBRARY "${OPENSSL_ROOT_DIR}/lib/VC/x64/MT/libssl.lib")
|
||||||
endif()
|
endif()
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
else()
|
|
||||||
find_package(OpenSSL REQUIRED)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(${BOT_NAME} PUBLIC
|
find_package(OpenSSL REQUIRED)
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
||||||
${OPENSSL_INCLUDE_DIR}
|
|
||||||
/usr/include/opus
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${BOT_NAME}
|
|
||||||
dl
|
|
||||||
dpp
|
|
||||||
opus
|
|
||||||
opusfile
|
|
||||||
ogg
|
|
||||||
oggz
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
|
||||||
${OPENSSL_CRYPTO_LIBRARY}
|
|
||||||
${OPENSSL_SSL_LIBRARY}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (DPP_FOUND)
|
|
||||||
target_link_libraries(${BOT_NAME} ${DPP_LIBRARIES})
|
|
||||||
target_include_directories(${BOT_NAME} PUBLIC ${DPP_INCLUDE_DIR})
|
|
||||||
else()
|
|
||||||
message(WARNING "Could not find DPP install. Building from source instead.")
|
|
||||||
option(DPP_BUILD_TEST "" OFF)
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
libdpp
|
Boost
|
||||||
GIT_REPOSITORY https://github.com/brainboxdotcc/DPP.git
|
URL "https://github.com/boostorg/boost/releases/download/boost-1.89.0/boost-1.89.0-cmake.7z"
|
||||||
GIT_TAG master)
|
DOWNLOAD_EXTRACT_TIMESTAMP ON
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
FetchContent_GetProperties(libdpp)
|
|
||||||
if(NOT libdpp_POPULATED)
|
|
||||||
FetchContent_Populate(libdpp)
|
|
||||||
target_include_directories(${BOT_NAME} PUBLIC
|
|
||||||
${libdpp_SOURCE_DIR}/include
|
|
||||||
)
|
)
|
||||||
add_subdirectory(
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Do not build SHARED libraries" FORCE)
|
||||||
${libdpp_SOURCE_DIR}
|
message(STATUS "Fetching and making available Boost...")
|
||||||
${libdpp_BINARY_DIR}
|
FetchContent_MakeAvailable(Boost)
|
||||||
EXCLUDE_FROM_ALL)
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
dpp
|
||||||
|
GIT_REPOSITORY "https://github.com/brainboxdotcc/DPP.git"
|
||||||
|
GIT_TAG "v10.1.3"
|
||||||
|
GIT_SHALLOW ON
|
||||||
|
)
|
||||||
|
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build SHARED libraries" FORCE)
|
||||||
|
message(STATUS "Fetching and making available dpp...")
|
||||||
|
FetchContent_MakeAvailable(dpp)
|
||||||
|
|
||||||
|
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD} CACHE BOOL "Type of libraries to build" FORCE)
|
||||||
|
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
# 플랫폼별 FFmpeg 바이너리 다운로드 및 링크
|
||||||
|
# -------------------------------------------------------------
|
||||||
|
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-lgpl-shared.zip")
|
||||||
|
set(FFMPEG_ARCHIVE_NAME "ffmpeg-windows")
|
||||||
|
set(FFMPEG_LIB_DIR "lib")
|
||||||
|
set(FFMPEG_INCLUDE_DIR "include")
|
||||||
|
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
|
||||||
|
set(FFMPEG_URL "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-lgpl-shared.tar.xz")
|
||||||
|
set(FFMPEG_ARCHIVE_NAME "ffmpeg-linux")
|
||||||
|
set(FFMPEG_LIB_DIR "lib")
|
||||||
|
set(FFMPEG_INCLUDE_DIR "include")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unsupported platform for FFmpeg precompiled binaries.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${BOT_NAME} dpp)
|
FetchContent_Declare(
|
||||||
|
ffmpeg
|
||||||
|
URL ${FFMPEG_URL}
|
||||||
|
DOWNLOAD_EXTRACT_TIMESTAMP ON
|
||||||
|
SOURCE_DIR ${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}
|
||||||
|
)
|
||||||
|
message(STATUS "Fetching and making available ffmpeg...")
|
||||||
|
FetchContent_MakeAvailable(ffmpeg)
|
||||||
|
|
||||||
|
set(FFMPEG_LIBRARY_PATH ${ffmpeg_SOURCE_DIR}/${FFMPEG_LIB_DIR})
|
||||||
|
set(FFMPEG_INCLUDE_PATH ${ffmpeg_SOURCE_DIR}/${FFMPEG_INCLUDE_DIR})
|
||||||
|
|
||||||
|
find_library(AVCODEC_LIBRARY NAMES avcodec PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
|
||||||
|
message(STATUS "AVCODEC_LIBRARY = ${AVCODEC_LIBRARY}")
|
||||||
|
find_library(AVFORMAT_LIBRARY NAMES avformat PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
|
||||||
|
message(STATUS "AVFORMAT_LIBRARY = ${AVFORMAT_LIBRARY}")
|
||||||
|
find_library(AVUTIL_LIBRARY NAMES avutil PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
|
||||||
|
message(STATUS "AVUTIL_LIBRARY = ${AVUTIL_LIBRARY}")
|
||||||
|
find_library(SWSCALE_LIBRARY NAMES swscale PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
|
||||||
|
message(STATUS "SWSCALE_LIBRARY = ${SWSCALE_LIBRARY}")
|
||||||
|
find_library(SWRESAMPLE_LIBRARY NAMES swresample PATHS ${FFMPEG_LIBRARY_PATH} NO_DEFAULT_PATH)
|
||||||
|
message(STATUS "SWRESAMPLE_LIBRARY = ${SWRESAMPLE_LIBRARY}")
|
||||||
|
|
||||||
|
if(NOT AVCODEC_LIBRARY OR NOT AVFORMAT_LIBRARY OR NOT AVUTIL_LIBRARY OR NOT SWRESAMPLE_LIBRARY)
|
||||||
|
message(FATAL_ERROR "FFmpeg 라이브러리를 찾을 수 없습니다. 다운로드 경로를 확인해주세요.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "-g")
|
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.cxx" "src/*.cc")
|
||||||
|
|
||||||
|
add_library(${BOT_NAME}_lib ${SOURCES})
|
||||||
|
|
||||||
|
target_include_directories(${BOT_NAME}_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
target_include_directories(${BOT_NAME}_lib PUBLIC ${OpenSSL_INCLUDE_DIRS})
|
||||||
|
target_include_directories(${BOT_NAME}_lib PUBLIC ${FFMPEG_INCLUDE_PATH})
|
||||||
|
|
||||||
|
target_precompile_headers(${BOT_NAME}_lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/precomp.h")
|
||||||
|
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC dpp)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::filesystem)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::process)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::log)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC Boost::beast)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC OpenSSL::Crypto)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC OpenSSL::SSL)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVUTIL_LIBRARY})
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVCODEC_LIBRARY})
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ${AVFORMAT_LIBRARY})
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ${SWSCALE_LIBRARY})
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ${SWRESAMPLE_LIBRARY})
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
target_link_libraries(${BOT_NAME}_lib PUBLIC ws2_32)
|
||||||
|
endif()
|
||||||
|
if(UNIX AND NOT APPLE)
|
||||||
|
set_target_properties(${BOT_NAME}_lib PROPERTIES
|
||||||
|
BUILD_WITH_INSTALL_RPATH TRUE
|
||||||
|
INSTALL_RPATH "$ORIGIN"
|
||||||
|
SKIP_BUILD_RPATH FALSE
|
||||||
|
BUILD_RPATH "$ORIGIN"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(${BOT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
target_link_libraries(${BOT_NAME} PUBLIC ${BOT_NAME}_lib)
|
||||||
|
|
||||||
|
file(GLOB FFMPEG_SHARED
|
||||||
|
"${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/bin/*.dll" # Windows
|
||||||
|
"${CMAKE_BINARY_DIR}/${FFMPEG_ARCHIVE_NAME}/lib/*.so*" # Linux
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(ffmpeg_shared ${FFMPEG_SHARED})
|
||||||
|
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"${ffmpeg_shared}"
|
||||||
|
"$<TARGET_FILE_DIR:${BOT_NAME}>"
|
||||||
|
COMMENT "Copying ${ffmpeg_shared} to output directory"
|
||||||
|
)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${BOT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
"$<TARGET_FILE:dpp>"
|
||||||
|
"$<TARGET_FILE_DIR:${BOT_NAME}>"
|
||||||
|
COMMENT "Copying dpp DLL/so files to output directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_subdirectory(tests)
|
||||||
BIN
DPP-markdown-logo.png
Normal file
BIN
DPP-markdown-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM debian:sid
|
||||||
|
WORKDIR /
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y curl libopus0 tini liboggz2 xz-utils ffmpeg python3 \
|
||||||
|
python3-pip python3-certifi python3-brotli python3-websockets python3-requests python3-mutagen && \
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
RUN pip3 install --break-system-packages --no-cache-dir curl_cffi
|
||||||
|
RUN pip3 install --break-system-packages --no-cache-dir pycryptodome
|
||||||
|
RUN curl -Lo dpp.deb https://dl.dpp.dev/latest
|
||||||
|
RUN curl -Lo dpp-legacy.deb https://github.com/brainboxdotcc/DPP/releases/download/v10.0.35/libdpp-10.0.35-linux-x64.deb
|
||||||
|
RUN dpkg -i dpp.deb
|
||||||
|
RUN dpkg -i dpp-legacy.deb
|
||||||
|
RUN rm dpp.deb
|
||||||
|
RUN curl -LO https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
|
||||||
|
RUN chmod +x ./yt-dlp
|
||||||
|
COPY ./build/BumbleCee /BumbleCee
|
||||||
|
COPY ./streamOpus.sh /streamOpus.sh
|
||||||
|
RUN chmod +x BumbleCee
|
||||||
|
RUN chmod +x streamOpus.sh
|
||||||
|
ENTRYPOINT ["/usr/bin/tini", "--", "./BumbleCee"]
|
||||||
48
README.md
Normal file
48
README.md
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
# 이게 뭔가요?
|
||||||
|
[](https://www.codefactor.io/repository/github/happytanuki/bumblecee)
|
||||||
|
|
||||||
|
C++ Dpp 라이브러리를 이용해서 개발된 간단한 디스코드 음악봇입니다!
|
||||||
|
<div align="center">
|
||||||
|
<a href="https://github.com/brainboxdotcc/DPP" alt="DPP"> <img src="DPP-markdown-logo.png" /> </a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
# 어떻게 써요?
|
||||||
|
1. 실행파일 경로에 config.json 파일을 만들고 다음과 같이 입력하세요:
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"CLEAR_PREVIOUS_COMMAND": true,
|
||||||
|
"FFMPEG_CMD": "ffmpeg",
|
||||||
|
"LOGLEVEL": "debug",
|
||||||
|
"TOKEN": "발급받은 토큰",
|
||||||
|
"YTDLP_CMD": "./yt-dlp"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. 봇을 초대하시고 사용하시면 됩니다.
|
||||||
|
|
||||||
|
# 명령어
|
||||||
|
## /p
|
||||||
|
노래를 예약합니다.
|
||||||
|
사용법:
|
||||||
|
/p (노래링크 또는 노래 제목)
|
||||||
|
## /q
|
||||||
|
현재 큐의 내용물을 확인합니다.
|
||||||
|
사용법:
|
||||||
|
/q
|
||||||
|
## /d
|
||||||
|
현재 큐의 내용물을 삭제합니다.
|
||||||
|
현재 재생중인 곡은 0번입니다.
|
||||||
|
사용법:
|
||||||
|
/d (큐의 노래번호)
|
||||||
|
## /s
|
||||||
|
현재 곡을 스킵합니다.
|
||||||
|
사용법:
|
||||||
|
/s
|
||||||
|
## /l
|
||||||
|
음성 채팅을 떠납니다.
|
||||||
|
사용법:
|
||||||
|
/l
|
||||||
|
|
||||||
|
# docker
|
||||||
|
happytanuki12/bumblebee:latest
|
||||||
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
bumblebee:
|
||||||
|
image: happytanuki12/bumblebee:latest
|
||||||
|
container_name: BumbleBee
|
||||||
|
volumes:
|
||||||
|
- ./config.json:/config.json
|
||||||
|
restart: unless-stopped
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <dpp/dpp.h>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
std::shared_ptr<dpp::cluster> botCluster;
|
|
||||||
std::vector<std::shared_ptr<commands::ICommand>> commandsArray;
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#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);
|
|
||||||
private:
|
|
||||||
//<guild_id, queue> 쌍임.
|
|
||||||
std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> queueMap;
|
|
||||||
};
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#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>
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Delete : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Leave : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Play : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Queue : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Repeat : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
class Skip : public VCCommand {
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include <dpp/dpp.h>
|
|
||||||
|
|
||||||
struct FQueueElement {
|
|
||||||
std::string URL;
|
|
||||||
std::string title;
|
|
||||||
std::string description;
|
|
||||||
std::string fileName;
|
|
||||||
std::string thumbnail;
|
|
||||||
std::string duration;
|
|
||||||
dpp::embed embed;
|
|
||||||
};
|
|
||||||
@@ -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;
|
|
||||||
};
|
|
||||||
23
include/precomp.h
Normal file
23
include/precomp.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BUMBLEBEE_INCLUDE_PRECOMP_H_
|
||||||
|
#define BUMBLEBEE_INCLUDE_PRECOMP_H_
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include "boost/asio.hpp"
|
||||||
|
#include "boost/beast/http.hpp"
|
||||||
|
#include "boost/beast/ssl.hpp"
|
||||||
|
#include "boost/log/trivial.hpp"
|
||||||
|
#include "boost/process.hpp"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "libavformat/avformat.h"
|
||||||
|
#include "libavutil/avutil.h"
|
||||||
|
#include "libswresample/swresample.h"
|
||||||
|
#include "libswscale/swscale.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BUMBLEBEE_INCLUDE_PRECOMP_H_
|
||||||
41
include/utils/console.h
Normal file
41
include/utils/console.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef BUMBLEBEE_INCLUDE_UTILS_CONSOLE_H_
|
||||||
|
#define BUMBLEBEE_INCLUDE_UTILS_CONSOLE_H_
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
// @brief 명령어가 실행 가능한지 체크합니다
|
||||||
|
// @param cmd 실행할 명령
|
||||||
|
// @return int error_code
|
||||||
|
int ValidateCommand(
|
||||||
|
boost::asio::io_context& ctx, std::string cmd,
|
||||||
|
const std::vector<std::string>& args = std::vector<std::string>());
|
||||||
|
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
|
||||||
|
// @param cmd 실행할 명령
|
||||||
|
// @param args 아규먼트
|
||||||
|
// @return int error_code
|
||||||
|
int ExecuteCommand(
|
||||||
|
boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args = std::vector<std::string>());
|
||||||
|
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
|
||||||
|
// @param cmd 실행할 명령
|
||||||
|
// @param result 실행결과
|
||||||
|
// @return int error_code
|
||||||
|
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
std::string& result);
|
||||||
|
// @brief 명령어를 쉘에서 실행하고 결과를 EOF 전까지 읽어 반환합니다
|
||||||
|
// @param cmd 실행할 명령
|
||||||
|
// @param args 아규먼트
|
||||||
|
// @param result 실행결과
|
||||||
|
// @return int error_code
|
||||||
|
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args, std::string& result);
|
||||||
|
// @brief 명령어를 쉘에서 실행하고 결과를 파이프로 연결하여 반환합니다
|
||||||
|
// @param cmd 실행할 명령
|
||||||
|
// @param args 아규먼트
|
||||||
|
// @return boost::process::popen
|
||||||
|
boost::process::popen OpenPipe(
|
||||||
|
boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args = std::vector<std::string>());
|
||||||
|
} // namespace utils
|
||||||
|
#endif
|
||||||
10
include/utils/file_downloader.h
Normal file
10
include/utils/file_downloader.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef BUMBLEBEE_INCLUDE_UTILS_FILE_DOWNLOADER_H_
|
||||||
|
#define BUMBLEBEE_INCLUDE_UTILS_FILE_DOWNLOADER_H_
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
void DownloadFileFromHTTPS(std::string url, std::string filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
14
include/utils/update_checker.h
Normal file
14
include/utils/update_checker.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef BUMBLEBEE_INCLUDE_UTILS_UPDATE_CHECKER_H_
|
||||||
|
#define BUMBLEBEE_INCLUDE_UTILS_UPDATE_CHECKER_H_
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
int InstallYtdlp(boost::asio::io_context& ctx);
|
||||||
|
|
||||||
|
int CheckUpdate(boost::asio::io_context& ctx);
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
|
||||||
|
#endif
|
||||||
42
src/Bot.cpp
42
src/Bot.cpp
@@ -1,42 +0,0 @@
|
|||||||
#include <Bot.hpp>
|
|
||||||
#include <Commands/CommandType.hpp>
|
|
||||||
|
|
||||||
IBot::IBot(std::string token, int totalShard)
|
|
||||||
{
|
|
||||||
botCluster = std::make_shared<dpp::cluster>(token, dpp::i_default_intents, totalShard);
|
|
||||||
botCluster->on_log(dpp::utility::cout_logger());
|
|
||||||
|
|
||||||
botCluster->on_slashcommand([this](const dpp::slashcommand_t& event){onCommand(event);});
|
|
||||||
botCluster->on_ready([this](const dpp::ready_t &event){onReady(event);});
|
|
||||||
}
|
|
||||||
|
|
||||||
void IBot::onCommand(const dpp::slashcommand_t &event)
|
|
||||||
{
|
|
||||||
auto _event = event;
|
|
||||||
for (int i = 0; i < commandsArray.size(); i++) {
|
|
||||||
for (auto alias : commandsArray[i]->commandObjectVector) {
|
|
||||||
if (event.command.get_command_name() == alias.name) {
|
|
||||||
(*commandsArray[i])(_event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IBot::onReady(const dpp::ready_t &event)
|
|
||||||
{
|
|
||||||
if (!dpp::run_once<struct register_bot_commands>())
|
|
||||||
return;
|
|
||||||
|
|
||||||
//BotCluster->global_bulk_command_delete();
|
|
||||||
|
|
||||||
for (int i = 0; i < commandsArray.size(); i++) {
|
|
||||||
for (auto Alias : commandsArray[i]->commandObjectVector) {
|
|
||||||
botCluster->global_command_create(Alias);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IBot::start()
|
|
||||||
{
|
|
||||||
botCluster->start(dpp::st_wait);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "BumbleCeepp.hpp"
|
|
||||||
#include <string>
|
|
||||||
#include <FQueueElement.hpp>
|
|
||||||
#include <Commands/Commands.hpp>
|
|
||||||
|
|
||||||
BumbleCeepp::BumbleCeepp(std::string token, int totalShard)
|
|
||||||
: IBot(token, totalShard)
|
|
||||||
{
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Play>(botCluster, &queueMap));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Repeat>(botCluster, &queueMap));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Queue>(botCluster, &queueMap));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Skip>(botCluster, &queueMap));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Leave>(botCluster, &queueMap));
|
|
||||||
commandsArray.push_back(std::make_shared<commands::Delete>(botCluster, &queueMap));
|
|
||||||
|
|
||||||
std::cout << "Command added.\n";
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#include <Commands/CommandType.hpp>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#include <Commands/Delete.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
commands::Delete::Delete(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand Command = dpp::slashcommand("d", "큐의 해당하는 번호의 노래를 지웁니다", botCluster->me.id);
|
|
||||||
|
|
||||||
Command.add_option(
|
|
||||||
dpp::command_option(dpp::co_string, "pos", "큐 번호", botCluster->me.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(Command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Delete::operator()(const dpp::slashcommand_t& event)
|
|
||||||
{
|
|
||||||
if (std::holds_alternative<std::monostate>(event.get_parameter("pos"))) {
|
|
||||||
event.reply("삭제할 노래의 인덱스가 정확하지 않습니다.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string Pos = std::get<std::string>(event.get_parameter("pos"));
|
|
||||||
event.thinking();
|
|
||||||
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()) == 0) {
|
|
||||||
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
|
||||||
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->voiceclient->stop_audio();
|
|
||||||
v->voiceclient->insert_marker("end of music");
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.add_embed(embed);
|
|
||||||
|
|
||||||
event.edit_original_response(msg);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#include <Commands/Leave.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
commands::Leave::Leave(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand command = dpp::slashcommand("l", "음챗을 떠납니다", botCluster->me.id);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Leave::operator()(const dpp::slashcommand_t& event)
|
|
||||||
{
|
|
||||||
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
|
||||||
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
v->voiceclient->stop_audio();
|
|
||||||
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
queue->clear();
|
|
||||||
event.from->disconnect_voice(event.command.guild_id);
|
|
||||||
|
|
||||||
dpp::message msg(event.command.channel_id, "음성 채팅방을 떠납니다!");
|
|
||||||
|
|
||||||
event.reply(msg);
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
#include <Commands/Play.hpp>
|
|
||||||
#include <dpp/dpp.h>
|
|
||||||
#include <dpp/nlohmann/json.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
commands::Play::Play(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand command = dpp::slashcommand("p", "노래 재생", botCluster->me.id);
|
|
||||||
|
|
||||||
command.add_option(
|
|
||||||
dpp::command_option(dpp::co_string, "query", "링크 또는 검색어", botCluster->me.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Play::operator()(const dpp::slashcommand_t& event)
|
|
||||||
{
|
|
||||||
if (std::holds_alternative<std::monostate>(event.get_parameter("query")))
|
|
||||||
{
|
|
||||||
event.reply("노래를 재생하려면 검색어 또는 링크를 입력해 주십시오.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Attempt to connect to a voice channel, returns false if we fail to connect. */
|
|
||||||
if (!event.from->get_voice(event.command.guild_id))
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
std::cout << "다운로드 시작" << "\n";
|
|
||||||
std::system(("python3 yt-download.py \"" + Query + "\" & wait").c_str());
|
|
||||||
std::cout << "다운로드 완료" << "\n";
|
|
||||||
|
|
||||||
dpp::message msg(event.command.channel_id, "큐에 다음 곡을 추가했습니다:");
|
|
||||||
|
|
||||||
std::ifstream infofile, idfile;
|
|
||||||
json document;
|
|
||||||
std::string ID;
|
|
||||||
std::queue<FQueueElement> RequestedMusic;
|
|
||||||
idfile.open("Temp/CurMusic");
|
|
||||||
while (std::getline(idfile, ID))
|
|
||||||
{
|
|
||||||
std::cout << ID << "\n";
|
|
||||||
infofile.open("Music/" + ID + ".info.json");
|
|
||||||
infofile >> document;
|
|
||||||
infofile.close();
|
|
||||||
|
|
||||||
time_t SongLength = int(document["duration"]);
|
|
||||||
char SongLengthStr[10];
|
|
||||||
tm t;
|
|
||||||
t.tm_mday = SongLength / 86400;
|
|
||||||
t.tm_hour = (SongLength % 86400)/3600;
|
|
||||||
t.tm_min = (SongLength % 3600)/60;
|
|
||||||
t.tm_sec = SongLength%60;
|
|
||||||
strftime(SongLengthStr, sizeof(SongLengthStr), "%X", &t);
|
|
||||||
|
|
||||||
FQueueElement Data = {
|
|
||||||
std::string(document["webpage_url"]),
|
|
||||||
std::string(document["title"]),
|
|
||||||
std::string(document["uploader"]),
|
|
||||||
std::string(document["id"]),
|
|
||||||
std::string(document["thumbnail"]),
|
|
||||||
to_string(document["duration"]),
|
|
||||||
dpp::embed()
|
|
||||||
.set_color(dpp::colors::sti_blue)
|
|
||||||
.set_title(Data.title)
|
|
||||||
.set_description(Data.description)
|
|
||||||
.set_url(Data.URL)
|
|
||||||
.set_image(Data.thumbnail)
|
|
||||||
.add_field(
|
|
||||||
"길이",
|
|
||||||
SongLengthStr,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
(*queue) += Data;
|
|
||||||
|
|
||||||
RequestedMusic.push(Data);
|
|
||||||
}
|
|
||||||
idfile.close();
|
|
||||||
std::system("rm -f Temp/CurMusic");
|
|
||||||
std::cout << "queued\n";
|
|
||||||
|
|
||||||
msg.add_embed(RequestedMusic.front().embed);
|
|
||||||
RequestedMusic.pop();
|
|
||||||
event.edit_original_response(msg);
|
|
||||||
|
|
||||||
while (!RequestedMusic.empty())
|
|
||||||
{
|
|
||||||
dpp::message followMsg(event.command.channel_id, "");
|
|
||||||
|
|
||||||
followMsg.add_embed(RequestedMusic.front().embed);
|
|
||||||
RequestedMusic.pop();
|
|
||||||
|
|
||||||
botCluster->message_create(followMsg);
|
|
||||||
}
|
|
||||||
std::cout << "replied\n";
|
|
||||||
|
|
||||||
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->on_voice_ready([this, queue](const dpp::voice_ready_t& Voice){ queue->play(); });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
#include <Commands/Queue.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace commands {
|
|
||||||
dpp::embed makeEmbed(std::list<FQueueElement>::iterator& iter, std::list<FQueueElement>::iterator end, bool Repeat = false, int Index = 0)
|
|
||||||
{
|
|
||||||
dpp::embed embed = dpp::embed()
|
|
||||||
.set_color(dpp::colors::sti_blue);
|
|
||||||
|
|
||||||
if (iter == end) {
|
|
||||||
embed
|
|
||||||
.set_title("큐가 비었습니다!")
|
|
||||||
.set_timestamp(time(0));
|
|
||||||
|
|
||||||
if (Repeat)
|
|
||||||
embed.add_field(":repeat:","");
|
|
||||||
|
|
||||||
return embed;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostringstream Number;
|
|
||||||
int Start = Index;
|
|
||||||
|
|
||||||
for (; (Index < Start + 5) && (iter != end); iter++, Index++) {
|
|
||||||
Number.clear();
|
|
||||||
Number.str("");
|
|
||||||
Number << Index;
|
|
||||||
embed.add_field(
|
|
||||||
Number.str(),
|
|
||||||
"",
|
|
||||||
true
|
|
||||||
)
|
|
||||||
.add_field(
|
|
||||||
iter->title,
|
|
||||||
iter->description,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
.add_field(
|
|
||||||
"",
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iter == end) {
|
|
||||||
embed.set_timestamp(time(0));
|
|
||||||
if (Repeat)
|
|
||||||
embed.add_field(":repeat:","");
|
|
||||||
}
|
|
||||||
|
|
||||||
return embed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commands::Queue::Queue(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand command = dpp::slashcommand("q", "노래 예약 큐 확인", botCluster->me.id);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Queue::operator()(const dpp::slashcommand_t& event) {
|
|
||||||
dpp::message msg;
|
|
||||||
msg.set_channel_id(event.command.channel_id);
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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(queueSize / 5.0); i++) {
|
|
||||||
dpp::embed followEmbed = makeEmbed(iter, queue->end(), queue->repeat, i * 5 + 1);
|
|
||||||
|
|
||||||
dpp::message followMsg;
|
|
||||||
followMsg.channel_id = event.command.channel_id;
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
followMsg.content = "현재 큐에 있는 항목:";
|
|
||||||
}
|
|
||||||
followMsg.add_embed(followEmbed);
|
|
||||||
|
|
||||||
botCluster->message_create(followMsg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#include <Commands/Repeat.hpp>
|
|
||||||
#include <dpp/dpp.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
commands::Repeat::Repeat(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand command = dpp::slashcommand("r", "반복 켜기/끄기", botCluster->me.id);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Repeat::operator()(const dpp::slashcommand_t& event) {
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
if (queue->repeat) {
|
|
||||||
event.reply("반복을 껐습니다.");
|
|
||||||
queue->repeat = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
event.reply("반복을 켰습니다.");
|
|
||||||
queue->repeat = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#include <Commands/Skip.hpp>
|
|
||||||
#include <dpp/dpp.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
commands::Skip::Skip(std::shared_ptr<dpp::cluster> botCluster, std::unordered_map<dpp::snowflake, std::shared_ptr<MusicQueue>> *queueMap)
|
|
||||||
: VCCommand(botCluster)
|
|
||||||
{
|
|
||||||
this->queueMap = queueMap;
|
|
||||||
dpp::slashcommand command = dpp::slashcommand("s", "현재곡 스킵", botCluster->me.id);
|
|
||||||
|
|
||||||
commandObjectVector.push_back(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
void commands::Skip::operator()(const dpp::slashcommand_t& event) {
|
|
||||||
dpp::voiceconn* v = event.from->get_voice(event.command.guild_id);
|
|
||||||
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
v->voiceclient->stop_audio();
|
|
||||||
v->voiceclient->insert_marker("next marker");
|
|
||||||
|
|
||||||
std::shared_ptr<MusicQueue> queue = getQueue(event);
|
|
||||||
|
|
||||||
event.reply("스킵했습니다!");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
OSeStDEAZJQ
|
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,216 +0,0 @@
|
|||||||
#include <MusicQueue.hpp>
|
|
||||||
#include <ogg/ogg.h>
|
|
||||||
#include <oggz/oggz.h>
|
|
||||||
#include <opus/opusfile.h>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
MusicQueue::MusicQueue(FMusicQueueID id, std::shared_ptr<dpp::cluster> botCluster)
|
|
||||||
{
|
|
||||||
this->id = id;
|
|
||||||
repeat = false;
|
|
||||||
this->botCluster = botCluster;
|
|
||||||
|
|
||||||
botCluster->on_voice_track_marker([this, botCluster](const dpp::voice_track_marker_t &marker)
|
|
||||||
{
|
|
||||||
std::cout << marker.track_meta << " Marker reached.\n";
|
|
||||||
|
|
||||||
if (empty())
|
|
||||||
{
|
|
||||||
std::cout << "Queue ended\n";
|
|
||||||
playMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto music = pop(0);
|
|
||||||
if (repeat)
|
|
||||||
{
|
|
||||||
(*this) += music;
|
|
||||||
}
|
|
||||||
|
|
||||||
markerCallback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void MusicQueue::operator+=(FQueueElement operand)
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
queue.push_back(operand);
|
|
||||||
mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
FQueueElement MusicQueue::pop(int index)
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
auto iter = queue.begin();
|
|
||||||
std::advance(iter, index);
|
|
||||||
auto returnValue = *iter;
|
|
||||||
queue.erase(iter);
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
FQueueElement MusicQueue::peek(int index)
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
auto iter = queue.begin();
|
|
||||||
std::advance(iter, index);
|
|
||||||
auto returnValue = *iter;
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MusicQueue::empty()
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
bool empty = queue.empty();
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MusicQueue::clear()
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
queue.clear();
|
|
||||||
mutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<struct FQueueElement>::iterator MusicQueue::begin()
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
auto returnValue = queue.begin();
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<struct FQueueElement>::iterator MusicQueue::end()
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
auto returnValue = queue.end();
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t MusicQueue::size()
|
|
||||||
{
|
|
||||||
mutex.lock();
|
|
||||||
auto returnValue = queue.size();
|
|
||||||
mutex.unlock();
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
FMusicQueueID MusicQueue::getId()
|
|
||||||
{
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MusicQueue::markerCallback()
|
|
||||||
{
|
|
||||||
std::cout << "Music play started\n";
|
|
||||||
|
|
||||||
dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id);
|
|
||||||
if (!joinedShard)
|
|
||||||
{
|
|
||||||
std::cout << "No shard\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty())
|
|
||||||
{
|
|
||||||
std::cout << "Queue ended\n";
|
|
||||||
playMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FQueueElement music = peek(0);
|
|
||||||
|
|
||||||
dpp::voiceconn* v = joinedShard->get_voice(id.guild_id);
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready())
|
|
||||||
{
|
|
||||||
std::cout << "not in voicechat. quit musicplay";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//v->voiceclient->error(4014);
|
|
||||||
|
|
||||||
/* load the audio file with oggz */
|
|
||||||
OGGZ *track_og = oggz_open(("Music/" + music.fileName + ".ogg").c_str(), OGGZ_READ);
|
|
||||||
|
|
||||||
/* If there was an issue reading the file, tell the user and stop */
|
|
||||||
if (!track_og) {
|
|
||||||
fprintf(stderr, "Error opening file\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set read callback, this callback will be called on packets with the serialno,
|
|
||||||
* -1 means every packet will be handled with this callback.
|
|
||||||
*/
|
|
||||||
oggz_set_read_callback(
|
|
||||||
track_og, -1,
|
|
||||||
[](OGGZ *oggz, oggz_packet *packet, long serialno, void *user_data) {
|
|
||||||
dpp::voiceconn *voiceconn = (dpp::voiceconn *)user_data;
|
|
||||||
|
|
||||||
/* send the audio */
|
|
||||||
voiceconn->voiceclient->send_audio_opus(packet->op.packet, packet->op.bytes);
|
|
||||||
|
|
||||||
/* make sure to always return 0 here, read more on oggz documentation */
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
/* this will be the value of void *user_data */
|
|
||||||
(void *)v
|
|
||||||
);
|
|
||||||
|
|
||||||
// read loop
|
|
||||||
while (v && v->voiceclient && !v->voiceclient->terminating) {
|
|
||||||
/* you can tweak this to whatever. Here I use BUFSIZ, defined in
|
|
||||||
* stdio.h as 8192.
|
|
||||||
*/
|
|
||||||
static const constexpr long CHUNK_READ = BUFSIZ * 2;
|
|
||||||
|
|
||||||
const long read_bytes = oggz_read(track_og, CHUNK_READ);
|
|
||||||
|
|
||||||
/* break on eof */
|
|
||||||
if (!read_bytes) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't forget to free the memory */
|
|
||||||
oggz_close(track_og);
|
|
||||||
|
|
||||||
v->voiceclient->insert_marker(music.fileName + " end");
|
|
||||||
|
|
||||||
std::cout << "audio sending complete\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void MusicQueue::play()
|
|
||||||
{
|
|
||||||
if (!playMutex.try_lock())
|
|
||||||
{
|
|
||||||
std::cout << "Already playing\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dpp::discord_client* joinedShard = botCluster->get_shard(id.shard_id);
|
|
||||||
if (!joinedShard)
|
|
||||||
{
|
|
||||||
std::cout << "No shard\n";
|
|
||||||
playMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dpp::voiceconn* v = joinedShard->get_voice(id.guild_id);
|
|
||||||
if (!v || !v->voiceclient || !v->voiceclient->is_ready())
|
|
||||||
{
|
|
||||||
std::cout << "not in voicechat. quit musicplay";
|
|
||||||
playMutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
markerCallback();
|
|
||||||
}
|
|
||||||
10
src/main.cc
Normal file
10
src/main.cc
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "precomp.h"
|
||||||
|
#include "utils/console.h"
|
||||||
|
#include "utils/update_checker.h"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
boost::asio::io_context ctx;
|
||||||
|
utils::CheckUpdate(ctx);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
18
src/main.cpp
18
src/main.cpp
@@ -1,18 +0,0 @@
|
|||||||
#include <BumbleCeepp.hpp>
|
|
||||||
#include <dpp/nlohmann/json.hpp>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
json configdocument;
|
|
||||||
std::ifstream configfile("config.json");
|
|
||||||
configfile >> configdocument;
|
|
||||||
|
|
||||||
std::shared_ptr<BumbleCeepp> bumbleBee = std::make_shared<BumbleCeepp>(configdocument["token"], 1);
|
|
||||||
|
|
||||||
bumbleBee->start();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
53
src/utils/console.cc
Normal file
53
src/utils/console.cc
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include "utils/console.h"
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
int ValidateCommand(boost::asio::io_context& ctx, std::string cmd,
|
||||||
|
const std::vector<std::string>& args) {
|
||||||
|
try {
|
||||||
|
ExecuteCommand(ctx, cmd, args);
|
||||||
|
} catch (const boost::process::system_error& e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args) {
|
||||||
|
std::string ignored;
|
||||||
|
return ExecuteCommand(ctx, cmd, args, ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
std::string& result) {
|
||||||
|
std::vector<std::string> ignored;
|
||||||
|
return ExecuteCommand(ctx, cmd, ignored, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExecuteCommand(boost::asio::io_context& ctx, const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args, std::string& result) {
|
||||||
|
try {
|
||||||
|
boost::system::error_code ec;
|
||||||
|
boost::process::popen proc(
|
||||||
|
ctx, cmd, args, boost::process::process_stdio{{}, nullptr, nullptr});
|
||||||
|
|
||||||
|
boost::asio::read(proc, boost::asio::dynamic_buffer(result), ec);
|
||||||
|
|
||||||
|
proc.wait();
|
||||||
|
|
||||||
|
return proc.exit_code();
|
||||||
|
} catch (const boost::process::system_error& e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::process::popen OpenPipe(boost::asio::io_context& ctx,
|
||||||
|
const std::string& cmd,
|
||||||
|
const std::vector<std::string>& args) {
|
||||||
|
return boost::process::popen(
|
||||||
|
ctx, cmd, args, boost::process::process_stdio{nullptr, nullptr, nullptr});
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
119
src/utils/file_downloader.cc
Normal file
119
src/utils/file_downloader.cc
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#include "utils/file_downloader.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include "boost/asio/ssl.hpp"
|
||||||
|
#include "boost/beast.hpp"
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
void DownloadFileFromHTTPS(std::string url, std::string filename) {
|
||||||
|
int max_redirects = 5;
|
||||||
|
|
||||||
|
std::string current_host;
|
||||||
|
std::string current_path;
|
||||||
|
|
||||||
|
if (url.find("https://") == 0) {
|
||||||
|
url.erase(0, 8); // https:// 제거
|
||||||
|
auto pos = url.find('/');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
current_host = url.substr(0, pos);
|
||||||
|
current_path = url.substr(pos);
|
||||||
|
} else {
|
||||||
|
current_host = url;
|
||||||
|
current_path = "/";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 상대 경로일 경우
|
||||||
|
current_path = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int redirect = 0; redirect < max_redirects; ++redirect) {
|
||||||
|
boost::asio::io_context ioc;
|
||||||
|
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);
|
||||||
|
ctx.set_default_verify_paths();
|
||||||
|
|
||||||
|
boost::beast::ssl_stream<boost::beast::tcp_stream> stream(ioc, ctx);
|
||||||
|
|
||||||
|
// DNS 해석
|
||||||
|
boost::asio::ip::tcp::resolver resolver(ioc);
|
||||||
|
auto const results = resolver.resolve(current_host, "443");
|
||||||
|
|
||||||
|
// TCP 연결
|
||||||
|
boost::beast::get_lowest_layer(stream).connect(results);
|
||||||
|
|
||||||
|
// SSL 핸드셰이크
|
||||||
|
stream.handshake(boost::asio::ssl::stream_base::client);
|
||||||
|
|
||||||
|
// HTTP GET 요청
|
||||||
|
boost::beast::http::request<boost::beast::http::string_body> req{
|
||||||
|
boost::beast::http::verb::get, current_path, 11};
|
||||||
|
req.set(boost::beast::http::field::host, current_host);
|
||||||
|
req.set(boost::beast::http::field::user_agent, "Mozilla/5.0");
|
||||||
|
|
||||||
|
boost::beast::http::write(stream, req);
|
||||||
|
|
||||||
|
boost::beast::flat_buffer buffer;
|
||||||
|
|
||||||
|
// 응답 파서 만들기
|
||||||
|
boost::beast::http::response_parser<boost::beast::http::dynamic_body>
|
||||||
|
parser;
|
||||||
|
|
||||||
|
// body 제한 해제 (무제한)
|
||||||
|
parser.body_limit((std::numeric_limits<std::uint64_t>::max)());
|
||||||
|
|
||||||
|
// 응답 읽기
|
||||||
|
boost::beast::http::read(stream, buffer, parser);
|
||||||
|
|
||||||
|
auto res = parser.release();
|
||||||
|
|
||||||
|
int status = res.result_int();
|
||||||
|
if (status / 100 == 3) {
|
||||||
|
// 리다이렉트 처리
|
||||||
|
auto loc = res[boost::beast::http::field::location];
|
||||||
|
if (loc.empty()) {
|
||||||
|
throw std::runtime_error("Redirect without Location header");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 새 호스트/경로 파싱
|
||||||
|
std::string new_url(loc);
|
||||||
|
if (new_url.find("https://") == 0) {
|
||||||
|
new_url.erase(0, 8); // https:// 제거
|
||||||
|
auto pos = new_url.find('/');
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
current_host = new_url.substr(0, pos);
|
||||||
|
current_path = new_url.substr(pos);
|
||||||
|
} else {
|
||||||
|
current_host = new_url;
|
||||||
|
current_path = "/";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 상대 경로일 경우
|
||||||
|
current_path = new_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != 200) {
|
||||||
|
throw std::runtime_error("HTTP request failed with status " +
|
||||||
|
std::to_string(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일 저장
|
||||||
|
std::ofstream file(filename, std::ios::binary);
|
||||||
|
if (!file) {
|
||||||
|
throw std::runtime_error("Could not open file for writing: " + filename);
|
||||||
|
}
|
||||||
|
for (auto const& buffer_part : res.body().data()) {
|
||||||
|
file.write(reinterpret_cast<const char*>(buffer_part.data()),
|
||||||
|
buffer_part.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::runtime_error("Too many redirects");
|
||||||
|
}
|
||||||
|
} // namespace utils
|
||||||
71
src/utils/update_checker.cc
Normal file
71
src/utils/update_checker.cc
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#include "utils/update_checker.h"
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
#include "utils/console.h"
|
||||||
|
#include "utils/file_downloader.h"
|
||||||
|
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
int InstallYtdlp(boost::asio::io_context& ctx) {
|
||||||
|
BOOST_LOG_TRIVIAL(warning) << "ytdlp is unavailable. downloading ytdlp...";
|
||||||
|
#ifdef WIN32
|
||||||
|
DownloadFileFromHTTPS(
|
||||||
|
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe",
|
||||||
|
"yt-dlp.exe");
|
||||||
|
#else
|
||||||
|
DownloadFileFromHTTPS(
|
||||||
|
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp",
|
||||||
|
"yt-dlp");
|
||||||
|
ExecuteCommand(ctx,
|
||||||
|
boost::process::environment::find_executable("chmod").string(),
|
||||||
|
{"+x", "yt-dlp"});
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int FindNewLinePos(std::string& string, int start_pos) {
|
||||||
|
int newline_pos = start_pos;
|
||||||
|
while (newline_pos < string.size()) {
|
||||||
|
if (string[newline_pos] == '\n') {
|
||||||
|
return newline_pos;
|
||||||
|
}
|
||||||
|
newline_pos++;
|
||||||
|
}
|
||||||
|
return newline_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CheckUpdate(boost::asio::io_context& ctx) {
|
||||||
|
std::string output = "";
|
||||||
|
int old_newline_pos = 0;
|
||||||
|
int newline_pos = 0;
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
if (ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output) !=
|
||||||
|
0) {
|
||||||
|
InstallYtdlp(ctx);
|
||||||
|
ExecuteCommand(ctx, "yt-dlp.exe", {"--version", "--newline"}, output);
|
||||||
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
|
||||||
|
<< output.substr(0, output.size() - 1);
|
||||||
|
output = "";
|
||||||
|
ExecuteCommand(ctx, "yt-dlp.exe", {"-U", "--newline"}, output);
|
||||||
|
#else
|
||||||
|
if (ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output) != 0) {
|
||||||
|
InstallYtdlp(ctx);
|
||||||
|
ExecuteCommand(ctx, "yt-dlp", {"--version", "--newline"}, output);
|
||||||
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "yt-dlp version: "
|
||||||
|
<< output.substr(0, output.size() - 1);
|
||||||
|
output = "";
|
||||||
|
ExecuteCommand(ctx, "yt-dlp", {"-U", "--newline"}, output);
|
||||||
|
#endif
|
||||||
|
while (newline_pos < output.size()) {
|
||||||
|
old_newline_pos = newline_pos;
|
||||||
|
newline_pos = FindNewLinePos(output, newline_pos);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << output.substr(old_newline_pos, newline_pos - 1);
|
||||||
|
newline_pos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace utils
|
||||||
BIN
src/yt-dlp
BIN
src/yt-dlp
Binary file not shown.
@@ -1,47 +0,0 @@
|
|||||||
import yt_dlp
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
ydl_opts = {
|
|
||||||
'quiet': True,
|
|
||||||
'clean_infojson': False,
|
|
||||||
'default_search': 'ytsearch',
|
|
||||||
'format': '251',
|
|
||||||
'outtmpl': {'default': 'Temp/%(id)s.temp'},
|
|
||||||
'overwrites': False,
|
|
||||||
'writeinfojson': True }
|
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
||||||
info = ydl.extract_info(sys.argv[1], download=False)
|
|
||||||
id = list()
|
|
||||||
with open("out", "w") as f:
|
|
||||||
f.write(json.dumps(ydl.sanitize_info(info)))
|
|
||||||
with open("Music/Archive", "r") as f:
|
|
||||||
ArchiveList = f.read().split("\n")
|
|
||||||
if "entries" in info:
|
|
||||||
if len(info["entries"]) != 0:
|
|
||||||
for entry in info["entries"]:
|
|
||||||
if entry["id"] not in ArchiveList:
|
|
||||||
ydl.download(entry["webpage_url"])
|
|
||||||
os.system("echo " + entry["id"] + " >> Music/Archive")
|
|
||||||
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + entry["id"] + ".temp" + "\" -c copy Music/" + entry["id"] + ".ogg")
|
|
||||||
os.system("mv Temp/" + entry["id"] + ".temp.info.json Music/" + entry["id"] + ".info.json")
|
|
||||||
id.append(entry["id"])
|
|
||||||
else:
|
|
||||||
if info["id"] not in ArchiveList:
|
|
||||||
ydl.download(info["webpage_url"])
|
|
||||||
os.system("echo " + info["id"] + " >> Music/Archive")
|
|
||||||
os.system("yes n 2>/dev/null | ffmpeg -hide_banner -loglevel error -i \"" + "Temp/" + info["id"] + ".temp" + "\" -c copy Music/" + info["id"] + ".ogg")
|
|
||||||
os.system("mv Temp/" + info["id"] + ".temp.info.json Music/" + info["id"] + ".info.json")
|
|
||||||
id.append(info["id"])
|
|
||||||
|
|
||||||
os.system("rm -f Temp/*.temp")
|
|
||||||
os.system("rm -f Temp/*.json")
|
|
||||||
|
|
||||||
with open("Temp/CurMusic", "w") as f:
|
|
||||||
for item in id:
|
|
||||||
f.write(item + "\n")
|
|
||||||
12
streamOpus.sh
Executable file
12
streamOpus.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
YTDLP_CMD=$1
|
||||||
|
FFMPEG_CMD=$2
|
||||||
|
URL=$3
|
||||||
|
|
||||||
|
$YTDLP_CMD -o - --quiet --ignore-errors -f bestaudio $URL 2>/dev/null | \
|
||||||
|
$FFMPEG_CMD -hwaccel vaapi -i - -loglevel quiet -hide_banner -c:a copy -f opus - || \
|
||||||
|
$YTDLP_CMD -o - --quiet --ignore-errors -f bestaudio $URL 2>/dev/null | \
|
||||||
|
$FFMPEG_CMD -hwaccel vaapi -i - -loglevel quiet -hide_banner -f opus -c:a libopus -b:a 128k -ar 48000 -ac 2 -
|
||||||
|
|
||||||
|
# -loglevel quiet
|
||||||
8
tests/CMakeLists.txt
Normal file
8
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
file(GLOB_RECURSE TEST_SOURCES "*.cpp" "*.cxx" "*.cc")
|
||||||
|
|
||||||
|
foreach(test_src ${TEST_SOURCES})
|
||||||
|
get_filename_component(test_name ${test_src} NAME_WE)
|
||||||
|
add_executable(${test_name} ${test_src})
|
||||||
|
target_link_libraries(${test_name} PRIVATE ${BOT_NAME}_lib)
|
||||||
|
add_test(NAME ${test_name} COMMAND ${test_name})
|
||||||
|
endforeach()
|
||||||
52
tests/basic_yt_dlp_download.cc
Normal file
52
tests/basic_yt_dlp_download.cc
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include "precomp.h"
|
||||||
|
#include "utils/console.h"
|
||||||
|
#include "utils/update_checker.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
boost::asio::io_context ctx;
|
||||||
|
boost::system::error_code ec;
|
||||||
|
|
||||||
|
utils::CheckUpdate(ctx);
|
||||||
|
|
||||||
|
char buf[8192];
|
||||||
|
#ifdef WIN32
|
||||||
|
/*try {
|
||||||
|
auto ytdlp_pipe = utils::OpenPipe(ctx,
|
||||||
|
"yt-dlp.exe", { "-o", "-", "--quiet", "--ignore-errors", "-f",
|
||||||
|
"bestaudio", "https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR" });
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
boost::system::error_code read_ec;
|
||||||
|
size_t bytes_read =
|
||||||
|
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf,
|
||||||
|
8192), read_ec); if (bytes_read > 0) { std::cout.write(buf, bytes_read);
|
||||||
|
}
|
||||||
|
if (read_ec == boost::asio::error::eof || read_ec) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const boost::process::system_error& e) {
|
||||||
|
std::string error = e.what();
|
||||||
|
return -1;
|
||||||
|
}*/
|
||||||
|
#else
|
||||||
|
auto ytdlp_pipe = utils::OpenPipe(
|
||||||
|
ctx, "yt-dlp",
|
||||||
|
{"-o", "-", "--quiet", "--ignore-errors", "-f", "bestaudio",
|
||||||
|
"https://youtu.be/9_bTl2vvYQg?si=IVhvpDhnpPvziwQR"});
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
boost::system::error_code read_ec;
|
||||||
|
size_t bytes_read =
|
||||||
|
boost::asio::read(ytdlp_pipe, boost::asio::buffer(buf, 8192), read_ec);
|
||||||
|
if (bytes_read > 0) {
|
||||||
|
std::cout.write(buf, bytes_read);
|
||||||
|
}
|
||||||
|
if (read_ec == boost::asio::error::eof || read_ec) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
tests/update.cc
Normal file
8
tests/update.cc
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "precomp.h"
|
||||||
|
#include "utils/update_checker.h"
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
boost::asio::io_context ctx;
|
||||||
|
utils::CheckUpdate(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user