Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove string casts for Snowflake.parse #559

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/src/gateway/gateway.dart
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class Gateway extends GatewayManager with EventParser {
}

GuildAuditLogCreateEvent parseGuildAuditLogCreate(Map<String, Object?> raw) {
final guildId = Snowflake.parse(raw['guild_id'] as String);
final guildId = Snowflake.parse(raw['guild_id']!);

return GuildAuditLogCreateEvent(
gateway: this,
Expand Down Expand Up @@ -583,7 +583,7 @@ class Gateway extends GatewayManager with EventParser {
}

GuildStickersUpdateEvent parseGuildStickersUpdate(Map<String, Object?> raw) {
final guildId = Snowflake.parse(raw['guild_id'] as String);
final guildId = Snowflake.parse(raw['guild_id']!);

return GuildStickersUpdateEvent(
gateway: this,
Expand All @@ -600,7 +600,7 @@ class Gateway extends GatewayManager with EventParser {
}

GuildMemberAddEvent parseGuildMemberAdd(Map<String, Object?> raw) {
final guildId = Snowflake.parse(raw['guild_id'] as String);
final guildId = Snowflake.parse(raw['guild_id']!);

return GuildMemberAddEvent(
gateway: this,
Expand Down Expand Up @@ -853,9 +853,9 @@ class Gateway extends GatewayManager with EventParser {

return MessageReactionRemoveEvent(
gateway: this,
userId: Snowflake.parse(raw['user_id'] as String),
channelId: Snowflake.parse(raw['channel_id'] as String),
messageId: Snowflake.parse(raw['message_id'] as String),
userId: Snowflake.parse(raw['user_id']!),
channelId: Snowflake.parse(raw['channel_id']!),
messageId: Snowflake.parse(raw['message_id']!),
guildId: guildId,
emoji: client.guilds[Snowflake.zero].emojis.parse(raw['emoji'] as Map<String, Object?>),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/managers/audit_log_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AuditLogManager extends ReadOnlyManager<AuditLogEntry> {
@override
AuditLogEntry parse(Map<String, Object?> raw) {
return AuditLogEntry(
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
manager: this,
targetId: maybeParse(raw['target_id'], Snowflake.parse),
changes: maybeParseMany(raw['changes'], parseAuditLogChange),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/managers/emoji_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EmojiManager extends Manager<Emoji> {
}

return GuildEmoji(
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
manager: this,
user: maybeParse(raw['user'], client.users.parse),
isAnimated: raw['animated'] as bool?,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/managers/guild_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GuildManager extends Manager<Guild> {

@override
Guild parse(Map<String, Object?> raw) {
final id = Snowflake.parse(raw['id'] as String);
final id = Snowflake.parse(raw['id']!);

return Guild(
id: id,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/http/managers/invite_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class InviteManager {
Invite parse(Map<String, Object?> raw) {
final guild = maybeParse(
raw['guild'],
(Map<String, Object?> raw) => PartialGuild(id: Snowflake.parse(raw['id'] as String), manager: client.guilds),
(Map<String, Object?> raw) => PartialGuild(id: Snowflake.parse(raw['id']!), manager: client.guilds),
);

return Invite(
code: raw['code'] as String,
guild: guild,
channel: PartialChannel(id: Snowflake.parse((raw['channel'] as Map<String, Object?>)['id'] as String), manager: client.channels),
channel: PartialChannel(id: Snowflake.parse((raw['channel'] as Map<String, Object?>)['id']!), manager: client.channels),
inviter: maybeParse(raw['inviter'], client.users.parse),
targetType: maybeParse(raw['target_type'], TargetType.parse),
targetUser: maybeParse(raw['target_user'], client.users.parse),
targetApplication: maybeParse(
raw['target_application'],
(Map<String, Object?> raw) => PartialApplication(id: Snowflake.parse(raw['id'] as String), manager: client.applications),
(Map<String, Object?> raw) => PartialApplication(id: Snowflake.parse(raw['id']!), manager: client.applications),
),
approximatePresenceCount: raw['approximate_presence_count'] as int?,
approximateMemberCount: raw['approximate_member_count'] as int?,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/managers/message_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MessageManager extends Manager<Message> {
activity: maybeParse(raw['activity'], parseMessageActivity),
application: maybeParse(
raw['application'],
(Map<String, Object?> raw) => PartialApplication(id: Snowflake.parse(raw['id'] as String), manager: client.applications),
(Map<String, Object?> raw) => PartialApplication(id: Snowflake.parse(raw['id']!), manager: client.applications),
),
applicationId: maybeParse(raw['application_id'], Snowflake.parse),
reference: maybeParse(raw['message_reference'], parseMessageReference),
Expand Down
22 changes: 11 additions & 11 deletions lib/src/http/managers/sticker_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ class GuildStickerManager extends Manager<GuildSticker> {
GuildSticker parse(Map<String, Object?> raw) {
return GuildSticker(
manager: this,
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
name: raw['name'] as String,
description: raw['description'] as String?,
tags: raw['tags'] as String,
type: StickerType.parse(raw['type'] as int),
formatType: StickerFormatType.parse(raw['format_type'] as int),
available: raw['available'] as bool? ?? false,
guildId: Snowflake.parse(raw['guild_id'] as String),
user: ((raw['user'] ?? {}) as Map)['id'] != null ? client.users[Snowflake.parse((raw['user'] as Map)['id'] as String)] : null,
guildId: Snowflake.parse(raw['guild_id']!),
user: ((raw['user'] ?? {}) as Map)['id'] != null ? client.users[Snowflake.parse((raw['user'] as Map<String, Object?>)['id']!)] : null,
sortValue: raw['sort_value'] as int?,
);
}
Expand Down Expand Up @@ -149,38 +149,38 @@ class GlobalStickerManager extends ReadOnlyManager<GlobalSticker> {

StickerItem parseStickerItem(Map<String, Object?> raw) {
return StickerItem(
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
name: raw['name'] as String,
formatType: StickerFormatType.parse(raw['format_type'] as int),
);
}

StickerPack parseStickerPack(Map<String, Object?> raw) {
return StickerPack(
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
manager: this,
stickers: (raw['stickers'] as List).map((e) => parse(e as Map<String, Object?>)).toList(),
name: raw['name'] as String,
skuId: Snowflake.parse(raw['sku_id'] as String),
coverStickerId: raw['cover_sticker_id'] != null ? Snowflake.parse(raw['cover_sticker_id'] as String) : null,
skuId: Snowflake.parse(raw['sku_id']!),
coverStickerId: raw['cover_sticker_id'] != null ? Snowflake.parse(raw['cover_sticker_id']!) : null,
description: raw['description'] as String,
bannerAssetId: raw['banner_asset_id'] != null ? Snowflake.parse(raw['banner_asset_id'] as String) : null,
bannerAssetId: raw['banner_asset_id'] != null ? Snowflake.parse(raw['banner_asset_id']!) : null,
);
}

@override
GlobalSticker parse(Map<String, Object?> raw) {
return GlobalSticker(
manager: this,
id: Snowflake.parse(raw['id'] as String),
packId: Snowflake.parse(raw['pack_id'] as String),
id: Snowflake.parse(raw['id']!),
packId: Snowflake.parse(raw['pack_id']!),
name: raw['name'] as String,
description: raw['description'] as String?,
tags: raw['tags'] as String,
type: StickerType.parse(raw['type'] as int),
formatType: StickerFormatType.parse(raw['format_type'] as int),
available: raw['available'] as bool? ?? false,
user: ((raw['user'] ?? {}) as Map)['id'] != null ? client.users[Snowflake.parse((raw['user'] as Map)['id'] as String)] : null,
user: ((raw['user'] ?? {}) as Map)['id'] != null ? client.users[Snowflake.parse((raw['user'] as Map<String, Object?>)['id']!)] : null,
sortValue: raw['sort_value'] as int?,
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/http/managers/user_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UserManager extends ReadOnlyManager<User> {
integrations: maybeParseMany(
raw['integrations'],
(Map<String, Object?> raw) => PartialIntegration(
id: Snowflake.parse(raw['id'] as String),
id: Snowflake.parse(raw['id']!),
// TODO: Can we know what guild the integrations are from?
manager: client.guilds[Snowflake.zero].integrations,
),
Expand Down Expand Up @@ -138,7 +138,7 @@ class UserManager extends ReadOnlyManager<User> {
final response = await client.httpHandler.executeSafe(request);
return parseMany(
response.jsonBody as List,
(Map<String, Object?> raw) => PartialGuild(id: Snowflake.parse(raw['id'] as String), manager: client.guilds),
(Map<String, Object?> raw) => PartialGuild(id: Snowflake.parse(raw['id']!), manager: client.guilds),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/managers/voice_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VoiceManager {
manager: this,
guildId: guildId,
channelId: maybeParse(raw['channel_id'], Snowflake.parse),
userId: Snowflake.parse(raw['user_id'] as String),
userId: Snowflake.parse(raw['user_id']!),
member: maybeParse(raw['member'], client.guilds[guildId ?? Snowflake.zero].members.parse),
sessionId: raw['session_id'] as String,
isServerDeafened: raw['deaf'] as bool,
Expand Down
Loading