Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #7

Merged
merged 6 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"clion",
"followup",
"gifv",
"ctls"
"ctls",
"ctest"
],
"flagWords": [
"hte"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: cd build && ninja

- name: Run unit tests
run: cd build && ./test
run: cd build && ctest -VV
env:
DPP_UNIT_TEST_TOKEN: ${{secrets.DPP_UNIT_TEST_TOKEN}}
TEST_GUILD_ID: ${{secrets.TEST_GUILD_ID}}
Expand Down
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,16 @@ target_compile_features(dpp PRIVATE cxx_variadic_templates)
target_compile_features(dpp PRIVATE cxx_attribute_deprecated)

if (DPP_BUILD_TEST)
add_executable(test ${coresrc})
target_compile_features(test PRIVATE cxx_std_17)
target_link_libraries(test PUBLIC ${modname})
enable_testing(${PROJECT_SOURCE_DIR})
add_executable(unittest ${coresrc})
target_compile_features(unittest PRIVATE cxx_std_17)
target_link_libraries(unittest PUBLIC ${modname})
add_test(
NAME unittests
COMMAND unittest
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)

endif()

if(HAVE_PRCTL)
Expand Down Expand Up @@ -333,3 +340,4 @@ include("cmake/CPackSetup.cmake") # Setup information for packaging and dis

# CPack initialization for distribution
include(CPack)

2 changes: 1 addition & 1 deletion docpages/03_example_programs.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ int main() {

### 7. Compile and run your bot

Compile your bot using `g++ -std=c++17 -o test test.cpp -ldpp` (if your .cpp file is called `test.cpp`) and run it with `./test`.
Compile your bot using `g++ -std=c++17 -o bot bot.cpp -ldpp` (if your .cpp file is called `bot.cpp`) and run it with `./bot`.

### 8. Inviting your bot to your server

Expand Down
6 changes: 4 additions & 2 deletions docpages/04_advanced_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Before running test cases, create a test server for your test bot. You should:
* Create at least one voice channel
* Create at least one text channel

Then, set the following variables to the appropriate values. (This uses a fake token, don't bother trying to use it.)
Then, set the following variables to the appropriate values. (Below is a fake token, don't bother trying to use it)

export DPP_UNIT_TEST_TOKEN="ODI2ZSQ4CFYyMzgxUzkzzACy.HPL5PA.9qKR4uh8po63-pjYVrPAvQQO4ln"
export TEST_GUILD_ID="907951970017480704"
Expand All @@ -171,7 +171,9 @@ Then, set the following variables to the appropriate values. (This uses a fake t
export TEST_USER_ID="826535422381391913"
export TEST_EVENT_ID="909928577951203360"

Then, after cloning and building DPP, run `./build/test` for unit test cases.
Then, after cloning and building DPP, run `cd build && ctest -VV` for unit test cases.

If you do not specify the `DPP_UNIT_TEST_TOKEN` environment variable, a subset of the tests will run which do not require discord connectivity.

\page lambdas-and-locals Ownership of local variables and safely transferring into a lambda

Expand Down
3 changes: 3 additions & 0 deletions include/dpp/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t {
virtual ~interaction_create_t() = default;
};

/**
* @brief User has issued a slash command
*/
struct DPP_EXPORT slashcommand_t : public interaction_create_t {
public:
/** Constructor
Expand Down
15 changes: 9 additions & 6 deletions include/dpp/permissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ class DPP_EXPORT permission {
* @return permission& reference to self for chaining
*/
template <typename... T>
permission& add(T... values) {
(value |= (0 | ... | values));
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
add(T... values) {
value |= (0 | ... | values);
return *this;
}

Expand All @@ -165,8 +166,9 @@ class DPP_EXPORT permission {
* @return permission& reference to self for chaining
*/
template <typename... T>
permission& set(T... values) {
(value = (0 | ... | values));
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
set(T... values) {
value = (0 | ... | values);
return *this;
}

Expand All @@ -185,8 +187,9 @@ class DPP_EXPORT permission {
* @return permission& reference to self for chaining
*/
template <typename... T>
permission& remove(T... values) {
(value &= ~(0 | ... | values));
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
remove(T... values) {
value &= ~(0 | ... | values);
return *this;
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/dpp/cluster/webhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ void cluster::execute_webhook(const class webhook &wh, const struct message& m,
{"wait", wait},
{"thread_id", thread_id},
});
rest_request<message>(this, API_PATH "/webhooks", std::to_string(wh.id), utility::url_encode(!wh.token.empty() ? wh.token: token) + parameters, m_post, m.build_json(false), callback);
this->post_rest_multipart(API_PATH API_PATH "/webhooks", std::to_string(wh.id), utility::url_encode(!wh.token.empty() ? wh.token: token) + parameters, m_post, m.build_json(), [this, callback](json &j, const http_request_completion_t& http) {
if (callback) {
callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http));
}
}, m.filename, m.filecontent);
}


Expand Down