DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
InputEvents.cpp
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/// InputEvents.cpp - Source file for the input-event handler class.
27/// Aug 18, 2021
28/// https://discordcoreapi.com
29/// \file InputEvents.cpp
30
35
36namespace discord_core_api {
37
40 if (dataPackage.eventType == interaction_type::Message_Component) {
41 create_interaction_response_data dataPackage02{ dataPackage };
42 if (dataPackage.type == input_event_response_type::Deferred_Response) {
44 } else {
46 }
47 input_event_data newEvent = respondToInputEvent(dataPackage02);
54 }
55 co_return std::move(newEvent);
56 } else if (dataPackage.eventType == interaction_type::Application_Command_Autocomplete) {
57 create_interaction_response_data dataPackage02{ dataPackage };
59 input_event_data newEvent =respondToInputEvent(dataPackage02);
61 co_return std::move(newEvent);
62 }
63 switch (dataPackage.type) {
65 create_deferred_interaction_response_data dataPackage02{ dataPackage };
66 dataPackage02.data.flags = 64;
67 co_return respondToInputEvent(dataPackage02);
68 }
69 case input_event_response_type::Deferred_Response: {
70 create_deferred_interaction_response_data dataPackage02{ dataPackage };
71 co_return respondToInputEvent(dataPackage02);
72 }
74 create_interaction_response_data dataPackage02{ dataPackage };
75 co_return respondToInputEvent(dataPackage02);
76 }
78 edit_interaction_response_data dataPackage02{ dataPackage };
79 co_return respondToInputEvent(dataPackage02);
80 }
82 create_ephemeral_interaction_response_data dataPackage02{ dataPackage };
83 co_return respondToInputEvent(dataPackage02);
84 }
86 create_follow_up_message_data dataPackage02{ dataPackage };
87 co_return respondToInputEvent(dataPackage02);
88 }
90 edit_follow_up_message_data dataPackage02{ dataPackage };
91 co_return respondToInputEvent(dataPackage02);
92 }
94 create_ephemeral_follow_up_message_data dataPackage02{ dataPackage };
95 co_return respondToInputEvent(dataPackage02);
96 }
98 [[fallthrough]];
99 }
101 [[fallthrough]];
102 }
104 break;
105 }
106 default: {
107 co_return input_event_data();
108 }
109 }
110 co_return input_event_data();
111 }
112
114 input_event_data newPackage = dataPackage;
115 co_await newThreadAwaitable<void>();
118 respond_to_input_event_data dataPackageNew{ newPackage };
119 delete_follow_up_message_data dataPackageNewer{ dataPackageNew };
120 dataPackageNewer.timeDelay = timeDelayNew;
121 interactions::deleteFollowUpMessageAsync(dataPackageNewer).get();
124 newPackage.responseType == input_event_response_type::Ephemeral_Deferred_Response || newPackage.responseType == input_event_response_type::Deferred_Response) {
125 respond_to_input_event_data dataPackageNew{ newPackage };
126 delete_interaction_response_data dataPackageNewer{ dataPackageNew };
127 dataPackageNewer.timeDelay = timeDelayNew;
128 interactions::deleteInteractionResponseAsync(dataPackageNewer).get();
129 }
130 co_return;
131 }
132
133 input_event_data input_events::respondToInputEvent(create_deferred_interaction_response_data dataPackage) {
134 create_interaction_response_data dataPackageNew{ dataPackage };
135 auto result = interactions::createInteractionResponse(dataPackageNew);
136 input_event_data dataPackageNewer{};
137 dataPackageNewer.responseType = input_event_response_type::Deferred_Response;
138 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
139 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
140 dataPackageNewer.interactionData->channelId = result.channelId;
141 dataPackageNewer.interactionData->message.id = result.messageReference.messageId;
142 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
143 dataPackageNewer.interactionData->user = result.author;
144 return dataPackageNewer;
145 }
146
147 input_event_data input_events::respondToInputEvent(create_interaction_response_data dataPackage) {
148 message_data messageData = interactions::createInteractionResponse(dataPackage);
149 input_event_data dataPackageNewer{};
150 dataPackageNewer.responseType = input_event_response_type::Interaction_Response;
151 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
152 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
153 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
154 dataPackageNewer.interactionData->channelId = messageData.channelId;
155 dataPackageNewer.interactionData->user = messageData.author;
156 dataPackageNewer.interactionData->message = messageData;
157 return dataPackageNewer;
158 }
159
160 input_event_data input_events::respondToInputEvent(edit_interaction_response_data dataPackage) {
161 message_data messageData = interactions::editInteractionResponse(dataPackage);
162 input_event_data dataPackageNewer{};
163 dataPackageNewer.responseType = input_event_response_type::Edit_Interaction_Response;
164 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
165 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
166 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
167 dataPackageNewer.interactionData->channelId = messageData.channelId;
168 dataPackageNewer.interactionData->user = messageData.author;
169 dataPackageNewer.interactionData->message = messageData;
170 return dataPackageNewer;
171 }
172
173 input_event_data input_events::respondToInputEvent(create_follow_up_message_data dataPackage) {
174 message_data messageData = interactions::createFollowUpMessage(dataPackage);
175 input_event_data dataPackageNewer{};
176 dataPackageNewer.responseType = input_event_response_type::Follow_Up_Message;
177 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
178 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
179 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
180 dataPackageNewer.interactionData->channelId = messageData.channelId;
181 dataPackageNewer.interactionData->user = messageData.author;
182 dataPackageNewer.interactionData->message = messageData;
183 return dataPackageNewer;
184 }
185
186 input_event_data input_events::respondToInputEvent(edit_follow_up_message_data dataPackage) {
187 message_data messageData = interactions::editFollowUpMessage(dataPackage);
188 input_event_data dataPackageNewer{};
189 dataPackageNewer.responseType = input_event_response_type::Edit_Follow_Up_Message;
190 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
191 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
192 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
193 dataPackageNewer.interactionData->channelId = messageData.channelId;
194 dataPackageNewer.interactionData->user = messageData.author;
195 dataPackageNewer.interactionData->message = messageData;
196 return dataPackageNewer;
197 }
198
199 input_event_data input_events::respondToInputEvent(create_ephemeral_interaction_response_data dataPackage) {
200 create_interaction_response_data dataPackageNew{ dataPackage };
201 message_data messageData = interactions::createInteractionResponse(dataPackageNew);
202 input_event_data dataPackageNewer{};
203 dataPackageNewer.responseType = input_event_response_type::Ephemeral_Interaction_Response;
204 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
205 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
206 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
207 dataPackageNewer.interactionData->channelId = messageData.channelId;
208 dataPackageNewer.interactionData->user = messageData.author;
209 dataPackageNewer.interactionData->message = messageData;
210 return dataPackageNewer;
211 }
212
213 input_event_data input_events::respondToInputEvent(create_ephemeral_follow_up_message_data dataPackage) {
214 create_follow_up_message_data dataPackageNew{ dataPackage };
215 message_data messageData = interactions::createFollowUpMessage(dataPackageNew);
216 input_event_data dataPackageNewer{};
217 dataPackageNewer.responseType = input_event_response_type::Ephemeral_Follow_Up_Message;
218 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
219 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
220 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
221 dataPackageNewer.interactionData->channelId = messageData.channelId;
222 dataPackageNewer.interactionData->user = messageData.author;
223 dataPackageNewer.interactionData->message = messageData;
224 return dataPackageNewer;
225 }
226
227}
A co_routine - representing a potentially asynchronous operation/function.
For creating an ephemeral follow up message_data.
For creating an ephemeral interaction response.
For editing a follow up message_data.
Data representing an input-event, which is any message or interaction that is coming into the bot as ...
input_event_response_type responseType
The type of response that this input value represents.
static co_routine< input_event_data > respondToInputEventAsync(respond_to_input_event_data dataPackage)
Responds to one of a number of types of "input_events".
static co_routine< void > deleteInputEventResponseAsync(input_event_data dataPackage, uint32_t timeDelayNew=0)
Deletes a previously sent "input-event-response".
static co_routine< void > deleteFollowUpMessageAsync(delete_follow_up_message_data dataPackage)
Deletes a follow up message_data.
static co_routine< void > deleteInteractionResponseAsync(delete_interaction_response_data dataPackage)
Deletes an interaction respnose.
Data for responding to an input-event.
input_event_response_type type
The type of response to make.
@ Ephemeral_Interaction_Response
Ephemeral interaction response.
@ Ephemeral_Deferred_Response
Deferred ephemeral response.
@ Modal_Interaction_Response
Respond to an interaction with a popup modal.
@ Edit_Interaction_Response
Interaction response edit.
@ Application_Command_AutoComplete_Result
Respond to an autocomplete interaction with suggested choices.
@ Edit_Follow_Up_Message
Follow-up message edit.
@ Ephemeral_Follow_Up_Message
Ephemeral follow-up message_data.
@ Follow_Up_Message
Follow-up message_data.
@ Deferred_Update_Message
For components, ack an interaction and edit the original message later; the user does not see a loadi...
@ Application_Command_Autocomplete_Result
Respond to an autocomplete interaction with suggested choices.
@ Update_Message
For components, edit the message the component was attached to.
@ Application_Command_Autocomplete
Application command autocomplete.
DCA_INLINE auto newThreadAwaitable()
An awaitable that can be used to launch the co_routine onto a new thread - as well as return the hand...
The main namespace for the forward-facing interfaces.