Skip to content

Commit 018a246

Browse files
committed
Added missing models implementations, documentations, and bitset getters
1 parent 38223c4 commit 018a246

25 files changed

+933
-152
lines changed

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class _MyHomePageState extends State<MyHomePage> {
7575
),
7676
).then((_) {
7777
if (_discordClient.discordHttpClient.discordToken != null) {
78-
print(
78+
debugPrint(
7979
"TOKEN: ${_discordClient.discordHttpClient.discordToken?.accessToken}");
8080
return _discordClient.discordHttpClient.discordToken;
8181
}

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ packages:
136136
name: path
137137
url: "https://pub.dartlang.org"
138138
source: hosted
139-
version: "1.8.0"
139+
version: "1.8.1"
140140
sky_engine:
141141
dependency: transitive
142142
description: flutter
@@ -183,7 +183,7 @@ packages:
183183
name: test_api
184184
url: "https://pub.dartlang.org"
185185
source: hosted
186-
version: "0.4.8"
186+
version: "0.4.9"
187187
typed_data:
188188
dependency: transitive
189189
description:

lib/src/models/discord_activity.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,17 @@ class DiscordActivity {
126126
DiscordActivityType get typeAsEnum =>
127127
_typeAsEnum ??= DiscordActivityType.values[type];
128128

129-
// TODO: RECOVER FLAGS FROM BITSET IN DISCORD ACTIVITY
130-
131-
// List<DiscordActivityFlag>? get flagsAsEnum =>
132-
// _flagsAsEnum ??= DiscordActivityFlag.valuesFromMask(flags);
129+
List<DiscordActivityFlag>? get flagsAsEnum {
130+
if (_flagsAsEnum != null) return _flagsAsEnum!;
131+
if (flags == null) return _flagsAsEnum ??= [];
132+
_flagsAsEnum = <DiscordActivityFlag>[];
133+
for (final k in DiscordActivityFlag.values) {
134+
if ((flags! & (1 << k.index)) >> k.index == 1) {
135+
_flagsAsEnum!.add(k);
136+
}
137+
}
138+
return _flagsAsEnum!;
139+
}
133140

134141
factory DiscordActivity.fromJson(Map<String, dynamic> json) =>
135142
DiscordActivity(

lib/src/models/discord_attachment.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import 'discord_snowflake.dart';
22

3-
// TODO: Add Documentation
43
class DiscordAttachment {
4+
/// attachment id
55
final DiscordSnowflake id;
6+
7+
/// name of file attached
68
final String filename;
9+
10+
/// description for the file
711
final String? description;
12+
13+
/// the attachment's [media type](https://en.wikipedia.org/wiki/Media_type)
814
final String? contentType;
15+
16+
/// size of file in bytes
917
final int size;
18+
19+
/// source url of file
1020
final String url;
21+
22+
/// a proxied url of file
1123
final String proxyUrl;
24+
25+
/// height of file (if image)
1226
final int? height;
27+
28+
/// width of file (if image)
1329
final int? width;
30+
31+
/// whether this attachment is ephemeral
1432
final bool? ephemeral;
1533

1634
static const idEntry = 'id';

lib/src/models/discord_audit_log.dart

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,23 @@ class DiscordAuditLog {
4747
factory DiscordAuditLog.fromJson(Map<String, dynamic> json) =>
4848
DiscordAuditLog(
4949
auditLogEntries: List<DiscordAuditLogEntry>.from(
50-
json[auditLogEntriesEntry].map(
51-
(x) => DiscordAuditLogEntry.fromJson(
52-
x as Map<String, dynamic>,
53-
),
54-
),
50+
json[auditLogEntriesEntry].map(DiscordAuditLogEntry.fromJson),
5551
),
5652
guildScheduledEvents: List<DiscordGuildScheduledEvent>.from(
57-
json[guildScheduledEventsEntry].map(
58-
(x) => DiscordGuildScheduledEvent.fromJson(
59-
x as Map<String, dynamic>,
60-
),
61-
),
53+
json[guildScheduledEventsEntry]
54+
.map(DiscordGuildScheduledEvent.fromJson),
6255
),
6356
integrations: List<DiscordIntegration>.from(
64-
json[integrationsEntry].map(
65-
(x) => DiscordIntegration.fromJson(
66-
x as Map<String, dynamic>,
67-
),
68-
),
57+
json[integrationsEntry].map(DiscordIntegration.fromJson),
6958
),
7059
threads: List<DiscordChannel>.from(
71-
json[threadsEntry].map(
72-
(x) => DiscordChannel.fromJson(
73-
x as Map<String, dynamic>,
74-
),
75-
),
60+
json[threadsEntry].map(DiscordChannel.fromJson),
7661
),
7762
users: List<DiscordUser>.from(
78-
json[usersEntry].map(
79-
(x) => DiscordUser.fromJson(
80-
x as Map<String, dynamic>,
81-
),
82-
),
63+
json[usersEntry].map(DiscordUser.fromJson),
8364
),
8465
webhooks: List<DiscordWebhook>.from(
85-
json[webhooksEntry].map(
86-
(x) => DiscordWebhook.fromJson(
87-
x as Map<String, dynamic>,
88-
),
89-
),
66+
json[webhooksEntry].map(DiscordWebhook.fromJson),
9067
),
9168
);
9269
}

lib/src/models/discord_authorization_information.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class DiscordAuthorizationInformation {
3333

3434
factory DiscordAuthorizationInformation.fromJson(Map<String, dynamic> json) =>
3535
DiscordAuthorizationInformation(
36-
application: DiscordApplication.fromJson(json[applicationEntry]),
37-
scopes: List<String>.from(json[scopesEntry]),
38-
expiresAt: DateTime.parse(json[expiresEntry]),
36+
application: DiscordApplication.fromJson(
37+
json[applicationEntry] as Map<String, dynamic>),
38+
scopes: List<String>.from(json[scopesEntry] as List<String>),
39+
expiresAt: DateTime.parse(json[expiresEntry] as String),
3940
user: json[userEntry] != null
40-
? DiscordUser.fromJson(json[userEntry])
41+
? DiscordUser.fromJson(json[userEntry] as Map<String, dynamic>)
4142
: null,
4243
);
4344
}

lib/src/models/discord_ban.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
import 'discord_user.dart';
2+
13
class DiscordBan {
2-
// TODO: Implement!
3-
// https://discord.com/developers/docs/resources/guild#ban-object
4+
// the reason for the ban
5+
final String? reason;
6+
7+
/// the banned user
8+
final DiscordUser user;
9+
10+
static const reasonEntry = 'reason';
11+
static const userEntry = 'user';
12+
13+
DiscordBan({
14+
this.reason,
15+
required this.user,
16+
});
17+
18+
factory DiscordBan.fromJson(Map<String, dynamic> json) {
19+
return DiscordBan(
20+
reason: json[reasonEntry] as String?,
21+
user: DiscordUser.fromJson(json[userEntry] as Map<String, dynamic>),
22+
);
23+
}
424
}

lib/src/models/discord_channel.dart

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,96 @@ import 'discord_thread_metadata.dart';
66
import 'discord_user.dart';
77
import 'discord_video_quality_mode.dart';
88

9-
/// TODO: Add Documentation
109
class DiscordChannel {
10+
/// the id of this channel
1111
final DiscordSnowflake id;
12+
13+
/// the [type of channel](https://discord.com/developers/docs/resources/channel#channel-object-channel-types)
1214
final int type;
15+
1316
late final DiscordChannelType? _typeAsEnum;
17+
18+
/// the id of the guild (may be missing for some channel objects received over gateway guild dispatches)
1419
final DiscordSnowflake? guildId;
20+
21+
/// sorting position of the channel
1522
final int? position;
23+
24+
/// explicit permission overewrites for members and roles
1625
final List<DiscordOverwrite>? permissionOverwrites;
26+
27+
/// the name of the channel (1-100 characters)
1728
final String? name;
29+
30+
/// the channel topic (0-1024 characters)
1831
final String? topic;
32+
33+
/// whether the channel is nsfw
1934
final bool? nsfw;
35+
36+
/// the id of the last message sent in this channel (may not point to an existing or valid message)
2037
final DiscordSnowflake? lastMessageId;
38+
39+
/// the bitrate (in bits) of the voice channel
2140
final int? bitrate;
41+
42+
/// the user limit of the voice channel
2243
final int? userLimit;
44+
45+
/// amount of seconds a user has to wait before sending another message (0-21600);
46+
/// bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected
2347
final int? rateLimitPerUser;
48+
49+
/// the recipients of the DM
2450
final List<DiscordUser>? recipients;
51+
52+
/// icon hash of the group DM
2553
final String? icon;
54+
55+
/// id of the creator of the group DM or thread
2656
final DiscordSnowflake? ownerId;
57+
58+
/// application id of the group DM creator if it is bot-created
59+
final DiscordSnowflake? applicationId;
60+
61+
/// for guild channels: id of the parent category for a channel (each parent category can contain up
62+
/// to 50 channels), for threads: id of the text channel this thread was created
2763
final DiscordSnowflake? parentId;
64+
65+
/// when the last pinned message was pinned. This may be null in events such as
66+
/// GUILD_CREATE when a message is not pinned.
2867
final String? lastPinTimestamp;
68+
2969
late final DateTime? _lastPinTimestampAsDateTime;
30-
final String? rtcRegion; // Id of a voice region
70+
71+
/// [voice region](https://discord.com/developers/docs/resources/voice#voice-region-object)
72+
/// id for the voice channel, automatic when set to null
73+
final String? rtcRegion;
74+
75+
/// the camera [video quality mode](https://discord.com/developers/docs/resources/channel#channel-object-video-quality-modes)
76+
/// of the voice channel, 1 when not present
3177
final int? videoQualityMode;
78+
3279
late final DiscordVideoQualityMode? _videoQualityModeAsEnum;
33-
final int? messageCount; // approximative + caps at 50
34-
final int? memberCount; // approximative + caps at 50
80+
81+
/// an approximate count of messages in a thread, stops counting at 50
82+
final int? messageCount;
83+
84+
/// an approximate count of users in a thread, stops counting at 50
85+
final int? memberCount;
86+
87+
/// thread-specific fields not needed by other channels
3588
final DiscordThreadMetadata? threadMetadata;
89+
90+
/// thread member object for the current user, if they have joined the thread, only included on certain API endpoints
3691
final DiscordThreadMember? member;
92+
93+
/// default duration that the clients (not the API) will use for newly created threads, in minutes,
94+
/// to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
3795
final int? defaultAutoArchiveDuration;
96+
97+
/// computed permissions for the invoking user in the channel, including overwrites, only included
98+
/// when part of the `resolved` data received on a slash command interaction
3899
final String? permissions;
39100

40101
static const idEntry = 'id';
@@ -52,6 +113,7 @@ class DiscordChannel {
52113
static const recipientsEntry = 'recipients';
53114
static const iconEntry = 'icon';
54115
static const ownerIdEntry = 'owner_id';
116+
static const applicationIdEntry = 'application_id';
55117
static const parentIdEntry = 'parent_id';
56118
static const lastPinTimestampEntry = 'last_pin_timestamp';
57119
static const rtcRegionEntry = 'rtc_region';
@@ -80,6 +142,7 @@ class DiscordChannel {
80142
this.recipients,
81143
this.icon,
82144
this.ownerId,
145+
this.applicationId,
83146
this.parentId,
84147
this.lastPinTimestamp,
85148
this.rtcRegion,
@@ -135,6 +198,9 @@ class DiscordChannel {
135198
ownerId: json[ownerIdEntry] != null
136199
? DiscordSnowflake(json[ownerIdEntry] as String)
137200
: null,
201+
applicationId: json[applicationIdEntry] != null
202+
? DiscordSnowflake(json[applicationIdEntry] as String)
203+
: null,
138204
parentId: json[parentIdEntry] != null
139205
? DiscordSnowflake(json[parentIdEntry] as String)
140206
: null,
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
1-
// TODO: Add Documentation
21
enum DiscordChannelType {
2+
/// a text channel within a server
33
guildText,
4+
5+
/// a direct message between users
46
dm,
7+
8+
/// a voice channel within a server
59
guildVoice,
10+
11+
/// a direct message between multiple users
612
groupDm,
13+
14+
/// an [organizational category](https://support.discord.com/hc/en-us/articles/115001580171-Channel-Categories-101)
15+
/// that contains up to 50 channels
716
guildCategory,
17+
18+
/// a channel that [users can follow and crosspost into their own server](https://support.discord.com/hc/en-us/articles/360032008192)
819
guildNews,
20+
21+
/// a channel in which game developers can [sell their game on Discord]()
922
guildStore,
23+
1024
unused7,
1125
unused8,
1226
unused9,
27+
28+
/// a temporary sub-channel within a GUILD_NEWS channel
29+
///
30+
/// only available in API v9
1331
guildNewsThread,
32+
33+
/// a temporary sub-channel within a GUILD_TEXT channel
34+
///
35+
/// only available in API v9
1436
guildPublicThread,
37+
38+
/// a temporary sub-channel within a GUILD_TEXT channel that is only viewable
39+
/// by those invited and those with the MANAGE_THREADS permission
40+
///
41+
/// only available in API v9
1542
guildPrivateThread,
43+
44+
/// a voice channel for [hosting events with an audience](https://support.discord.com/hc/en-us/articles/1500005513722)
1645
guildStageVoice,
1746
}

0 commit comments

Comments
 (0)