Skip to content

Commit

Permalink
style: apply dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev committed Aug 27, 2024
1 parent 44ee968 commit cf87b64
Show file tree
Hide file tree
Showing 211 changed files with 1,668 additions and 935 deletions.
7 changes: 5 additions & 2 deletions lib/api/common/activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ final class Activity {
factory Activity.fromJson(Map<String, dynamic> json) {
return Activity(
name: json['name'],
type: ActivityType.values.firstWhere((element) => element.value == json['type'],
type: ActivityType.values.firstWhere(
(element) => element.value == json['type'],
orElse: () => ActivityType.unknown),
url: json['url'],
createdAt: DateTime.fromMillisecondsSinceEpoch(json['created_at']),
Expand All @@ -33,6 +34,8 @@ final class Activity {
emoji: Helper.createOrNull(
field: json['emoji'],
fn: () => ActivityEmoji(
name: json['name'], id: json['id'], animated: json['animated'] ?? false)));
name: json['name'],
id: json['id'],
animated: json['animated'] ?? false)));
}
}
2 changes: 1 addition & 1 deletion lib/api/common/activity_emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ final class ActivityEmoji {
required this.id,
required this.animated,
});
}
}
35 changes: 18 additions & 17 deletions lib/api/common/bot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ final class Bot {
});

factory Bot.fromJson(Map<String, dynamic> json) => Bot._(
id: Snowflake(json['user']['id']),
discriminator: json['user']['discriminator'],
version: json['v'],
username: json['user']['username'],
hasEnabledMfa: json['user']['mfa_enabled'],
globalName: json['user']['global_name'],
flags: json['user']['flags'],
avatar: json['user']['avatar'],
sessionType: json['session_type'],
privateChannels: json['private_channels'],
presences: json['presences'],
guildIds: List<String>.from(json['guilds'].map((element) => element['id'])),
application: PartialApplication(
id: json['application']['id'],
flags: json['application']['flags'],
),
);
id: Snowflake(json['user']['id']),
discriminator: json['user']['discriminator'],
version: json['v'],
username: json['user']['username'],
hasEnabledMfa: json['user']['mfa_enabled'],
globalName: json['user']['global_name'],
flags: json['user']['flags'],
avatar: json['user']['avatar'],
sessionType: json['session_type'],
privateChannels: json['private_channels'],
presences: json['presences'],
guildIds:
List<String>.from(json['guilds'].map((element) => element['id'])),
application: PartialApplication(
id: json['application']['id'],
flags: json['application']['flags'],
),
);
}
16 changes: 12 additions & 4 deletions lib/api/common/channel_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ final class ChannelMethods {
);
}

