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 dataPackageNewer.interactionData->user = result.author;
140 return dataPackageNewer;
141 }
142
143 InputEventData InputEvents::respondToInputEvent(CreateInteractionResponseData& dataPackage) {
144 Message messageData = Interactions::createInteractionResponseAsync(dataPackage).get();
145 InputEventData dataPackageNewer{};
146 dataPackageNewer.responseType = InputEventResponseType::Interaction_Response;
147 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
148 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
149 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
150 dataPackageNewer.interactionData->channelId = messageData.channelId;
151 dataPackageNewer.interactionData->user = messageData.author;
152 dataPackageNewer.interactionData->message = messageData;
153 return dataPackageNewer;
154 }
155
156 InputEventData InputEvents::respondToInputEvent(EditInteractionResponseData& dataPackage) {
157 Message messageData = Interactions::editInteractionResponseAsync(dataPackage).get();
158 InputEventData dataPackageNewer{};
159 dataPackageNewer.responseType = InputEventResponseType::Edit_Interaction_Response;
160 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
161 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
162 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
163 dataPackageNewer.interactionData->channelId = messageData.channelId;
164 dataPackageNewer.interactionData->user = messageData.author;
165 dataPackageNewer.interactionData->message = messageData;
166 return dataPackageNewer;
167 }
168
169 InputEventData InputEvents::respondToInputEvent(CreateFollowUpMessageData& dataPackage) {
170 Message messageData = Interactions::createFollowUpMessageAsync(dataPackage).get();
171 InputEventData dataPackageNewer{};
172 dataPackageNewer.responseType = InputEventResponseType::Follow_Up_Message;
173 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
174 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
175 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
176 dataPackageNewer.interactionData->channelId = messageData.channelId;
177 dataPackageNewer.interactionData->user = messageData.author;
178 dataPackageNewer.interactionData->message = messageData;
179 return dataPackageNewer;
180 }
181
182 InputEventData InputEvents::respondToInputEvent(EditFollowUpMessageData& dataPackage) {
183 Message messageData = Interactions::editFollowUpMessageAsync(dataPackage).get();
184 InputEventData dataPackageNewer{};
185 dataPackageNewer.responseType = InputEventResponseType::Edit_Follow_Up_Message;
186 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
187 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
188 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
189 dataPackageNewer.interactionData->channelId = messageData.channelId;
190 dataPackageNewer.interactionData->user = messageData.author;
191 dataPackageNewer.interactionData->message = messageData;
192 return dataPackageNewer;
193 }
194
195 InputEventData InputEvents::respondToInputEvent(CreateEphemeralInteractionResponseData& dataPackage) {
196 CreateInteractionResponseData dataPackageNew{ dataPackage };
197 Message messageData = Interactions::createInteractionResponseAsync(dataPackageNew).get();
198 InputEventData dataPackageNewer{};
199 dataPackageNewer.responseType = InputEventResponseType::Ephemeral_Interaction_Response;
200 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
201 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
202 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
203 dataPackageNewer.interactionData->channelId = messageData.channelId;
204 dataPackageNewer.interactionData->user = messageData.author;
205 dataPackageNewer.interactionData->message = messageData;
206 return dataPackageNewer;
207 }
208
209 InputEventData InputEvents::respondToInputEvent(CreateEphemeralFollowUpMessageData& dataPackage) {
210 CreateFollowUpMessageData dataPackageNew{ dataPackage };
211 Message messageData = Interactions::createFollowUpMessageAsync(dataPackageNew).get();
212 InputEventData dataPackageNewer{};
213 dataPackageNewer.responseType = InputEventResponseType::Ephemeral_Follow_Up_Message;
214 dataPackageNewer.interactionData->applicationId = dataPackage.interactionPackage.applicationId;
215 dataPackageNewer.interactionData->token = dataPackage.interactionPackage.interactionToken;
216 dataPackageNewer.interactionData->id = dataPackage.interactionPackage.interactionId;
217 dataPackageNewer.interactionData->channelId = messageData.channelId;
218 dataPackageNewer.interactionData->user = messageData.author;
219 dataPackageNewer.interactionData->message = messageData;
220 return dataPackageNewer;
221 }
222}
@ 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.