Skip to content

Commit cd384d3

Browse files
Merge pull request #10 from Henonicks/dev
2 parents c6af373 + 1c1e813 commit cd384d3

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "DPP"]
2+
path = DPP
3+
url = https://github.com/brainboxdotcc/DPP

CMakeLists.txt

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.6)
1+
cmake_minimum_required (VERSION 3.15)
22

33
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
44
set(BOT_NAME "templatebot")
@@ -50,26 +50,19 @@ if (DPP_FOUND)
5050
target_link_libraries(${BOT_NAME} ${DPP_LIBRARIES})
5151
target_include_directories(${BOT_NAME} PUBLIC ${DPP_INCLUDE_DIR})
5252
else()
53-
message(WARNING "Could not find DPP install. Building from source instead.")
54-
option(DPP_BUILD_TEST "" OFF)
55-
include(FetchContent)
56-
57-
FetchContent_Declare(
58-
libdpp
59-
GIT_REPOSITORY https://github.com/brainboxdotcc/DPP.git
60-
GIT_TAG master)
61-
62-
FetchContent_GetProperties(libdpp)
63-
if(NOT libdpp_POPULATED)
64-
FetchContent_Populate(libdpp)
65-
target_include_directories(${BOT_NAME} PUBLIC
66-
${libdpp_SOURCE_DIR}/include
67-
)
68-
add_subdirectory(
69-
${libdpp_SOURCE_DIR}
70-
${libdpp_BINARY_DIR}
71-
EXCLUDE_FROM_ALL)
72-
endif()
73-
74-
target_link_libraries(${BOT_NAME} dpp)
53+
find_package(Git)
54+
message(WARNING "Could not find DPP install. Building from source instead.")
55+
if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
56+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init
57+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
58+
RESULT_VARIABLE RESULT)
59+
if (NOT RESULT EQUAL 0)
60+
message(FATAL_ERROR "Failed to update the D++ submodule. Code: ${RESULT}.")
61+
else()
62+
add_subdirectory(DPP)
63+
target_link_libraries(${BOT_NAME} dpp)
64+
endif()
65+
else()
66+
message(FATAL_ERROR "Failed to find the git executable. Can't update the D++ submodule.")
67+
endif()
7568
endif()

DPP

Submodule DPP added at 8293247

src/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <templatebot/templatebot.h>
2-
#include <sstream>
32

43
/* When you invite the bot, be sure to invite it with the
54
* scopes 'bot' and 'applications.commands', e.g.
@@ -8,14 +7,15 @@
87

98
using json = nlohmann::json;
109

11-
int main(int argc, char const *argv[])
12-
{
10+
int main(int argc, char const *argv[]) {
1311
json configdocument;
1412
std::ifstream configfile("../config.json");
1513
configfile >> configdocument;
1614

17-
/* Setup the bot */
18-
dpp::cluster bot(configdocument["token"]);
15+
const std::string BOT_TOKEN = configdocument["token"];
16+
17+
/* Set up the bot */
18+
dpp::cluster bot(BOT_TOKEN);
1919

2020
/* Output simple log messages to stdout */
2121
bot.on_log(dpp::utility::cout_logger());
@@ -29,7 +29,7 @@ int main(int argc, char const *argv[])
2929

3030
/* Register slash command here in on_ready */
3131
bot.on_ready([&bot](const dpp::ready_t& event) {
32-
/* Wrap command registration in run_once to make sure it doesnt run on every full reconnection */
32+
/* Wrap command registration in run_once to make sure it doesn't run on every full reconnection */
3333
if (dpp::run_once<struct register_bot_commands>()) {
3434
bot.global_command_create(dpp::slashcommand("ping", "Ping pong!", bot.me.id));
3535
}

0 commit comments

Comments
 (0)