Start to add discord API structures
This commit is contained in:
parent
f6aac8fdc6
commit
bcaf02091f
3 changed files with 296 additions and 0 deletions
156
lib/discord/user.dart
Normal file
156
lib/discord/user.dart
Normal file
|
@ -0,0 +1,156 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
class User {
|
||||
String id;
|
||||
String username;
|
||||
String discriminator;
|
||||
String? globalName;
|
||||
String? avatar;
|
||||
bool? bot;
|
||||
bool? system;
|
||||
bool? mfaEnabled;
|
||||
String? banner;
|
||||
int? accentColor;
|
||||
String? locale;
|
||||
bool? verified;
|
||||
String? email;
|
||||
UserFlags? flags;
|
||||
PremiumType? premiumType;
|
||||
UserFlags? publicFlags;
|
||||
AvatarDecorationData? decoration;
|
||||
|
||||
User(
|
||||
{required this.id,
|
||||
required this.username,
|
||||
required this.discriminator,
|
||||
this.globalName,
|
||||
this.avatar,
|
||||
this.bot,
|
||||
this.system,
|
||||
this.mfaEnabled,
|
||||
this.banner,
|
||||
this.accentColor,
|
||||
this.locale,
|
||||
this.verified,
|
||||
this.email,
|
||||
this.flags,
|
||||
this.premiumType,
|
||||
this.publicFlags,
|
||||
this.decoration});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"id": id,
|
||||
"username": username,
|
||||
"discriminator": discriminator,
|
||||
"global_name": globalName,
|
||||
"avatar": avatar,
|
||||
if (bot != null) "bot": bot,
|
||||
if (system != null) "system": system,
|
||||
if (mfaEnabled != null) "mfa_enabled": mfaEnabled,
|
||||
if (banner != null) "banner": banner,
|
||||
if (accentColor != null) "accent_color": accentColor,
|
||||
if (locale != null) "locale": locale,
|
||||
if (verified != null) "verified": verified,
|
||||
if (email != null) "email": email,
|
||||
if (flags != null) "flags": flags!.flags,
|
||||
if (premiumType != null) "premium_type": premiumType!.flag,
|
||||
if (publicFlags != null) "public_flags": publicFlags!.flags,
|
||||
if (decoration != null) "avatar_decoration_data": decoration!.toJson()
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromJson(String js) {
|
||||
return User.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory User.decode(Map<String, dynamic> js) {
|
||||
return User(
|
||||
id: js['id'] as String,
|
||||
username: js['username'] as String,
|
||||
discriminator: js['discrimination'] as String,
|
||||
globalName: js['global_name'],
|
||||
avatar: js['avatar'],
|
||||
bot: setor(js, "bot", null),
|
||||
system: setor(js, "system", null),
|
||||
mfaEnabled: setor(js, "mfa_enabled", null),
|
||||
banner: setor(js, "banner", null),
|
||||
accentColor: setor(js, "accent_color", null),
|
||||
locale: setor(js, "locale", null),
|
||||
verified: setor(js, "verified", null),
|
||||
email: setor(js, "email", null),
|
||||
flags: UserFlags.decode(setor(js, "flags", null)),
|
||||
premiumType: PremiumType.decode(setor(js, "premium_type", null)),
|
||||
publicFlags: UserFlags.decode(setor(js, "public_flags", null)),
|
||||
decoration: AvatarDecorationData.decode(
|
||||
setor(js, "avatar_decoration_data", null)));
|
||||
}
|
||||
}
|
||||
|
||||
enum UserFlags {
|
||||
DiscordEmployee(1 << 0),
|
||||
PartneredServerOwner(1 << 1),
|
||||
HypeSquadEvents(1 << 2),
|
||||
BugHunterLv1(1 << 3),
|
||||
HouseBravery(1 << 6),
|
||||
HouseBrilliance(1 << 7),
|
||||
HouseBalance(1 << 8),
|
||||
EarlyNitro(1 << 9),
|
||||
Team(1 << 10),
|
||||
BugHunterLv2(1 << 14),
|
||||
VerifiedBot(1 << 16),
|
||||
VerifiedEarlyDeveloper(1 << 17),
|
||||
ModeratorProgramAlumni(1 << 18),
|
||||
BotHTTP(1 << 19),
|
||||
ActiveDeveloper(1 << 22);
|
||||
|
||||
final int flags;
|
||||
|
||||
const UserFlags(this.flags);
|
||||
|
||||
static UserFlags? decode(dynamic value) {
|
||||
if (value == null) return null;
|
||||
int flag = value as int;
|
||||
}
|
||||
}
|
||||
|
||||
enum PremiumType {
|
||||
None(0),
|
||||
Classic(1),
|
||||
Nitro(2),
|
||||
Basic(3);
|
||||
|
||||
final int flag;
|
||||
|
||||
const PremiumType(this.flag);
|
||||
}
|
||||
|
||||
class AvatarDecorationData {
|
||||
String asset;
|
||||
String sku;
|
||||
|
||||
AvatarDecorationData({required this.asset, required this.sku});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {"asset": asset, "sku_id": sku};
|
||||
}
|
||||
|
||||
factory AvatarDecorationData.fromJson(String js) {
|
||||
return AvatarDecorationData.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory AvatarDecorationData.decode(Map<String, dynamic> js) {
|
||||
return AvatarDecorationData(
|
||||
asset: js['asset'] as String, sku: js['sku_id'] as String);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue