176 lines
4.6 KiB
Dart
176 lines
4.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:libac_dart/discord/structures/user.dart';
|
|
|
|
import '../../structs/Snowflake.dart';
|
|
|
|
class Sticker {
|
|
Snowflake id;
|
|
Snowflake? packId;
|
|
String name;
|
|
String? description;
|
|
String tags;
|
|
String? asset;
|
|
int type;
|
|
int formatType;
|
|
bool? available;
|
|
Snowflake? guildId;
|
|
User? user;
|
|
int? sortValue;
|
|
|
|
Sticker(
|
|
{required this.id,
|
|
this.packId,
|
|
required this.name,
|
|
required this.description,
|
|
required this.tags,
|
|
this.asset,
|
|
required this.type,
|
|
required this.formatType,
|
|
this.available,
|
|
this.guildId,
|
|
this.user,
|
|
this.sortValue});
|
|
|
|
String encode() {
|
|
return json.encode(toJson());
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
"id": id.toString(),
|
|
if (packId != null) "pack_id": packId.toString(),
|
|
"name": name,
|
|
"description": description,
|
|
"tags": tags,
|
|
if (asset != null) "asset": asset,
|
|
"type": type,
|
|
"format_type": formatType,
|
|
if (available != null) "available": available,
|
|
if (guildId != null) "guild_id": guildId,
|
|
if (user != null) "user": user!.toJson(),
|
|
if (sortValue != null) "sort_value": sortValue
|
|
};
|
|
}
|
|
|
|
factory Sticker.fromJson(String js) {
|
|
return Sticker.decode(json.decode(js));
|
|
}
|
|
|
|
factory Sticker.decode(Map<String, dynamic> js) {
|
|
return Sticker(
|
|
id: Snowflake.parse(js['id'], Snowflake.DiscordEpoch),
|
|
packId: js.containsKey("pack_id")
|
|
? Snowflake.parse(js['pack_id'], Snowflake.DiscordEpoch)
|
|
: null,
|
|
name: js['name'],
|
|
description: js['description'],
|
|
tags: js['tags'],
|
|
asset: js['asset'],
|
|
type: js['type'],
|
|
formatType: js['format_type'],
|
|
available:
|
|
js.containsKey("available") ? bool.parse(js['available']) : null,
|
|
guildId: js.containsKey("guild_id")
|
|
? Snowflake.parse(js['guild_id'], Snowflake.DiscordEpoch)
|
|
: null,
|
|
user: js.containsKey("user") ? User.decode(js['user']) : null,
|
|
sortValue:
|
|
js.containsKey("sort_value") ? int.parse(js['sort_value']) : null);
|
|
}
|
|
}
|
|
|
|
enum StickerType { STANDARD, GUILD }
|
|
|
|
enum StickerFormatTypes { PNG, APNG, LOTTIE, GIF }
|
|
|
|
class StickerItem {
|
|
Snowflake id;
|
|
String name;
|
|
int formatType;
|
|
|
|
StickerItem({required this.id, required this.name, required this.formatType});
|
|
|
|
String encode() {
|
|
return json.encode(toJson());
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {"id": id.toString(), "name": name, "format_type": formatType};
|
|
}
|
|
|
|
factory StickerItem.fromJson(String js) {
|
|
return StickerItem.decode(json.decode(js));
|
|
}
|
|
|
|
factory StickerItem.decode(Map<String, dynamic> js) {
|
|
return StickerItem(
|
|
id: Snowflake.parse(js['id'], Snowflake.DiscordEpoch),
|
|
name: js['name'],
|
|
formatType: int.parse(js['format_type']));
|
|
}
|
|
}
|
|
|
|
class StickerPack {
|
|
Snowflake id;
|
|
List<Sticker> stickers;
|
|
String name;
|
|
Snowflake sku_id;
|
|
Snowflake? coverStickerId;
|
|
String description;
|
|
Snowflake? bannerAssetId;
|
|
|
|
StickerPack(
|
|
{required this.id,
|
|
required this.stickers,
|
|
required this.name,
|
|
required this.sku_id,
|
|
this.coverStickerId,
|
|
required this.description,
|
|
this.bannerAssetId});
|
|
|
|
String encode() {
|
|
return json.encode(toJson());
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
List<Map<String, dynamic>> stickersJs = [];
|
|
for (Sticker sticker in stickers) {
|
|
stickersJs.add(sticker.toJson());
|
|
}
|
|
|
|
return {
|
|
"id": id.toString(),
|
|
"stickers": stickersJs,
|
|
"name": name,
|
|
"sku_id": sku_id.toString(),
|
|
if (coverStickerId != null) "cover_sticker_id": coverStickerId.toString(),
|
|
"description": description,
|
|
if (bannerAssetId != null) "banner_asset_id": bannerAssetId.toString()
|
|
};
|
|
}
|
|
|
|
factory StickerPack.fromJson(String js) {
|
|
return StickerPack.decode(json.decode(js));
|
|
}
|
|
|
|
factory StickerPack.decode(Map<String, dynamic> js) {
|
|
List<Sticker> jsStickers = [];
|
|
for (var entry in js['stickers']) {
|
|
jsStickers.add(Sticker.decode(entry));
|
|
}
|
|
|
|
return StickerPack(
|
|
id: Snowflake.parse(js['id'], Snowflake.DiscordEpoch),
|
|
stickers: jsStickers,
|
|
name: js['name'],
|
|
sku_id: Snowflake.parse(js['sku_id'], Snowflake.DiscordEpoch),
|
|
coverStickerId: js.containsKey("cover_sticker_id")
|
|
? Snowflake.parse(js['cover_sticker_id'], Snowflake.DiscordEpoch)
|
|
: null,
|
|
description: js['description'],
|
|
bannerAssetId: js.containsKey("banner_asset_id")
|
|
? Snowflake.parse(js['banner_asset_id'], Snowflake.DiscordEpoch)
|
|
: null);
|
|
}
|
|
}
|