LibAC-dart/lib/discord/structures/sticker.dart

112 lines
2.8 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']));
}
}