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 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
3
4 Copyright 2021, 2022 Chris M. (RealTimeChris)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
20*/
21/// InputEvents.cpp - Source file for the input-event handler class.
22/// Aug 18, 2021
23/// https://discordcoreapi.com
24/// \file InputEvents.cpp
25
29
30namespace DiscordCoreAPI {
31
33 co_await NewThreadAwaitable<InputEventData>();
34 if (dataPackage.type == InputEventResponseType::Unset) {
35 throw DCAException("InputEvents::respondToInputEventAsync() Error: Please set an "
36 "input-event-response-type!\n\n");
37 }
38 if (dataPackage.eventType == InteractionType::Message_Component) {
39 CreateInteractionResponseData dataPackage02{ dataPackage };
40 if (dataPackage.type == InputEventResponseType::Deferred_Response) {
42 } else {
43 dataPackage02.data.type = InteractionCallbackType::Update_Message;
44 }
45 InputEventData newEvent = InputEvents::respondToInputEvent(dataPackage02);
50 } else if (dataPackage.type == InputEventResponseType::Follow_Up_Message ||
54 }
55 co_return std::move(newEvent);
56 } else if (dataPackage.eventType == InteractionType::Application_Command_Autocomplete) {
57 CreateInteractionResponseData dataPackage02{ dataPackage };
59 InputEventData newEvent = InputEvents::respondToInputEvent(dataPackage02);
61 co_return std::move(newEvent);
62 }
63 switch (dataPackage.type) {
65 CreateDeferredInteractionResponseData dataPackage02{ dataPackage };
66 dataPackage02.data.data.flags = 64;
67 co_return InputEvents::respondToInputEvent(dataPackage02);
68 }
69 case InputEventResponseType::Deferred_Response: {
70 CreateDeferredInteractionResponseData dataPackage02{ dataPackage };
71 co_return InputEvents::respondToInputEvent(dataPackage02);
72 }
74 CreateInteractionResponseData dataPackage02{ dataPackage };
75 co_return InputEvents::respondToInputEvent(dataPackage02);
76 }
78 EditInteractionResponseData dataPackage02{ dataPackage };
79 co_return InputEvents::respondToInputEvent(dataPackage02);
80 }
82 CreateEphemeralInteractionResponseData dataPackage02{ dataPackage };
83 co_return InputEvents::respondToInputEvent(dataPackage02);
84 }
86 CreateFollowUpMessageData dataPackage02{ dataPackage };
87 co_return InputEvents::respondToInputEvent(dataPackage02);
88 }
90 EditFollowUpMessageData dataPackage02{ dataPackage };
91 co_return InputEvents::respondToInputEvent(dataPackage02);
92 }
94 CreateEphemeralFollowUpMessageData dataPackage02{ dataPackage };
95 co_return InputEvents::respondToInputEvent(dataPackage02);
96 }
98 break;
99 }
100 default: {
101 co_return InputEventData();
102 }
103 }
104 }
105
107 InputEventData newPackage = dataPackage;
108 co_await NewThreadAwaitable<void>();
112 RespondToInputEventData dataPackageNew{ newPackage };
113 DeleteFollowUpMessageData dataPackageNewer{ dataPackageNew };
114 dataPackageNewer.timeDelay = timeDelayNew;
120 newPackage.responseType == InputEventResponseType::Deferred_Response) {
121 RespondToInputEventData dataPackageNew{ newPackage };
122 DeleteInteractionResponseData dataPackageNewer{ dataPackageNew };
123 dataPackageNewer.timeDelay = timeDelayNew;
125 }
126 co_return;
127 }
128
129 InputEventData InputEvents::respondToInputEvent(CreateDeferredInteractionResponseData& dataPackage) {
130 CreateInteractionResponseData dataPackageNew{ dataPackage };
131 auto result = Interactions::createInteractionResponseAsync(dataPackageNew).get();
132 InputEventData dataPackageNewer{};
133 dataPackageNewer.responseType = InputEventResponseType::Deferred_Response;
134 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
135 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
136 dataPackageNewer.interactionData->channelId = result.channelId;
137 dataPackageNewer.interactionData->message.id = result.referencedMessage->id;
138 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
139 return dataPackageNewer;
140 }
141
142 InputEventData InputEvents::respondToInputEvent(CreateInteractionResponseData& dataPackage) {
143 Message messageData = Interactions::createInteractionResponseAsync(dataPackage).get();
144 InputEventData dataPackageNewer{};
145 dataPackageNewer.responseType = InputEventResponseType::Interaction_Response;
146 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
147 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
148 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
149 dataPackageNewer.interactionData->channelId = messageData.channelId;
150 dataPackageNewer.interactionData->user = messageData.author;
151 dataPackageNewer.interactionData->message = messageData;
152 return dataPackageNewer;
153 }
154
155 InputEventData InputEvents::respondToInputEvent(EditInteractionResponseData& dataPackage) {
156 Message messageData = Interactions::editInteractionResponseAsync(dataPackage).get();
157 InputEventData dataPackageNewer{};
158 dataPackageNewer.responseType = InputEventResponseType::Edit_Interaction_Response;
159 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
160 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
161 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
162 dataPackageNewer.interactionData->channelId = messageData.channelId;
163 dataPackageNewer.interactionData->user = messageData.author;
164 dataPackageNewer.interactionData->message = messageData;
165 return dataPackageNewer;
166 }
167
168 InputEventData InputEvents::respondToInputEvent(CreateFollowUpMessageData& dataPackage) {
169 Message messageData = Interactions::createFollowUpMessageAsync(dataPackage).get();
170 InputEventData dataPackageNewer{};
171 dataPackageNewer.responseType = InputEventResponseType::Follow_Up_Message;
172 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
173 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
174 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
175 dataPackageNewer.interactionData->channelId = messageData.channelId;
176 dataPackageNewer.interactionData->user = messageData.author;
177 dataPackageNewer.interactionData->message = messageData;
178 return dataPackageNewer;
179 }
180
181 InputEventData InputEvents::respondToInputEvent(EditFollowUpMessageData& dataPackage) {
182 Message messageData = Interactions::editFollowUpMessageAsync(dataPackage).get();
183 InputEventData dataPackageNewer{};
184 dataPackageNewer.responseType = InputEventResponseType::Edit_Follow_Up_Message;
185 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
186 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
187 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
188 dataPackageNewer.interactionData->channelId = messageData.channelId;
189 dataPackageNewer.interactionData->user = messageData.author;
190 dataPackageNewer.interactionData->message = messageData;
191 return dataPackageNewer;
192 }
193
194 InputEventData InputEvents::respondToInputEvent(CreateEphemeralInteractionResponseData& dataPackage) {
195 CreateInteractionResponseData dataPackageNew{ dataPackage };
196 Message messageData = Interactions::createInteractionResponseAsync(dataPackageNew).get();
197 InputEventData dataPackageNewer{};
198 dataPackageNewer.responseType = InputEventResponseType::Ephemeral_Interaction_Response;
199 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
200 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
201 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
202 dataPackageNewer.interactionData->channelId = messageData.channelId;
203 dataPackageNewer.interactionData->user = messageData.author;
204 dataPackageNewer.interactionData->message = messageData;
205 return dataPackageNewer;
206 }
207
208 InputEventData InputEvents::respondToInputEvent(CreateEphemeralFollowUpMessageData& dataPackage) {
209 CreateFollowUpMessageData dataPackageNew{ dataPackage };
210 Message messageData = Interactions::createFollowUpMessageAsync(dataPackageNew).get();
211 InputEventData dataPackageNewer{};
212 dataPackageNewer.responseType = InputEventResponseType::Ephemeral_Follow_Up_Message;
213 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
214 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
215 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
216 dataPackageNewer.interactionData->channelId = messageData.channelId;
217 dataPackageNewer.interactionData->user = messageData.author;
218 dataPackageNewer.interactionData->message = messageData;
219 return dataPackageNewer;
220 }
221}
@ 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.
@ Message_Component
Message component.
@ Application_Command_Autocomplete
Application command autocomplete.
@ Ephemeral_Interaction_Response
Ephemeral Interaction response.
@ Ephemeral_Deferred_Response
Deferred ephemeral response.
@ Interaction_Response
Interaction response.
@ 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.
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:59
void get()
Gets the resulting value of the CoRoutine.
Definition: CoRoutine.hpp:312
Data representing an input-event, which is any Message or Interaction that is coming into the bot as ...
InputEventResponseType responseType
The type of response that this input value represents.
Data for responding to an input-event.
InputEventResponseType type
The type of response to make.
static CoRoutine< void > deleteInputEventResponseAsync(InputEventData &dataPackage, int32_t timeDelayNew=0)
Deletes a previously sent "input-event-response".
static CoRoutine< InputEventData > respondToInputEventAsync(RespondToInputEventData dataPackage)
Responds to one of a number of types of "InputEvents".
Definition: InputEvents.cpp:32
For creating an ephemeral Interaction response.
For creating a deferred Interaction response.
For creating an Interaction response.
For editing an Interaction response.
For deleting an Interaction response.
For creating an ephemeral follow up Message.
For editing a follow up Message.
static CoRoutine< Message > createFollowUpMessageAsync(CreateFollowUpMessageData dataPackage)
Creates a follow up Message to an input Interaction.
static CoRoutine< Message > editInteractionResponseAsync(EditInteractionResponseData dataPackage)
Edits an Interaction response.
static CoRoutine< void > deleteFollowUpMessageAsync(DeleteFollowUpMessageData dataPackage)
Deletes a follow up Message.
static CoRoutine< Message > createInteractionResponseAsync(CreateInteractionResponseData dataPackage)
Creates a response to an input Interaction.
static CoRoutine< Message > editFollowUpMessageAsync(EditFollowUpMessageData dataPackage)
Edits a follow up Message.
static CoRoutine< void > deleteInteractionResponseAsync(DeleteInteractionResponseData dataPackage)
Deletes an Interaction respnose.