From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- src/discord/sticker.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/discord/sticker.cpp (limited to 'src/discord/sticker.cpp') diff --git a/src/discord/sticker.cpp b/src/discord/sticker.cpp new file mode 100644 index 0000000..b92d031 --- /dev/null +++ b/src/discord/sticker.cpp @@ -0,0 +1,52 @@ +#include "sticker.hpp" + +void to_json(nlohmann::json &j, const StickerData &m) { + j["id"] = m.ID; + j["pack_id"] = m.PackID; + j["name"] = m.Name; + j["description"] = m.Description; + JS_IF("tags", m.Tags); + JS_IF("asset", m.AssetHash); + JS_IF("preview_asset", m.PreviewAssetHash); + j["format_type"] = m.FormatType; +} + +void from_json(const nlohmann::json &j, StickerData &m) { + JS_D("id", m.ID); + JS_D("pack_id", m.PackID); + JS_D("name", m.Name); + JS_D("description", m.Description); + JS_O("tags", m.Tags); + JS_O("asset", m.AssetHash); + JS_ON("preview_asset", m.PreviewAssetHash); + JS_D("format_type", m.FormatType); +} + +std::string StickerData::GetURL() const { + if (!AssetHash.has_value()) return ""; + if (FormatType == StickerFormatType::PNG || FormatType == StickerFormatType::APNG) + return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".png?size=256"; + else if (FormatType == StickerFormatType::LOTTIE) + return "https://media.discordapp.net/stickers/" + std::to_string(ID) + "/" + *AssetHash + ".json"; + return ""; +} + +void to_json(nlohmann::json &j, const StickerItem &m) { + j["id"] = m.ID; + j["name"] = m.Name; + j["format_type"] = m.FormatType; +} + +void from_json(const nlohmann::json &j, StickerItem &m) { + JS_D("id", m.ID); + JS_D("name", m.Name); + JS_D("format_type", m.FormatType); +} + +std::string StickerItem::GetURL() const { + if (FormatType == StickerFormatType::PNG || FormatType == StickerFormatType::APNG) + return "https://media.discordapp.net/stickers/" + std::to_string(ID) + ".png?size=256"; + else if (FormatType == StickerFormatType::LOTTIE) + return "https://media.discordapp.net/stickers/" + std::to_string(ID) + ".json"; + return ""; +} -- cgit v1.2.3