Debian Codegraph @

src/userapptest/userapp.cpp

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ************************************************************************************/
22
23 #include <dpp/dpp.h>
24 #include <iostream>
25
26 int main() {
27 char* t = getenv("DPP_UNIT_TEST_TOKEN");
28
29 if (!t) {
30 std::cerr << "Missing DPP_UNIT_TEST_TOKEN\n";
31 exit(1);
32 }
33
34 dpp::cluster bot(t, dpp::i_default_intents);
35 bot.on_log(dpp::utility::cout_logger());
36
37 bot.on_ready([&bot](const auto& event) {
38 if (dpp::run_once<struct boot_t>()) {
39 /**
40 * Create a slash command which has interaction context 'itc_private_channel'.
41 * This is a user-app command which can be executed anywhere and is added to the user's profile.
42 */
43 bot.global_bulk_command_create({
44 dpp::slashcommand("userapp", "Test command", bot.me.id)
45 .set_interaction_contexts({dpp::itc_guild, dpp::itc_bot_dm, dpp::itc_private_channel})
46 });
47 }
48 });
49
50 bot.on_button_click([](const dpp::button_click_t& event) {
51 event.reply("You declared your love for cats by clicking button id: " + event.custom_id);
52 });
53
54 bot.register_command("userapp", [](const dpp::slashcommand_t& e) {
55 e.reply(dpp::message().set_flags(dpp::m_using_components_v2).add_component_v2(
56 /* A container... */
57 dpp::component()
58 .set_type(dpp::cot_container)
59 .set_accent(dpp::utility::rgb(255, 0, 0))
60 .set_spoiler(true)
61 .add_component_v2(
62 /* ...which contains a section... */
63 dpp::component()
64 .set_type(dpp::cot_section)
65 .add_component_v2(
66 /* ...with text... */
67 dpp::component()
68 .set_type(dpp::cot_text_display)
69 .set_content("Click if you love cats")
70 )
71 .set_accessory(
72 /* ...and an accessory button to the right */
73 dpp::component()
74 .set_type(dpp::cot_button)
75 .set_label("Click me")
76 .set_style(dpp::cos_danger)
77 .set_id("button")
78 )
79 )
80 ).add_component_v2(
81 /* ... with a large visible divider between... */
82 dpp::component()
83 .set_type(dpp::cot_separator)
84 .set_spacing(dpp::sep_large)
85 .set_divider(true)
86 ).add_component_v2(
87 /* ... followed by a media gallery... */
88 dpp::component()
89 .set_type(dpp::cot_media_gallery)
90 .add_media_gallery_item(
91 /* ...containing one cat pic (obviously) */
92 dpp::component()
93 .set_type(dpp::cot_thumbnail)
94 .set_description("A cat")
95 .set_thumbnail("https://www.catster.com/wp-content/uploads/2023/11/Beluga-Cat-e1714190563227.webp")
96 )
97 ));
98 });
99
100 bot.start(dpp::st_wait);
101 }