| 1 | /************************************************************************************ |
| 2 | * |
| 3 | * D++, A Lightweight C++ library for Discord |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * Copyright 2021 Craig Edwards and D++ contributors |
| 7 | * (https://github.com/brainboxdotcc/DPP/graphs/contributors) |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | ************************************************************************************/ |
| 22 | #include <dpp/dtemplate.h> |
| 23 | #include <dpp/discordevents.h> |
| 24 | #include <dpp/json.h> |
| 25 | |
| 26 | namespace dpp { |
| 27 | |
| 28 | using json = nlohmann::json; |
| 29 | |
| 30 | dtemplate::dtemplate() : code(""), name(""), description(""), usage_count(0), creator_id(0), source_guild_id(0) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | dtemplate& dtemplate::fill_from_json_impl(nlohmann::json* j) { |
| 35 | code = string_not_null(j, "code"); |
| 36 | name = string_not_null(j, "name"); |
| 37 | description = string_not_null(j, "description"); |
| 38 | usage_count = int32_not_null(j, "usage_count"); |
| 39 | creator_id = snowflake_not_null(j, "creator_id"); |
| 40 | created_at = ts_not_null(j, "created_at"); |
| 41 | updated_at = ts_not_null(j, "updated_at"); |
| 42 | source_guild_id = snowflake_not_null(j, "source_guild_id"); |
| 43 | is_dirty = bool_not_null(j, "is_dirty"); |
| 44 | return *this; |
| 45 | } |
| 46 | |
| 47 | json dtemplate::to_json_impl(bool with_id) const { |
| 48 | return { |
| 49 | {"code", code}, |
| 50 | {"name", name}, |
| 51 | {"description", description}, |
| 52 | {"usage_count", usage_count}, |
| 53 | {"creator_id", creator_id}, |
| 54 | {"updated_at", updated_at}, |
| 55 | {"source_guild_id", source_guild_id, |
| 56 | "is_dirty", is_dirty} |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | } |