DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
ToEntity.hpp
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/// ToEntity.hpp - Header for the final index.
27/// Oct 6, 2021
28/// https://discordcoreapi.com
29/// \file ToEntity.hpp
30#pragma once
31
34
35namespace discord_core_api {
36
37 template<> struct to_entity<guild_data> {
38 guild_data toEntity(snowflake id) {
39 if (guilds::doWeCacheGuilds()) {
40 return guilds::getCachedGuild({ .guildId = id });
41 } else {
42 return guilds::getGuildAsync({ .guildId = id }).get();
43 }
44 }
45 };
46
47 template<> struct to_entity<user_data> {
48 user_data toEntity(snowflake id) {
49 if (guilds::doWeCacheGuilds()) {
50 return users::getCachedUser({ .userId = id });
51 } else {
52 return users::getUserAsync({ .userId = id }).get();
53 }
54 }
55 };
56
57 template<> struct to_entity<channel_data> {
58 channel_data toEntity(snowflake id) {
59 if (guilds::doWeCacheGuilds()) {
60 return channels::getCachedChannel({ .channelId = id });
61 } else {
62 return channels::getChannelAsync({ .channelId = id }).get();
63 }
64 }
65 };
66
67 template<> struct to_entity<role_data> {
68 role_data toEntity(snowflake id) {
69 if (guilds::doWeCacheGuilds()) {
70 return roles::getCachedRole({ .roleId = id });
71 } else {
72 return roles::getRoleAsync({ .roleId = id }).get();
73 }
74 }
75 };
76
77 template<> struct to_entity<guild_member_data> {
78 guild_member_data toEntity(snowflake id, snowflake idTwo) {
79 if (guilds::doWeCacheGuilds()) {
80 return guild_members::getCachedGuildMember({ .guildMemberId = id, .guildId = idTwo });
81 } else {
82 return guild_members::getGuildMemberAsync({ .guildMemberId = id, .guildId = idTwo }).get();
83 }
84 }
85 };
86
87 template<> struct to_entity<message_data> {
88 message_data toEntity(snowflake idNew, snowflake channelIdNew) {
89 return messages::getMessageAsync({ .channelId = channelIdNew, .id = idNew }).get();
90 }
91 };
92
93 template<> struct to_entity<stage_instance_data> {
94 stage_instance_data toEntity(snowflake idNew) {
95 return stage_instances::getStageInstanceAsync({ .channelId = idNew }).get();
96 }
97 };
98
99}
static channel_cache_data getCachedChannel(const get_channel_data dataPackage)
Collects a channel from the library's cache.
static co_routine< channel_data > getChannelAsync(const get_channel_data dataPackage)
Collects a channel from the discord servers.
static guild_member_cache_data getCachedGuildMember(const get_guild_member_data dataPackage)
Collects a guild_member from the library's cache.
static co_routine< guild_member_data > getGuildMemberAsync(const get_guild_member_data dataPackage)
Collects a guild_member from the discord servers.
static co_routine< guild_data > getGuildAsync(const get_guild_data dataPackage)
Collects a guild from the discord servers.
static guild_cache_data getCachedGuild(const get_guild_data dataPackage)
Collects a guild from the library's cache.
static co_routine< message_data > getMessageAsync(const get_message_data dataPackage)
Collects a message from the discord servers.
static co_routine< role_data > getRoleAsync(const get_role_data dataPackage)
Collects a role_data from the discord servers.
static role_cache_data getCachedRole(const get_role_data dataPackage)
Collects a given role from the library's cache.
static co_routine< stage_instance_data > getStageInstanceAsync(const get_stage_instance_data dataPackage)
Collects a stage_instance_data.
static user_cache_data getCachedUser(const get_user_data dataPackage)
Collects a given user from the library's cache.
static co_routine< user_data > getUserAsync(const get_user_data dataPackage)
Collects a given user from the discord servers.
The main namespace for the forward-facing interfaces.