| 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>cxx . . $ `<file>/include/dpp/dpp.h`/ |
| 24 | #include <iostream> |
| 25 | |
| 26 | /** |
| 27 | * @brief Generate a simple html response |
| 28 | * @param request request to respond to |
| 29 | */ |
| 30 | void respondcxx . . $ respond(b2ba89cf2fa5e1be).(dppcxx . . $ dpp/::http_server_requestcxx . . $ dpp/http_server_request#& request) { |
| 31 | request.set_statuscxx . . $ dpp/http_server_request#set_status(de799747b7541414).(200).set_response_headercxx . . $ dpp/http_server_request#set_response_header(5fe2a57fb7c6af6d).("Content-Type"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "text/html"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).).set_response_bodycxx . . $ dpp/http_server_request#set_response_body(3a2eab05f88d318a).("<h1>It lives!</h1>"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 32 | } |
| 33 | |
| 34 | int maincxx . . $ main(b126dc7c1de90089).() { |
| 35 | using namespace stdcxx . . $ std/::chrono_literals; |
| 36 | char* t = getenv("DPP_UNIT_TEST_TOKEN"); |
| 37 | if (t) { |
| 38 | dppcxx . . $ dpp/::clustercxx . . $ dpp/cluster# botcxx . . $ dpp/cluster#cluster(13cb741d36ace229).(tcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., 0, dppcxx . . $ dpp/::NO_SHARDScxx . . $ dpp/NO_SHARDS., 1, 1, false, dppcxx . . $ dpp/::cache_policycxx . . $ dpp/cache_policy/::cpol_nonecxx . . $ dpp/cache_policy/cpol_none.); |
| 39 | dppcxx . . $ dpp/::http_servercxx . . $ dpp/http_server# *server1{nullptr}, *server2{nullptr}; |
| 40 | |
| 41 | bot.on_logcxx . . $ dpp/cluster#on_log.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::log_tcxx . . $ dpp/log_t#& log) { |
| 42 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "[" <<cxx . . $ std/`operator<<`(88df5bef833f7f83). dppcxx . . $ dpp/::utilitycxx . . $ dpp/utility/::current_date_timecxx . . $ dpp/utility/current_date_time(efd28698952f529a).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "] " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). dppcxx . . $ dpp/::utilitycxx . . $ dpp/utility/::loglevelcxx . . $ dpp/utility/loglevel(bd6669da0656db).(log.severitycxx . . $ dpp/log_t#severity.) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). log.messagecxx . . $ dpp/log_t#message. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 43 | }); |
| 44 | bot.on_readycxx . . $ dpp/cluster#on_ready.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::ready_tcxx . . $ dpp/ready_t#& ready) { |
| 45 | |
| 46 | /* A plaintext HTTP server on port 3011 */ |
| 47 | server1 = new dppcxx . . $ dpp/::http_servercxx . . $ dpp/http_server#(&bot, "0.0.0.0"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792)., 3011, [cxx . . $ std/function#function(bdc3712e480e4d04).&bot](dppcxx . . $ dpp/::http_server_requestcxx . . $ dpp/http_server_request#* request) { |
| 48 | respondcxx . . $ respond(b2ba89cf2fa5e1be).(*request); |
| 49 | }); |
| 50 | |
| 51 | /* An SSL enabled HTTPS server on port 3042 */ |
| 52 | server2 = new dppcxx . . $ dpp/::http_servercxx . . $ dpp/http_server#(&bot, "0.0.0.0"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792)., 3042, [cxx . . $ std/function#function(bdc3712e480e4d04).&bot](dppcxx . . $ dpp/::http_server_requestcxx . . $ dpp/http_server_request#* request) { |
| 53 | respondcxx . . $ respond(b2ba89cf2fa5e1be).(*request); |
| 54 | }, "../../testdata/localhost.key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "../../testdata/localhost.pem"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 55 | |
| 56 | /* A discord interactions endpoint on port 3010 */ |
| 57 | bot.enable_webhook_servercxx . . $ dpp/cluster#enable_webhook_server(5f55eafb17e19bc7).(getenvcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).("DPP_PUBLIC_KEY"), "0.0.0.0"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792)., 3010); |
| 58 | }); |
| 59 | bot.on_slashcommandcxx . . $ dpp/cluster#on_slashcommand.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::slashcommand_tcxx . . $ dpp/slashcommand_t#& event) { |
| 60 | event.replycxx . . $ dpp/interaction_create_t#reply(fd6834981af6b30e).("hello"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 61 | }); |
| 62 | |
| 63 | bot.startcxx . . $ dpp/cluster#start(fa7c3f1aeb8ff3e5).(dppcxx . . $ dpp/::st_waitcxx . . $ dpp/st_wait.); |
| 64 | } |
| 65 | } |