Future<void> setDefaultAutoArchiveDuration(int defaultAutoArchiveDuration, String? reason) async {
Future<void> setDefaultAutoArchiveDuration(
int defaultAutoArchiveDuration, String? reason) async {
await dataStoreChannel.updateChannel(
id: id,
reason: reason,
payload: {'default_auto_archive_duration': defaultAutoArchiveDuration},
);
}

Future<void> setDefaultThreadRateLimitPerUser(int value, String? reason) async {
Future<void> setDefaultThreadRateLimitPerUser(
int value, String? reason) async {
await dataStoreChannel.updateChannel(
id: id,
reason: reason,
Expand Down Expand Up @@ -110,8 +112,14 @@ final class ChannelMethods {
);
}

Future<void> send({ Snowflake? guildId, String? content, List<MessageEmbed>? embeds, Poll? poll, List<MessageComponent>? components}) async {
await dataStoreChannel.createMessage(guildId, id, content, embeds, poll, components);
Future<void> send(
{Snowflake? guildId,
String? content,
List<MessageEmbed>? embeds,
Poll? poll,
List<MessageComponent>? components}) async {
await dataStoreChannel.createMessage(
guildId, id, content, embeds, poll, components);
}

Future<void> delete(String? reason) async {
Expand Down
92 changes: 48 additions & 44 deletions lib/api/common/channel_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,55 +84,59 @@ final class ChannelProperties {
final permissionOverwrites = await Helper.createOrNullAsync(
field: element['permission_overwrites'],
fn: () async => Future.wait(
List.from(element['permission_overwrites'])
.map((json) async =>
marshaller.serializers.channelPermissionOverwrite.serialize(json))
.toList(),
));
List.from(element['permission_overwrites'])
.map((json) async => marshaller
.serializers.channelPermissionOverwrite
.serialize(json))
.toList(),
));

final recipients = await Helper.createOrNullAsync(
field: element['recipients'],
fn: () async => Future.wait(
List.from(element['recipients'])
.map((json) async => marshaller.serializers.user.serialize(json))
.toList(),
));
List.from(element['recipients'])
.map((json) async =>
marshaller.serializers.user.serialize(json))
.toList(),
));

return ChannelProperties(
id: Snowflake(element['id']),
type: findInEnum(ChannelType.values, element['type']),
name: element['name'],
description: element['description'],
serverId: Helper.createOrNull(
field: element['server_id'], fn: () => Snowflake(element['server_id'])),
categoryId: Helper.createOrNull(
field: element['parent_id'], fn: () => Snowflake(element['parent_id'])),
position: element['position'],
nsfw: element['nsfw'] ?? false,
lastMessageId: Helper.createOrNull(
field: element['last_message_id'], fn: () => Snowflake(element['last_message_id'])),
bitrate: element['bitrate'],
userLimit: element['user_limit'],
rateLimitPerUser: element['rate_limit_per_user'],
recipients: recipients ?? [],
icon: element['icon'],
ownerId: element['owner_id'],
applicationId: element['application_id'],
lastPinTimestamp: element['last_pin_timestamp'],
rtcRegion: element['rtc_region'],
videoQualityMode: element['video_quality_mode'],
messageCount: element['message_count'],
memberCount: element['member_count'],
defaultAutoArchiveDuration: element['default_auto_archive_duration'],
permissions: permissionOverwrites,
flags: element['flags'],
totalMessageSent: element['total_message_sent'],
available: element['available'],
appliedTags: element['applied_tags'] ?? [],
defaultReactions: element['default_reactions'],
defaultSortOrder: element['default_sort_order'],
defaultForumLayout: element['default_forum_layout'],
threads: ThreadsManager({})
);
id: Snowflake(element['id']),
type: findInEnum(ChannelType.values, element['type']),
name: element['name'],
description: element['description'],
serverId: Helper.createOrNull(
field: element['server_id'],
fn: () => Snowflake(element['server_id'])),
categoryId: Helper.createOrNull(
field: element['parent_id'],
fn: () => Snowflake(element['parent_id'])),
position: element['position'],
nsfw: element['nsfw'] ?? false,
lastMessageId: Helper.createOrNull(
field: element['last_message_id'],
fn: () => Snowflake(element['last_message_id'])),
bitrate: element['bitrate'],
userLimit: element['user_limit'],
rateLimitPerUser: element['rate_limit_per_user'],
recipients: recipients ?? [],
icon: element['icon'],
ownerId: element['owner_id'],
applicationId: element['application_id'],
lastPinTimestamp: element['last_pin_timestamp'],
rtcRegion: element['rtc_region'],
videoQualityMode: element['video_quality_mode'],
messageCount: element['message_count'],
memberCount: element['member_count'],
defaultAutoArchiveDuration: element['default_auto_archive_duration'],
permissions: permissionOverwrites,
flags: element['flags'],
totalMessageSent: element['total_message_sent'],
available: element['available'],
appliedTags: element['applied_tags'] ?? [],
defaultReactions: element['default_reactions'],
defaultSortOrder: element['default_sort_order'],
defaultForumLayout: element['default_forum_layout'],
threads: ThreadsManager({}));
}
}
4 changes: 2 additions & 2 deletions lib/api/common/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ final class Color {
final String _color;
Color(this._color);

int toInt () => int.parse(_color.replaceAll('#', ''), radix: 16);
int toInt() => int.parse(_color.replaceAll('#', ''), radix: 16);

@override
String toString () => _color;
String toString() => _color;

factory Color.of(int color) {
final hex = color.toRadixString(16);
Expand Down
18 changes: 11 additions & 7 deletions lib/api/common/commands/builder/command_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ final class CommandBuilder {
final firstArg = fn.toString().split('(')[1].split(')')[0].split(' ')[0];

if (!firstArg.contains('CommandContext')) {
throw Exception('The first argument of the handler function must be CommandContext');
throw Exception(
'The first argument of the handler function must be CommandContext');
}

_handle = fn;
return this;
}

CommandBuilder addSubCommand(SubCommandBuilder Function(SubCommandBuilder) command) {
CommandBuilder addSubCommand(
SubCommandBuilder Function(SubCommandBuilder) command) {
final builder = SubCommandBuilder();
command(builder);
_subCommands.add(builder);
return this;
}

CommandBuilder createGroup(CommandGroupBuilder Function(CommandGroupBuilder) group) {
CommandBuilder createGroup(
CommandGroupBuilder Function(CommandGroupBuilder) group) {
final builder = CommandGroupBuilder();
group(builder);
_groups.add(builder);
Expand All @@ -68,14 +71,15 @@ final class CommandBuilder {
return {
'name': _name,
'description': _description,
if (_subCommands.isEmpty && _groups.isEmpty) 'type': CommandType.subCommand.value,
if (_subCommands.isEmpty && _groups.isEmpty)
'type': CommandType.subCommand.value,
'options': options,
};
}

List<(String, Function handler)> reduceHandlers() {
if (_subCommands.isEmpty && _groups.isEmpty) {
return [('$_name', _handle!)];
return [('$_name', _handle!)];
}

final List<(String, Function handler)> handlers = [];
Expand All @@ -86,11 +90,11 @@ final class CommandBuilder {

for (final group in _groups) {
for (final subCommand in group.commands) {
handlers.add(('$_name.${group.name}.${subCommand.name}', subCommand.handle!));
handlers.add(
('$_name.${group.name}.${subCommand.name}', subCommand.handle!));
}
}

return handlers;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ final class CommandDeclarationBuilder implements CommandBuilder {

for (final subCommand in subCommands) {
if (subCommand.handle case null) {
throw MissingMethodException('Command "$commandName.${subCommand.name}" has no handler');
throw MissingMethodException(
'Command "$commandName.${subCommand.name}" has no handler');
}

handlers.add(('$name.${subCommand.name}', subCommand.handle!));
Expand Down
Loading

0 comments on commit cf87b64

Please sign in to comment.