Implement snowflakes
This commit is contained in:
parent
660b7df562
commit
662b93e011
4 changed files with 103 additions and 25 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:libac_dart/discord/structures/user.dart';
|
||||
import 'package:libac_dart/structs/Snowflake.dart';
|
||||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
class ApplicationPacket {
|
||||
|
@ -8,13 +9,13 @@ class ApplicationPacket {
|
|||
bool botRequiresCodeGrant;
|
||||
String? coverImage;
|
||||
String description;
|
||||
String? guildId;
|
||||
Snowflake? guildId;
|
||||
String? icon;
|
||||
String id;
|
||||
Snowflake id;
|
||||
Map<String, ApplicationIntegrationType>? integrationConfig;
|
||||
String name;
|
||||
User? owner;
|
||||
String? primarySkuId;
|
||||
Snowflake? primarySkuId;
|
||||
String? slug;
|
||||
String summary;
|
||||
|
||||
|
@ -48,13 +49,13 @@ class ApplicationPacket {
|
|||
"bot_require_code_grant": botRequiresCodeGrant,
|
||||
if (coverImage != null) "cover_image": coverImage,
|
||||
"description": description,
|
||||
if (guildId != null) "guild_id": guildId,
|
||||
if (guildId != null) "guild_id": guildId.toString(),
|
||||
"icon": icon,
|
||||
"id": id,
|
||||
"id": id.toString(),
|
||||
if (integrationConfig != null) "integration_types_config": itc,
|
||||
"name": name,
|
||||
if (owner != null) "owner": owner!.toJson(),
|
||||
if (primarySkuId != null) "primary_sku_id": primarySkuId,
|
||||
if (primarySkuId != null) "primary_sku_id": primarySkuId.toString(),
|
||||
if (slug != null) "slug": slug,
|
||||
"summary": summary,
|
||||
};
|
||||
|
@ -84,13 +85,18 @@ class ApplicationPacket {
|
|||
botRequiresCodeGrant: js['bot_require_code_grant'] as bool,
|
||||
coverImage: setor(js, 'cover_image', null),
|
||||
description: js['description'] as String,
|
||||
guildId: setor(js, 'guild_id', null),
|
||||
id: js['id'] as String,
|
||||
guildId: js.containsKey("guild_id")
|
||||
? Snowflake.parse(js['guild_id'] as String, Snowflake.DiscordEpoch)
|
||||
: null,
|
||||
id: Snowflake.parse(js['id'] as String, Snowflake.DiscordEpoch),
|
||||
integrationConfig: itc,
|
||||
name: js['name'] as String,
|
||||
owner: User.decode(js['owner']),
|
||||
icon: js['icon'],
|
||||
primarySkuId: setor(js, 'primary_sku_id', null),
|
||||
primarySkuId: js.containsKey("primary_sku_id")
|
||||
? Snowflake.parse(
|
||||
js['primary_sku_id'] as String, Snowflake.DiscordEpoch)
|
||||
: null,
|
||||
slug: setor(js, "slug", null),
|
||||
summary: js['summary']);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ import 'dart:convert';
|
|||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
import '../../structs/Bitmasks.dart';
|
||||
import '../../structs/Snowflake.dart';
|
||||
|
||||
class User {
|
||||
String id;
|
||||
Snowflake id;
|
||||
String username;
|
||||
String discriminator;
|
||||
String? globalName;
|
||||
|
@ -54,7 +55,7 @@ class User {
|
|||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"id": id,
|
||||
"id": id.toString(),
|
||||
"username": username,
|
||||
"discriminator": discriminator,
|
||||
"global_name": globalName,
|
||||
|
@ -81,7 +82,7 @@ class User {
|
|||
static User? decode(Map<String, dynamic>? js) {
|
||||
if (js == null) return null;
|
||||
return User(
|
||||
id: js['id'] as String,
|
||||
id: Snowflake.parse(js['id'] as String, Snowflake.DiscordEpoch),
|
||||
username: js['username'] as String,
|
||||
discriminator: js['discrimination'] as String,
|
||||
globalName: js['global_name'],
|
||||
|
@ -137,7 +138,7 @@ enum PremiumType {
|
|||
|
||||
class AvatarDecorationData {
|
||||
String asset;
|
||||
String sku;
|
||||
Snowflake sku;
|
||||
|
||||
AvatarDecorationData({required this.asset, required this.sku});
|
||||
|
||||
|
@ -146,7 +147,7 @@ class AvatarDecorationData {
|
|||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {"asset": asset, "sku_id": sku};
|
||||
return {"asset": asset, "sku_id": sku.toString()};
|
||||
}
|
||||
|
||||
factory AvatarDecorationData.fromJson(String js) {
|
||||
|
@ -155,16 +156,17 @@ class AvatarDecorationData {
|
|||
|
||||
factory AvatarDecorationData.decode(Map<String, dynamic> js) {
|
||||
return AvatarDecorationData(
|
||||
asset: js['asset'] as String, sku: js['sku_id'] as String);
|
||||
asset: js['asset'] as String,
|
||||
sku: Snowflake.parse(js['sku_id'] as String, Snowflake.DiscordEpoch));
|
||||
}
|
||||
}
|
||||
|
||||
class Team {
|
||||
String? icon;
|
||||
String id;
|
||||
Snowflake id;
|
||||
List<TeamMember> members;
|
||||
String name;
|
||||
String ownerUserId;
|
||||
Snowflake ownerUserId;
|
||||
|
||||
Team(
|
||||
{required this.icon,
|
||||
|
@ -183,10 +185,10 @@ class Team {
|
|||
|
||||
return {
|
||||
"icon": icon,
|
||||
"id": id,
|
||||
"id": id.toString(),
|
||||
"members": membersJs,
|
||||
"name": name,
|
||||
"owner_user_id": ownerUserId
|
||||
"owner_user_id": ownerUserId.toString()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -204,16 +206,17 @@ class Team {
|
|||
|
||||
return Team(
|
||||
icon: js['icon'],
|
||||
id: js['id'],
|
||||
id: Snowflake.parse(js['id'], Snowflake.DiscordEpoch),
|
||||
members: memberjs,
|
||||
name: js['name'],
|
||||
ownerUserId: js['owner_user_id']);
|
||||
ownerUserId:
|
||||
Snowflake.parse(js['owner_user_id'], Snowflake.DiscordEpoch));
|
||||
}
|
||||
}
|
||||
|
||||
class TeamMember {
|
||||
MembershipState membershipState;
|
||||
String teamId;
|
||||
Snowflake teamId;
|
||||
User user;
|
||||
String role;
|
||||
|
||||
|
@ -230,7 +233,7 @@ class TeamMember {
|
|||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"membership_state": membershipState,
|
||||
"team_id": teamId,
|
||||
"team_id": teamId.toString(),
|
||||
"user": user.toJson(),
|
||||
"role": role
|
||||
};
|
||||
|
@ -243,7 +246,7 @@ class TeamMember {
|
|||
factory TeamMember.decode(Map<String, dynamic> js) {
|
||||
return TeamMember(
|
||||
membershipState: MembershipState.of(js['membership_state']),
|
||||
teamId: js['team_id'],
|
||||
teamId: Snowflake.parse(js['team_id'], Snowflake.DiscordEpoch),
|
||||
user: User.decode(js['user'] as Map<String, dynamic>)!,
|
||||
role: js['role']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue