33 Reaction::Reaction(simdjson::ondemand::value jsonObjectData) {
34 this->
count = getUint32(jsonObjectData,
"count");
36 this->
me = getBool(jsonObjectData,
"me");
38 simdjson::ondemand::value
object{};
39 if (getObject(
object,
"emoji", jsonObjectData)) {
40 this->
emoji = EmojiData{
object };
43 this->
guildId = getId(jsonObjectData,
"guild_id");
45 this->
channelId = getId(jsonObjectData,
"channel_id");
47 this->
userId = getId(jsonObjectData,
"user_id");
49 this->
messageId = getId(jsonObjectData,
"message_id");
51 if (jsonObjectData[
"member"].get(
object) == simdjson::error_code::SUCCESS) {
52 this->
member = GuildMemberData{
object };
56 ReactionVector::ReactionVector(simdjson::ondemand::value jsonObjectData) {
57 if (jsonObjectData.type() != simdjson::ondemand::json_type::null) {
58 simdjson::ondemand::array arrayValue{};
59 if (getArray(arrayValue, jsonObjectData)) {
60 for (simdjson::simdjson_result<simdjson::ondemand::value> value: arrayValue) {
61 Reaction newData{ value.value() };
62 this->reactions.emplace_back(std::move(newData));
68 CreateGuildEmojiData::operator Jsonifier() {
70 for (
auto& value: this->roles) {
71 data[
"roles"].emplaceBack(value.operator std::string());
73 data[
"images"] = this->imageDataFinal;
74 data[
"name"] = this->name;
78 ModifyGuildEmojiData::operator Jsonifier() {
80 for (
auto& value: this->roles) {
81 data[
"roles"].emplaceBack(value.operator std::string());
83 data[
"name"] = this->name;
87 ReactionVector::operator std::vector<Reaction>() {
88 return this->reactions;
91 void Reactions::initialize(DiscordCoreInternal::HttpsClient* client) {
92 Reactions::httpsClient = client;
96 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Put_Reaction };
97 co_await NewThreadAwaitable<Reaction>();
104 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Put;
105 workload.relativePath =
106 "/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions/" + urlEncode(emoji) +
"/@me";
107 workload.callStack =
"Reactions::createReactionAsync()";
109 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
Reaction>(workload, &returnValue);
113 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Own_Reaction };
114 co_await NewThreadAwaitable<void>();
116 if (dataPackage.
emojiId != 0) {
121 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
122 workload.relativePath =
123 "/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions/" + urlEncode(emoji) +
"/@me";
124 workload.callStack =
"Reactions::deleteOwnReactionAsync()";
125 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
void>(workload);
129 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_User_Reaction };
130 co_await NewThreadAwaitable<void>();
132 if (dataPackage.
emojiId != 0) {
138 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
139 workload.relativePath =
140 "/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions/" + urlEncode(emoji) +
"/" + dataPackage.
userId;
141 workload.callStack =
"Reactions::deleteUserReactionAsync()";
142 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
void>(workload);
146 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Reactions };
147 co_await NewThreadAwaitable<UserVector>();
148 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
149 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions/" + dataPackage.
emoji;
150 if (dataPackage.
afterId != 0) {
151 workload.relativePath +=
"?after=" + dataPackage.
afterId;
152 if (dataPackage.
limit != 0) {
153 workload.relativePath +=
"&limit=" + std::to_string(dataPackage.
limit);
155 }
else if (dataPackage.
limit != 0) {
156 workload.relativePath +=
"?limit=" + std::to_string(dataPackage.
limit);
158 workload.callStack =
"Reactions::getReactionsAsync()";
159 UserVector returnValue{};
160 co_return Reactions::httpsClient->submitWorkloadAndGetResult<UserVector>(workload, &returnValue);
165 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_All_Reactions };
166 co_await NewThreadAwaitable<void>();
167 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
168 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions";
169 workload.callStack =
"Reactions::deleteAllReactionsAsync()";
170 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
void>(workload);
174 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Reactions_By_Emoji };
175 co_await NewThreadAwaitable<void>();
177 if (dataPackage.
emojiId != 0) {
182 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
183 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/reactions/" + urlEncode(emoji);
184 workload.callStack =
"Reactions::deleteReactionsByEmojiAsync()";
185 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
void>(workload);
189 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Emoji_List };
190 co_await NewThreadAwaitable<EmojiDataVector>();
191 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
192 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/emojis";
193 workload.callStack =
"Reactions::getEmojiListAsync()";
194 EmojiDataVector returnValue{};
195 co_return Reactions::httpsClient->submitWorkloadAndGetResult<EmojiDataVector>(workload, &returnValue);
199 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Guild_Emoji };
200 co_await NewThreadAwaitable<EmojiData>();
201 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
202 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/emojis/" + dataPackage.
emojiId;
203 workload.callStack =
"Reactions::getGuildEmojiAsync()";
205 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
EmojiData>(workload, &returnValue);
209 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Guild_Emoji };
210 co_await NewThreadAwaitable<EmojiData>();
211 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
212 std::ifstream fin(dataPackage.
imageFilePath, std::ios::binary);
213 fin.seekg(0, std::ios::end);
215 data.resize(fin.tellg());
216 fin.seekg(0, std::ios::beg);
217 fin.read(data.data(), data.size());
218 std::string newerFile = base64Encode(data);
219 switch (dataPackage.
type) {
220 case ImageType::Jpg: {
221 dataPackage.imageDataFinal =
"data:image/jpeg;base64,";
222 dataPackage.imageDataFinal.insert(dataPackage.imageDataFinal.end(), newerFile.begin(), newerFile.end());
225 case ImageType::Png: {
226 dataPackage.imageDataFinal =
"data:image/png;base64,";
227 dataPackage.imageDataFinal.insert(dataPackage.imageDataFinal.end(), newerFile.begin(), newerFile.end());
230 case ImageType::Gif: {
231 dataPackage.imageDataFinal =
"data:image/gif;base64,";
232 dataPackage.imageDataFinal.insert(dataPackage.imageDataFinal.end(), newerFile.begin(), newerFile.end());
236 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/emojis";
237 auto serializer = dataPackage.operator Jsonifier();
238 serializer.refreshString(JsonifierSerializeType::Json);
239 workload.content = serializer.operator std::string();
240 workload.callStack =
"Reactions::createGuildEmojiAsync()";
241 if (dataPackage.
reason !=
"") {
242 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
245 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
EmojiData>(workload, &returnValue);
249 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Patch_Guild_Emoji };
250 co_await NewThreadAwaitable<EmojiData>();
251 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Patch;
252 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/emojis/" + dataPackage.
emojiId;
253 auto serializer = dataPackage.operator Jsonifier();
254 serializer.refreshString(JsonifierSerializeType::Json);
255 workload.content = serializer.operator std::string();
256 workload.callStack =
"Reactions::modifyGuildEmojiAsync()";
257 if (dataPackage.
reason !=
"") {
258 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
261 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
EmojiData>(workload, &returnValue);
265 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Guild_Emoji };
266 co_await NewThreadAwaitable<void>();
267 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
268 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/emojis/" + dataPackage.
emojiId;
269 workload.callStack =
"Reactions::deleteGuildEmojiAsync()";
270 if (dataPackage.
reason !=
"") {
271 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
273 co_return Reactions::httpsClient->submitWorkloadAndGetResult<
void>(workload);
275 DiscordCoreInternal::HttpsClient* Reactions::httpsClient{
nullptr };
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Data structure representing a single emoji.
bool me
Whether or not I (The bot) placed it.
Snowflake messageId
The id of the Message upon which it was placed.
Snowflake guildId
The id of the Guild where it was placed.
EmojiData emoji
The emoji that was placed as a reaction.
Snowflake channelId
The id of the Channel where it was placed.
GuildMemberData member
The GuildMember who placed the reaction.
Snowflake userId
The id of the User who placed the reaction.
int32_t count
The number of times this particular emoji was placed as a reaction to the given Message.
For creating a single Reaction.
std::string emojiName
The emoji name of the Reaction to add.
Snowflake messageId
The Message on which to add the Reaction.
Snowflake emojiId
The emoji id of the Reaction to add.
Snowflake channelId
The Channel for which to add the Reaction.
For deleting one's own Reaction.
Snowflake channelId
The Channel from which to remove the Reaction.
Snowflake messageId
The Message from which to remove the Reaction.
std::string emojiName
The emoji name for which to remove the emoji.
Snowflake emojiId
The emoji id for which to remove the emoji.
For deleting a reaction, by User.
std::string emojiName
The name of which emoji to remove.
Snowflake channelId
The Channel from which to remove the Reaction.
Snowflake emojiId
The id of which emoji to remove.
Snowflake userId
The User id for whom to remove their emoji.
Snowflake messageId
The Message from which to remove the Reaction.
For getting all of the Reactions.
int32_t limit
The maximum number of reactors to collect.
Snowflake channelId
The Channel from which to acquire the reactors.
Snowflake afterId
Get users after this user ID.
std::string emoji
The emoji name for which to acquire the reactors.
Snowflake messageId
The Message from which to acquire the reactors.
For deleting all of the Reactions on a particular Message.
Snowflake messageId
The Message from which you would like to remove the emoji.
Snowflake channelId
The Channel from which you would like to remove the emoji.
For deleting all of the Reactions of a particular Emoji.
Snowflake messageId
The Message from which you would like to remove the emoji.
Snowflake channelId
The Channel from which you would like to remove the emoji.
Snowflake emojiId
The id of which emoji to remove.
std::string emojiName
The name of which emoji to remove.
For collecting a list of Emoji from a Guild.
Snowflake guildId
The id of the chosen Guild.
For collecting a single Guild Emoji.
Snowflake emojiId
The id of the chosen Emoji.
Snowflake guildId
The id of the chosen Guild.
For creating a new Guild Emoji.
std::string reason
Reason for creating the new Emoji.
Snowflake guildId
The Guild within which to create the Emoji.
ImageType type
The type of image being uploaded.
std::string imageFilePath
The image responseData.
For modifying a Guild Emoji.
Snowflake emojiId
The id of the Emoji to modify.
Snowflake guildId
The Guild within which to modify the Emoji.
std::string reason
Reason for modifying the Emoji.
For deleting a Guild Emoji.
std::string reason
Reason for deleting the Emoji.
Snowflake guildId
The Guild within which to delete the Emoji.
Snowflake emojiId
The id of the Emoji to delete.
static CoRoutine< UserVector > getReactionsAsync(GetReactionsData dataPackage)
Get a list of users that reacted with this emoji. Returns an array of user objects on success.
static CoRoutine< void > deleteOwnReactionAsync(DeleteOwnReactionData dataPackage)
Deletes your own Reactions from a given Message.
static CoRoutine< void > deleteGuildEmojiAsync(DeleteGuildEmojiData dataPackage)
Deletes a single Guild Emoji within a chosen Guild.
static CoRoutine< EmojiDataVector > getEmojiListAsync(GetEmojiListData dataPackage)
Collects a list of Guild Emoji from a chosen Guild.
static CoRoutine< Reaction > createReactionAsync(CreateReactionData dataPackage)
Creates a Reaction on a Message.
static CoRoutine< EmojiData > getGuildEmojiAsync(GetGuildEmojiData dataPackage)
Collects a single Guild Emoji from a chosen Guild.
static CoRoutine< void > deleteReactionsByEmojiAsync(DeleteReactionsByEmojiData dataPackage)
Deletes all of the Reactions by a specific emoji from a given Message.
static CoRoutine< void > deleteAllReactionsAsync(DeleteAllReactionsData dataPackage)
Deletes all of the Reactions from a given Message.
static CoRoutine< EmojiData > createGuildEmojiAsync(CreateGuildEmojiData dataPackage)
Creates a single Guild Emoji within a chosen Guild.
static CoRoutine< void > deleteUserReactionAsync(DeleteUserReactionData dataPackage)
Deletes all of the Reactions by a specific User from a given Message.
static CoRoutine< EmojiData > modifyGuildEmojiAsync(ModifyGuildEmojiData dataPackage)
Modifies a single Guild Emoji within a chosen Guild.