DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
SongAPI.hpp
Go to the documentation of this file.
1/*
2 MIT License
3
4 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
5
6 Copyright 2022, 2023 Chris M. (RealTimeChris)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26/// SongAPI.hpp - Header for the song api related stuff.
27/// Sep 17, 2021
28/// https://discordcoreapi.com
29/// \file SongAPI.hpp
30#pragma once
31
36
37namespace discord_core_api {
38
39 /**
40 * \addtogroup voice_connection
41 * @{
42 */
43
44 /// @brief A class representing the song apis.
45 class DiscordCoreAPI_Dll song_api {
46 public:
47 friend class discord_core_internal::sound_cloud_api;
48 friend class discord_core_internal::you_tube_api;
49 friend class voice_connection;
50 friend class guild_cache_data;
51 friend class guild_data;
52
53 discord_core_internal::event<co_routine<void, false>, song_completion_event_data> onSongCompletionEvent{};
54 unbounded_message_block<audio_frame_data> audioDataBuffer{};
55 discord_core_internal::event_delegate_token eventToken{};
56
57 song_api(snowflake guildId);
58
59 /// @brief For setting up behavior in response to a completed song
60 /// @param handler a delegate taking a song_completion_event_data structure as an argument.
61 void onSongCompletion(std::function<co_routine<void, false>(song_completion_event_data)> handler);
62
63 /// @brief Skips to the next song in the queue, if applicable.
64 /// @param wasItAfail a bool representing whether or not this skip is due to a playing failure.
65 /// @return a bool suggesting the success or failure of the skip command.
66 bool skip(bool wasItAfail = false);
67
68 /// @brief Search for a song to play.
69 /// @param searchQuery the song to search for.
70 /// @param limit The maximum number of search results to return.
71 /// @return a vector of song objects representing the search results.
72 jsonifier::vector<song> searchForSong(jsonifier::string_view searchQuery, uint64_t limit = 20);
73
74 /// @brief Plays the current song. (assuming that you are currently connected to a voice_connection).
75 /// @param songNew the song to play.
76 /// @return a bool suggesting the success or failure of the play command.
77 bool play(song songNew);
78
79 /// @brief Checks if there is currently playing music for the current guild.
80 /// @return a bool representing the currently playing status.
81 bool areWeCurrentlyPlaying() const;
82
83 /// @brief Toggles pausing on and off.
84 /// @return a bool suggesting the success or failure of the pauseToggle command.
85 bool pauseToggle();
86
87 /// @brief Plays the current song. (assuming that you are currently connected to a voice_connection).
88 /// @return a bool suggesting the success or failure of the play command.
89 bool play();
90
91 /// @brief Stops the currently playing song.
92 /// @return a bool suggesting the success or failure of the stop command.
93 bool stop();
94
95 protected:
96 co_routine<void, false> taskThread{};
97 std::recursive_mutex accessMutex{};
98 snowflake guildId{};
99
100 void disconnect();
101 };
102 /**@}*/
103};
A class representing the song apis.
Definition SongAPI.hpp:45
The main namespace for the forward-facing interfaces.