DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
GuildScheduledEventEntities.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/// GuildScheduledEventEntities.cpp - Source file for the guild scheduled events stuff.
27/// Nov 27, 2021
28/// https://discordcoreapi.com
29/// \file GuildScheduledEventEntities.cpp
30
34
35namespace jsonifier {
36
37 template<> struct core<discord_core_api::modify_guild_scheduled_event_data> {
39 static constexpr auto parseValue = createObject("privacy_level", &value_type::privacyLevel, "status", &value_type::status, "entity_metadata", &value_type::entityMetadata,
40 "entity_type", &value_type::entityType, "guild_scheduled_event_id", &value_type::guildScheduledEventId, "scheduled_start_time", &value_type::scheduledStartTime,
41 "scheduled_end_time", &value_type::scheduledEndTime, "description", &value_type::description, "channel_id", &value_type::channelId, "guild_id", &value_type::guildId,
42 "name", &value_type::name);
43 };
44
45 template<> struct core<discord_core_api::create_guild_scheduled_event_data> {
47 static constexpr auto parseValue = createObject("privacy_level", &value_type::privacyLevel, "entity_metadata", &value_type::entityMetadata, "entity_type",
48 &value_type::entityType, "scheduled_start_time", &value_type::scheduledStartTime, "scheduled_end_time", &value_type::scheduledEndTime, "description",
49 &value_type::description, "channel_id", &value_type::channelId, "guild_id", &value_type::guildId, "name", &value_type::name);
50 };
51
52}
53
54namespace discord_core_api {
55
56 void guild_scheduled_events::initialize(discord_core_internal::https_client* client) {
57 guild_scheduled_events::httpsClient = client;
58 }
59
61 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Scheduled_Events };
62 co_await newThreadAwaitable<jsonifier::vector<guild_scheduled_event_data>>();
63 workload.workloadClass = discord_core_internal::https_workload_class::Get;
64 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events";
65 workload.callStack = "guild_scheduled_events::getGuildScheduledEventAsync()";
66 jsonifier::vector<guild_scheduled_event_data> returnData{};
67 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
68 co_return returnData;
69 }
70
72 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Post_Guild_Scheduled_Event };
73 co_await newThreadAwaitable<guild_scheduled_event_data>();
74 workload.workloadClass = discord_core_internal::https_workload_class::Post;
75 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events";
76 parser.serializeJson<true>(dataPackage, workload.content);
77 workload.callStack = "guild_scheduled_events::createGuildScheduledEventAsync()";
78 guild_scheduled_event_data returnData{};
79 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
80 co_return returnData;
81 }
82
84 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Scheduled_Event };
85 co_await newThreadAwaitable<guild_scheduled_event_data>();
86 workload.workloadClass = discord_core_internal::https_workload_class::Get;
87 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events/" + dataPackage.guildScheduledEventId;
88 workload.relativePath += "?with_user_count=";
89 std::stringstream stream{};
90 stream << std::boolalpha << dataPackage.withUserCount;
91 workload.relativePath += stream.str();
92 workload.callStack = "guild_scheduled_events::getGuildScheduledEventAsync()";
93 guild_scheduled_event_data returnData{};
94 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
95 co_return returnData;
96 }
97
99 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Patch_Guild_Scheduled_Event };
100 co_await newThreadAwaitable<guild_scheduled_event_data>();
101 workload.workloadClass = discord_core_internal::https_workload_class::Patch;
102 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events/" + dataPackage.guildScheduledEventId;
103 parser.serializeJson<true>(dataPackage, workload.content);
104 workload.callStack = "guild_scheduled_events::modifyGuildScheduledEventAsync()";
105 guild_scheduled_event_data returnData{};
106 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
107 co_return returnData;
108 }
109
111 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Delete_Guild_Scheduled_Event };
112 co_await newThreadAwaitable<void>();
113 workload.workloadClass = discord_core_internal::https_workload_class::Delete;
114 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events/" + dataPackage.guildScheduledEventId;
115 workload.callStack = "guild_scheduled_events::deleteGuildScheduledEventAsync()";
116 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload));
117 co_return;
118 }
119
121 discord_core_internal::https_workload_data workload{ discord_core_internal::https_workload_type::Get_Guild_Scheduled_Event_Users };
122 co_await newThreadAwaitable<jsonifier::vector<guild_scheduled_event_user_data>>();
123 workload.workloadClass = discord_core_internal::https_workload_class::Get;
124 workload.relativePath = "/guilds/" + dataPackage.guildId + "/scheduled-events/" + dataPackage.guildScheduledEventId + "/users";
125 if (dataPackage.limit != 0) {
126 workload.relativePath += "?limit=" + jsonifier::toString(dataPackage.limit);
127 if (dataPackage.after != 0) {
128 workload.relativePath += "&after=" + dataPackage.after;
129 }
130 if (dataPackage.before != 0) {
131 workload.relativePath += "&before=" + dataPackage.before;
132 }
133 if (dataPackage.withMember) {
134 workload.relativePath += "&with_member=true";
135 }
136 }
137 if (dataPackage.after != 0) {
138 workload.relativePath += "?after=" + dataPackage.after;
139 if (dataPackage.before != 0) {
140 workload.relativePath += "&before=" + dataPackage.before;
141 }
142 if (dataPackage.withMember) {
143 workload.relativePath += "&with_member=true";
144 }
145 }
146 if (dataPackage.before != 0) {
147 workload.relativePath += "?before=" + dataPackage.before;
148 if (dataPackage.withMember) {
149 workload.relativePath += "&with_member=true";
150 }
151 }
152 if (dataPackage.withMember) {
153 workload.relativePath += "?with_member=true";
154 }
155 workload.callStack = "guild_scheduled_events::getGuildScheduledEventUsersAsync()";
156 jsonifier::vector<guild_scheduled_event_user_data> returnData{};
157 guild_scheduled_events::httpsClient->submitWorkloadAndGetResult(std::move(workload), returnData);
158 co_return returnData;
159 }
160
161 discord_core_internal::https_client* guild_scheduled_events::httpsClient{};
162
163}
A co_routine - representing a potentially asynchronous operation/function.
Definition: CoRoutine.hpp:83
Data representing a guild scheduled event.
static co_routine< jsonifier::vector< guild_scheduled_event_user_data > > getGuildScheduledEventUsersAsync(const get_guild_scheduled_event_users_data dataPackage)
Collects a list of users for a given guild_scheduled_event_data.
static co_routine< jsonifier::vector< guild_scheduled_event_data > > getGuildScheduledEventsAsync(const get_guild_scheduled_events_data dataPackage)
Gets a list of a given guild's scheduled events.
static co_routine< void > deleteGuildScheduledEventAsync(const delete_guild_scheduled_event_data dataPackage)
Deletes a single guild_scheduled_event_data.
static co_routine< guild_scheduled_event_data > modifyGuildScheduledEventAsync(const modify_guild_scheduled_event_data dataPackage)
Modifies a single guild_scheduled_event_data.
static co_routine< guild_scheduled_event_data > createGuildScheduledEventAsync(const create_guild_scheduled_event_data dataPackage)
Creates a new guild_scheduled_event_data within a chosen guild.
static co_routine< guild_scheduled_event_data > getGuildScheduledEventAsync(const get_guild_scheduled_event_data dataPackage)
Collects a single guild_scheduled_event_data.
@ stream
Allows the user to go live.
The main namespace for the forward-facing interfaces.
snowflake guildId
The guild within which to create the event.
snowflake guildId
The guild within which to modify the event.
snowflake guildScheduledEventId
The id of the event to modify.
For collecting a single guild scheduled event.
snowflake guildScheduledEventId
The id of the desired scheduled event.
snowflake guildId
Guild from which we would like to collect the events.
For collecting a list of guild scheduled event users.
snowflake before
consider only users before given user id.
bool withMember
Include guild member responseData if it exists.
uint32_t limit
How many users to receive from the event.
snowflake guildId
The guild within which to modify the event.
snowflake after
consider only users after given user id.
For collecting a list of a guild's scheduled events.
snowflake guildId
Guild from which we would like to collect the events.
For modifying a single guild scheduled event.
snowflake guildScheduledEventId
The id of the event to modify.
snowflake guildId
The guild within which to modify the event.