Start adding networking stuff
This commit is contained in:
parent
d310401ecb
commit
b905722b20
3 changed files with 2 additions and 2 deletions
152
lib/discord/structures/application.dart
Normal file
152
lib/discord/structures/application.dart
Normal file
|
@ -0,0 +1,152 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:libac_dart/discord/structures/user.dart';
|
||||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
class ApplicationPacket {
|
||||
bool botPublic;
|
||||
bool botRequiresCodeGrant;
|
||||
String? coverImage;
|
||||
String description;
|
||||
String? guildId;
|
||||
String? icon;
|
||||
String id;
|
||||
Map<String, ApplicationIntegrationType>? integrationConfig;
|
||||
String name;
|
||||
User? owner;
|
||||
String? primarySkuId;
|
||||
String? slug;
|
||||
String summary;
|
||||
|
||||
ApplicationPacket(
|
||||
{required this.botPublic,
|
||||
required this.botRequiresCodeGrant,
|
||||
this.coverImage,
|
||||
required this.description,
|
||||
this.guildId,
|
||||
required this.id,
|
||||
this.integrationConfig,
|
||||
required this.name,
|
||||
this.icon,
|
||||
this.owner,
|
||||
this.primarySkuId,
|
||||
this.slug,
|
||||
required this.summary});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> itc = {};
|
||||
|
||||
if (integrationConfig != null) {
|
||||
for (MapEntry<String, ApplicationIntegrationType> entry
|
||||
in integrationConfig!.entries) {
|
||||
itc[entry.key] = entry.value.toJson();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
"bot_public": botPublic,
|
||||
"bot_require_code_grant": botRequiresCodeGrant,
|
||||
if (coverImage != null) "cover_image": coverImage,
|
||||
"description": description,
|
||||
if (guildId != null) "guild_id": guildId,
|
||||
"icon": icon,
|
||||
"id": id,
|
||||
if (integrationConfig != null) "integration_types_config": itc,
|
||||
"name": name,
|
||||
if (owner != null) "owner": owner!.toJson(),
|
||||
if (primarySkuId != null) "primary_sku_id": primarySkuId,
|
||||
if (slug != null) "slug": slug,
|
||||
"summary": summary,
|
||||
};
|
||||
}
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
factory ApplicationPacket.fromJson(String js) {
|
||||
return ApplicationPacket.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory ApplicationPacket.decode(Map<String, dynamic> js) {
|
||||
Map<String, ApplicationIntegrationType>? itc = null;
|
||||
if (js.containsKey("integration_types_config")) {
|
||||
itc = {};
|
||||
var itc_js = js["integration_types_config"] as Map<String, dynamic>;
|
||||
for (MapEntry<String, dynamic> jsx in itc_js.entries) {
|
||||
itc[jsx.key] = ApplicationIntegrationType.decode(
|
||||
jsx.value as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
|
||||
return ApplicationPacket(
|
||||
botPublic: js['bot_public'] as bool,
|
||||
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,
|
||||
integrationConfig: itc,
|
||||
name: js['name'] as String,
|
||||
owner: User.decode(js['owner']),
|
||||
icon: js['icon'],
|
||||
primarySkuId: setor(js, 'primary_sku_id', null),
|
||||
slug: setor(js, "slug", null),
|
||||
summary: js['summary']);
|
||||
}
|
||||
}
|
||||
|
||||
class OAuth2InstallParams {
|
||||
List<String> scopes;
|
||||
String permissions;
|
||||
|
||||
OAuth2InstallParams({required this.scopes, required this.permissions});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {"scopes": scopes, "permissions": permissions};
|
||||
}
|
||||
|
||||
factory OAuth2InstallParams.fromJson(String js) {
|
||||
return OAuth2InstallParams.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory OAuth2InstallParams.decode(Map<String, dynamic> js) {
|
||||
return OAuth2InstallParams(
|
||||
scopes: js['scopes'] as List<String>,
|
||||
permissions: js['permissions'] as String);
|
||||
}
|
||||
}
|
||||
|
||||
class ApplicationIntegrationType {
|
||||
OAuth2InstallParams? installParams;
|
||||
|
||||
ApplicationIntegrationType({this.installParams});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {"oauth2_install_params": installParams};
|
||||
}
|
||||
|
||||
factory ApplicationIntegrationType.fromJson(String js) {
|
||||
Map<String, dynamic> jd = json.decode(js);
|
||||
return ApplicationIntegrationType.decode(jd);
|
||||
}
|
||||
|
||||
factory ApplicationIntegrationType.decode(Map<String, dynamic> js) {
|
||||
ApplicationIntegrationType ait = ApplicationIntegrationType();
|
||||
if (js["oauth2_install_params"] == null) {
|
||||
ait = ApplicationIntegrationType(
|
||||
installParams:
|
||||
OAuth2InstallParams.decode(js['oauth2_install_params']));
|
||||
}
|
||||
|
||||
return ait;
|
||||
}
|
||||
}
|
277
lib/discord/structures/user.dart
Normal file
277
lib/discord/structures/user.dart
Normal file
|
@ -0,0 +1,277 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:libac_dart/utils/DictTools.dart';
|
||||
|
||||
import '../../structs/Bitmasks.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
|
||||
BitMask? flags;
|
||||
|
||||
/// PremiumType
|
||||
BitMask? premiumType;
|
||||
|
||||
/// UserFlags
|
||||
BitMask? 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!.value,
|
||||
if (premiumType != null) "premium_type": premiumType!.value,
|
||||
if (publicFlags != null) "public_flags": publicFlags!.value,
|
||||
if (decoration != null) "avatar_decoration_data": decoration!.toJson()
|
||||
};
|
||||
}
|
||||
|
||||
factory User.fromJson(String js) {
|
||||
return User.decode(json.decode(js))!;
|
||||
}
|
||||
|
||||
static User? decode(Map<String, dynamic>? js) {
|
||||
if (js == null) return null;
|
||||
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: BitMask.of(setor(js, "flags", null)),
|
||||
premiumType: BitMask.of(setor(js, "premium_type", null)),
|
||||
publicFlags: BitMask.of(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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
class Team {
|
||||
String? icon;
|
||||
String id;
|
||||
List<TeamMember> members;
|
||||
String name;
|
||||
String ownerUserId;
|
||||
|
||||
Team(
|
||||
{required this.icon,
|
||||
required this.id,
|
||||
required this.members,
|
||||
required this.name,
|
||||
required this.ownerUserId});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
List<Map<String, dynamic>> membersJs = [];
|
||||
for (TeamMember tm in members) {}
|
||||
|
||||
return {
|
||||
"icon": icon,
|
||||
"id": id,
|
||||
"members": membersJs,
|
||||
"name": name,
|
||||
"owner_user_id": ownerUserId
|
||||
};
|
||||
}
|
||||
|
||||
factory Team.fromJson(String js) {
|
||||
return Team.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory Team.decode(Map<String, dynamic> js) {
|
||||
List<TeamMember> memberjs = [];
|
||||
List<Map<String, dynamic>> mmap =
|
||||
js['members'] as List<Map<String, dynamic>>;
|
||||
for (var entry in mmap) {
|
||||
memberjs.add(TeamMember.decode(entry));
|
||||
}
|
||||
|
||||
return Team(
|
||||
icon: js['icon'],
|
||||
id: js['id'],
|
||||
members: memberjs,
|
||||
name: js['name'],
|
||||
ownerUserId: js['owner_user_id']);
|
||||
}
|
||||
}
|
||||
|
||||
class TeamMember {
|
||||
MembershipState membershipState;
|
||||
String teamId;
|
||||
User user;
|
||||
String role;
|
||||
|
||||
TeamMember(
|
||||
{required this.membershipState,
|
||||
required this.teamId,
|
||||
required this.user,
|
||||
required this.role});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"membership_state": membershipState,
|
||||
"team_id": teamId,
|
||||
"user": user.toJson(),
|
||||
"role": role
|
||||
};
|
||||
}
|
||||
|
||||
factory TeamMember.fromJson(String js) {
|
||||
return TeamMember.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory TeamMember.decode(Map<String, dynamic> js) {
|
||||
return TeamMember(
|
||||
membershipState: MembershipState.of(js['membership_state']),
|
||||
teamId: js['team_id'],
|
||||
user: User.decode(js['user'] as Map<String, dynamic>)!,
|
||||
role: js['role']);
|
||||
}
|
||||
}
|
||||
|
||||
enum MembershipState {
|
||||
INVITED(1),
|
||||
ACCEPTED(2);
|
||||
|
||||
final int val;
|
||||
|
||||
const MembershipState(this.val);
|
||||
|
||||
static MembershipState of(int val) {
|
||||
switch (val) {
|
||||
case 1:
|
||||
{
|
||||
return MembershipState.INVITED;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return MembershipState.ACCEPTED;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
return MembershipState.INVITED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue