Skip to content

Commit 1d74130

Browse files
committed
Added new objects + TODOs
1 parent d234619 commit 1d74130

File tree

58 files changed

+2387
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2387
-102
lines changed

lib/src/models/discord_allowed_mentions.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import 'discord_mention_type.dart';
22

33
class DiscordAllowedMentions {
4+
/// an array of [allowed mention types](https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mention-types)
5+
/// to parse from the content.
46
final List<String> parse;
7+
58
late final List<DiscordMentionType>? _parseAsEnum;
9+
10+
/// array of role_ids to mention (Max size of 100)
11+
///
12+
/// Should be converted to DiscordSnowflake if the need arise
613
final List<String> roles;
14+
15+
/// array of user_ids to mention (Max size of 100)
16+
///
17+
/// Should be converted to DiscordSnowflake if the need arise
718
final List<String> users;
19+
20+
/// for replies, whether to mention the author of the message being
21+
/// replied to (default false)
822
final bool repliedUser;
923

1024
static const parseEntry = 'parse';

lib/src/models/discord_application.dart

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,88 @@ import 'discord_team.dart';
44
import 'discord_user.dart';
55

66
class DiscordApplication {
7+
/// the id of the app
78
final DiscordSnowflake id;
89

10+
/// the name of the app
911
final String name;
12+
13+
/// the [icon hash](https://discord.com/developers/docs/reference#image-formatting) of the app
14+
///
15+
/// is always returned, but can be null
1016
final String? icon;
17+
18+
/// the description of the app
1119
final String description;
1220

21+
/// an array of rpc origin urls, if rpc is enabled
22+
///
23+
/// is not always returned, hence the nullable property
1324
final List<String>? rpcOrigins;
25+
26+
/// when false only app owner can join the app's bot to guilds
1427
final bool botPublic;
28+
29+
/// when true the app's bot will only join upon completion of the full oauth2
30+
/// code grant flow
1531
final bool botRequireCodeGrant;
32+
33+
/// the url of the app's terms of service
34+
///
35+
/// is not always returned, hence the nullable property
1636
final String? termsOfServiceUrl;
37+
38+
/// the url of the app's privacy policy
39+
///
40+
/// is not always returned, hence the nullable property
1741
final String? privacyPolicyUrl;
42+
43+
/// partial user object containing info on the owner of the application
44+
///
45+
/// is not always returned, hence the nullable property
1846
final DiscordUser? owner;
47+
48+
/// if this application is a game sold on Discord,
49+
/// this field will be the summary field for the store page of its primary sku
1950
final String summary;
51+
52+
/// the hex encoded key for verification in interactions and the
53+
/// GameSDK's [GetTicket](https://discord.com/developers/docs/game-sdk/applications#getticket)
2054
final String verifyKey;
55+
56+
/// if the application belongs to a team, this will be a list of the members of that team
57+
///
58+
/// is always returned, but can be null
2159
final DiscordTeam? team;
60+
61+
/// if this application is a game sold on Discord, this field
62+
/// will be the guild to which it has been linked
63+
///
64+
/// is not always returned, hence the nullable property
2265
final DiscordSnowflake? guildId;
66+
67+
/// if this application is a game sold on Discord, this field
68+
/// will be the id of the "Game SKU" that is created, if exists
69+
///
70+
/// is not always returned, hence the nullable property
2371
final DiscordSnowflake? primarySkuId;
72+
73+
/// if this application is a game sold on Discord, this field
74+
/// will be the URL slug that links to the store page
75+
///
76+
/// is not always returned, hence the nullable property
2477
final String? slug;
78+
79+
/// the application's default rich presence invite [cover image hash](https://discord.com/developers/docs/reference#image-formatting)
80+
///
81+
/// is not always returned, hence the nullable property
2582
final String? coverImage;
83+
84+
/// the application's public [flags](https://discord.com/developers/docs/resources/application#application-object-application-flags)
85+
///
86+
/// is not always returned, hence the nullable property
2687
final int? flags;
88+
2789
late final List<DiscordApplicationFlag>? _flagsAsEnum;
2890

2991
static const idEntry = 'id';
@@ -66,37 +128,8 @@ class DiscordApplication {
66128
this.flags,
67129
});
68130

69-
void _addFlagAsEnum(String r, int index, DiscordApplicationFlag flag) {
70-
if (r.length >= index + 1 && r.substring(index, index + 1) == '1') {
71-
_flagsAsEnum!.add(flag);
72-
}
73-
}
74-
75-
List<DiscordApplicationFlag> get flagsAsEnum {
76-
if (flags == null) {
77-
return <DiscordApplicationFlag>[];
78-
}
79-
if (_flagsAsEnum != null) {
80-
return _flagsAsEnum!;
81-
}
82-
_flagsAsEnum = <DiscordApplicationFlag>[];
83-
final radixString =
84-
String.fromCharCodes(flags!.toRadixString(2).runes.toList().reversed);
85-
_addFlagAsEnum(radixString, 12, DiscordApplicationFlag.gatewayPresence);
86-
_addFlagAsEnum(
87-
radixString, 13, DiscordApplicationFlag.gatewayPresenceLimited);
88-
_addFlagAsEnum(radixString, 14, DiscordApplicationFlag.gatewayGuildMembers);
89-
_addFlagAsEnum(
90-
radixString, 15, DiscordApplicationFlag.gatewayGuildMembersLimited);
91-
_addFlagAsEnum(
92-
radixString, 16, DiscordApplicationFlag.verificationPendingGuildLimit);
93-
_addFlagAsEnum(radixString, 17, DiscordApplicationFlag.embedded);
94-
_addFlagAsEnum(
95-
radixString, 18, DiscordApplicationFlag.gatewayMessageContent);
96-
_addFlagAsEnum(
97-
radixString, 19, DiscordApplicationFlag.gatewayMessageContentLimited);
98-
return _flagsAsEnum!;
99-
}
131+
List<DiscordApplicationFlag> get flagsAsEnum =>
132+
_flagsAsEnum ??= discordApplicationFlagsAsEnum(flags);
100133

101134
factory DiscordApplication.fromJson(Map<String, dynamic> json) =>
102135
DiscordApplication(

lib/src/models/discord_application_flag.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,72 @@ enum DiscordApplicationFlag {
2323
/// 1 << 19
2424
gatewayMessageContentLimited,
2525
}
26+
27+
void _addFlagAsEnum(
28+
String r,
29+
int index,
30+
DiscordApplicationFlag flag,
31+
List<DiscordApplicationFlag> f,
32+
) {
33+
if (r.length >= index + 1 && r.substring(index, index + 1) == '1') {
34+
f.add(flag);
35+
}
36+
}
37+
38+
List<DiscordApplicationFlag> discordApplicationFlagsAsEnum(int? flags) {
39+
if (flags == null) {
40+
return <DiscordApplicationFlag>[];
41+
}
42+
final flagsAsEnum = <DiscordApplicationFlag>[];
43+
final radixString =
44+
String.fromCharCodes(flags.toRadixString(2).runes.toList().reversed);
45+
_addFlagAsEnum(
46+
radixString,
47+
12,
48+
DiscordApplicationFlag.gatewayPresence,
49+
flagsAsEnum,
50+
);
51+
_addFlagAsEnum(
52+
radixString,
53+
13,
54+
DiscordApplicationFlag.gatewayPresenceLimited,
55+
flagsAsEnum,
56+
);
57+
_addFlagAsEnum(
58+
radixString,
59+
14,
60+
DiscordApplicationFlag.gatewayGuildMembers,
61+
flagsAsEnum,
62+
);
63+
_addFlagAsEnum(
64+
radixString,
65+
15,
66+
DiscordApplicationFlag.gatewayGuildMembersLimited,
67+
flagsAsEnum,
68+
);
69+
_addFlagAsEnum(
70+
radixString,
71+
16,
72+
DiscordApplicationFlag.verificationPendingGuildLimit,
73+
flagsAsEnum,
74+
);
75+
_addFlagAsEnum(
76+
radixString,
77+
17,
78+
DiscordApplicationFlag.embedded,
79+
flagsAsEnum,
80+
);
81+
_addFlagAsEnum(
82+
radixString,
83+
18,
84+
DiscordApplicationFlag.gatewayMessageContent,
85+
flagsAsEnum,
86+
);
87+
_addFlagAsEnum(
88+
radixString,
89+
19,
90+
DiscordApplicationFlag.gatewayMessageContentLimited,
91+
flagsAsEnum,
92+
);
93+
return flagsAsEnum;
94+
}

lib/src/models/discord_attachment.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'discord_snowflake.dart';
22

3+
// TODO: Add Documentation
34
class DiscordAttachment {
45
final DiscordSnowflake id;
56
final String filename;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import 'discord_audit_log_entry.dart';
2+
import 'discord_channel.dart';
3+
import 'discord_guild_scheduled_event.dart';
4+
import 'discord_integration.dart';
5+
import 'discord_user.dart';
6+
import 'discord_webhook.dart';
7+
8+
class DiscordAuditLog {
9+
/// list of audit log entries
10+
final List<DiscordAuditLogEntry> auditLogEntries;
11+
12+
/// list of guild scheduled events found in the audit log
13+
final List<DiscordGuildScheduledEvent> guildScheduledEvents;
14+
15+
/// list of partial integration objects
16+
final List<DiscordIntegration> integrations;
17+
18+
/// list of threads found in the audit log
19+
///
20+
/// * Threads referenced in THREAD_CREATE and THREAD_UPDATE
21+
/// events are included in the threads map, since archived
22+
/// threads might not be kept in memory by clients.
23+
final List<DiscordChannel> threads;
24+
25+
/// list of users found in the audit log
26+
final List<DiscordUser> users;
27+
28+
/// list of webhooks found in the audit log
29+
final List<DiscordWebhook> webhooks;
30+
31+
static const auditLogEntriesEntry = 'audit_log_entries';
32+
static const guildScheduledEventsEntry = 'guild_scheduled_events';
33+
static const integrationsEntry = 'integrations';
34+
static const threadsEntry = 'threads';
35+
static const usersEntry = 'users';
36+
static const webhooksEntry = 'webhooks';
37+
38+
DiscordAuditLog({
39+
required this.auditLogEntries,
40+
required this.guildScheduledEvents,
41+
required this.integrations,
42+
required this.threads,
43+
required this.users,
44+
required this.webhooks,
45+
});
46+
47+
factory DiscordAuditLog.fromJson(Map<String, dynamic> json) =>
48+
DiscordAuditLog(
49+
auditLogEntries: List<DiscordAuditLogEntry>.from(
50+
json[auditLogEntriesEntry].map(
51+
(x) => DiscordAuditLogEntry.fromJson(
52+
x as Map<String, dynamic>,
53+
),
54+
),
55+
),
56+
guildScheduledEvents: List<DiscordGuildScheduledEvent>.from(
57+
json[guildScheduledEventsEntry].map(
58+
(x) => DiscordGuildScheduledEvent.fromJson(
59+
x as Map<String, dynamic>,
60+
),
61+
),
62+
),
63+
integrations: List<DiscordIntegration>.from(
64+
json[integrationsEntry].map(
65+
(x) => DiscordIntegration.fromJson(
66+
x as Map<String, dynamic>,
67+
),
68+
),
69+
),
70+
threads: List<DiscordChannel>.from(
71+
json[threadsEntry].map(
72+
(x) => DiscordChannel.fromJson(
73+
x as Map<String, dynamic>,
74+
),
75+
),
76+
),
77+
users: List<DiscordUser>.from(
78+
json[usersEntry].map(
79+
(x) => DiscordUser.fromJson(
80+
x as Map<String, dynamic>,
81+
),
82+
),
83+
),
84+
webhooks: List<DiscordWebhook>.from(
85+
json[webhooksEntry].map(
86+
(x) => DiscordWebhook.fromJson(
87+
x as Map<String, dynamic>,
88+
),
89+
),
90+
),
91+
);
92+
}

0 commit comments

Comments
 (0)