| 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 | #include <dpp/dpp.h>cxx . . $ `<file>/include/dpp/dpp.h`/ |
| 23 | #include <iostream> |
| 24 | #include <string> |
| 25 | |
| 26 | stdcxx . . $ std/::stringcxx . . $ std/string# get_testdata_dircxx . . $ get_testdata_dir(efd28698952f529a).() { |
| 27 | char *env_var = getenv("TEST_DATA_DIR"); |
| 28 | return (cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).env_var ? env_var : "../../testdata/"); |
| 29 | } |
| 30 | |
| 31 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> load_test_audiocxx . . $ load_test_audio(695134cc693f8bd0).() { |
| 32 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> testaudiocxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 33 | stdcxx . . $ std/::stringcxx . . $ std/string# dir = get_testdata_dircxx . . $ get_testdata_dir(efd28698952f529a).(); |
| 34 | stdcxx . . $ std/::ifstreamcxx . . $ std/ifstream# inputcxx . . $ std/basic_ifstream#basic_ifstream(be6c264dafcf0985). (dir +cxx . . $ std/operator+(40fc1db9226233c6). "Robot.pcm", stdcxx . . $ std/::ioscxx . . $ std/ios#::incxx . . $ std/ios_base#in.|cxx . . $ std/`operator|`(2dd9eb40323da8bf).stdcxx . . $ std/::ioscxx . . $ std/ios#::binarycxx . . $ std/ios_base#binary.|cxx . . $ std/`operator|`(2dd9eb40323da8bf).stdcxx . . $ std/::ioscxx . . $ std/ios#::atecxx . . $ std/ios_base#ate.); |
| 35 | if (input.is_opencxx . . $ std/basic_ifstream#is_open(c9857a73d68e59ba).()) { |
| 36 | size_tcxx . . $ size_t# testaudio_size = input.tellgcxx . . $ std/basic_istream#tellg(bf66e90edbd3e74a).(); |
| 37 | testaudio.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(testaudio_size); |
| 38 | input.seekgcxx . . $ std/basic_istream#seekg(f79fad2892c4fe4).(0, stdcxx . . $ std/::ioscxx . . $ std/ios#::begcxx . . $ std/ios_base#beg.); |
| 39 | input.readcxx . . $ std/basic_istream#read(ec7d6f01d31dcb96).((char*)testaudio.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), testaudio_size); |
| 40 | input.closecxx . . $ std/basic_ifstream#close(49f6e7a06ebc5aa8).(); |
| 41 | } |
| 42 | else { |
| 43 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). "ERROR: Can't load " +cxx . . $ std/operator+(42c652dfebe55ad7). dir +cxx . . $ std/operator+(900ec9581c410ad9). "Robot.pcm\n"; |
| 44 | exit(1); |
| 45 | } |
| 46 | return testaudiocxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 47 | } |
| 48 | |
| 49 | int maincxx . . $ main(b126dc7c1de90089).() { |
| 50 | |
| 51 | using namespace stdcxx . . $ std/::chrono_literals; |
| 52 | char* t = getenv("DPP_UNIT_TEST_TOKEN"); |
| 53 | if (t == nullptr || getenv("TEST_GUILD_ID") == nullptr || getenv("TEST_VC_ID") == nullptr) { |
| 54 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Missing unit test environment. Set DPP_UNIT_TEST_TOKEN, TEST_GUILD_ID, and TEST_VC_ID\n"; |
| 55 | exit(1); |
| 56 | } |
| 57 | dppcxx . . $ dpp/::snowflakecxx . . $ dpp/snowflake# TEST_GUILD_IDcxx . . $ dpp/snowflake#snowflake(80d8335016fb1bdc).(stdcxx . . $ std/::stringcxx . . $ std/string#(getenv("TEST_GUILD_ID"))); |
| 58 | dppcxx . . $ dpp/::snowflakecxx . . $ dpp/snowflake# TEST_VC_IDcxx . . $ dpp/snowflake#snowflake(80d8335016fb1bdc).(stdcxx . . $ std/::stringcxx . . $ std/string#(getenv("TEST_VC_ID"))); |
| 59 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Test Guild ID: " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). TEST_GUILD_ID <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " Test VC ID: " <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). TEST_VC_ID <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n\n"; |
| 60 | dppcxx . . $ dpp/::clustercxx . . $ dpp/cluster# dave_testcxx . . $ dpp/cluster#cluster(13cb741d36ace229).(tcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., dppcxx . . $ dpp/::i_default_intentscxx . . $ dpp/i_default_intents., 1, 0, 1, false, dppcxx . . $ dpp/::cache_policy_tcxx . . $ dpp/cache_policy_t#{ dppcxx . . $ dpp/::cp_nonecxx . . $ dpp/cp_none., dppcxx . . $ dpp/::cp_nonecxx . . $ dpp/cp_none., dppcxx . . $ dpp/::cp_nonecxx . . $ dpp/cp_none., dppcxx . . $ dpp/::cp_nonecxx . . $ dpp/cp_none., dppcxx . . $ dpp/::cp_nonecxx . . $ dpp/cp_none. }); |
| 61 | |
| 62 | dave_test.on_logcxx . . $ dpp/cluster#on_log.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::log_tcxx . . $ dpp/log_t#& log) { |
| 63 | 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).; |
| 64 | }); |
| 65 | |
| 66 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> testaudio = load_test_audiocxx . . $ load_test_audio(695134cc693f8bd0).(); |
| 67 | |
| 68 | dave_test.on_voice_readycxx . . $ dpp/cluster#on_voice_ready.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::voice_ready_tcxx . . $ dpp/voice_ready_t# & event) { |
| 69 | dave_test.logcxx . . $ dpp/cluster#log(7f5f639e8434218f).(dppcxx . . $ dpp/::ll_infocxx . . $ dpp/ll_info., "Voice channel ready, sending audio..."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 70 | dppcxx . . $ dpp/::discord_voice_clientcxx . . $ dpp/discord_voice_client#* v = event.voice_clientcxx . . $ dpp/voice_ready_t#voice_client.; |
| 71 | if (v && v->is_readycxx . . $ dpp/discord_voice_client#is_ready(c9857a73d68e59ba).()) { |
| 72 | v->send_audio_rawcxx . . $ dpp/discord_voice_client#send_audio_raw(ccf5db8c4f4f7e6a).((uint16_tcxx . . $ uint16_t#*)testaudio.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), testaudio.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 73 | } |
| 74 | dave_test.start_timercxx . . $ dpp/cluster#start_timer(9b5287c873d344e0).([cxx . . $ std/function#function(bdc3712e480e4d04).v, &testaudio](auto) { |
| 75 | v->send_audio_rawcxx . . $ dpp/discord_voice_client#send_audio_raw(ccf5db8c4f4f7e6a).((uint16_tcxx . . $ uint16_t#*)testaudio.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(), testaudio.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 76 | }, 15); |
| 77 | }); |
| 78 | |
| 79 | |
| 80 | dave_test.on_guild_createcxx . . $ dpp/cluster#on_guild_create.(cxx . . $ dpp/event_router_t#`operator()`(7d840609c6f74506).[&](const dppcxx . . $ dpp/::guild_create_tcxx . . $ dpp/guild_create_t# & event) { |
| 81 | if (event.createdcxx . . $ dpp/guild_create_t#created..idcxx . . $ dpp/managed#id. ==cxx . . $ dpp/snowflake#`operator==`(b7f99ffc707c9db7). TEST_GUILD_IDcxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a).) { |
| 82 | dppcxx . . $ dpp/::discord_clientcxx . . $ dpp/discord_client#* s = event.fromcxx . . $ dpp/event_dispatch_t#from(5792d35fcd4936ef).(); |
| 83 | bool muted = false, deaf = false; |
| 84 | s->connect_voicecxx . . $ dpp/discord_client#connect_voice(53a6ed65108e7a27).(TEST_GUILD_IDcxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a)., TEST_VC_IDcxx . . $ dpp/snowflake#snowflake(14a7ecd272f4e02a)., muted, deaf); |
| 85 | } |
| 86 | }); |
| 87 | dave_test.startcxx . . $ dpp/cluster#start(fa7c3f1aeb8ff3e5).(dppcxx . . $ dpp/::st_waitcxx . . $ dpp/st_wait.); |
| 88 | } |