Skip to content

Commit

Permalink
refactor: remove dead code and organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev committed Aug 19, 2024
1 parent 5dd3b14 commit 40b04b2
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 61 deletions.
1 change: 1 addition & 0 deletions lib/api/common/permission.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum Permission implements EnhancedEnum<int> {
startEmbeddedActivities(1 << 39),
moderateMembers(1 << 40);

@override
final int value;

const Permission(this.value);
Expand Down
2 changes: 2 additions & 0 deletions lib/api/server/enums/forum_layout_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ enum ForumLayoutType implements EnhancedEnum<int> {
listView(1),
galleryView(2);

@override
final int value;

const ForumLayoutType(this.value);
}
2 changes: 2 additions & 0 deletions lib/api/server/enums/sort_order_forum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ enum SortOrderType implements EnhancedEnum<int> {
lastedActivity(0),
creationDate(1);

@override
final int value;

const SortOrderType(this.value);
}
4 changes: 2 additions & 2 deletions lib/api/server/managers/member_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ final class MemberManager {
});
}

Member? get(String? id) => _members[id];
Member? get(String? id) => _members[id != null ? Snowflake(id) : null];

Member getOrFail(String id, {String? error}) => _members.values
.firstWhere((element) => element.id == id, orElse: () => throw error ?? 'Member not found');
.firstWhere((element) => element.id.value == id, orElse: () => throw error ?? 'Member not found');


late final int maxInGuild;
Expand Down
5 changes: 0 additions & 5 deletions lib/domains/commands/contexts/global_command_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@ final class GlobalCommandContext implements CommandContext {
required this.user,
this.channel,
});

@override
Future<void> reply() {
throw UnimplementedError();
}
}
20 changes: 4 additions & 16 deletions lib/infrastructure/internals/environment/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ final class Environment implements EnvContract {
@override
Map<String, String> get list => _values;

T getRawOrFail<T>(String key) {
final value = _values.entries
T getRawOrFail<T extends dynamic>(String key) {
return _values.entries
.firstWhere((element) => element.key == key,
orElse: () => throw Exception('Environment variable $key not found'))
.value;

return switch (T) {
int => int.parse(value),
double => double.parse(value),
bool => bool.parse(value),
_ => value,
} as T;
.value as T;
}

@override
Expand All @@ -43,12 +36,7 @@ final class Environment implements EnvContract {
throw Exception('Environment variable ${variable.key} not found');
}

return switch (T) {
int => int.parse(result!.value),
double => double.parse(result!.value),
bool => bool.parse(result!.value),
_ => result?.value,
} as T;
return result?.value as T;
}

@override
Expand Down
10 changes: 5 additions & 5 deletions lib/infrastructure/internals/marshaller/serializer_bucket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ final class SerializerBucket {
: channels = ChannelSerializer(marshaller),
server = ServerSerializer(marshaller),
member = MemberSerializer(marshaller),
user = UserSerializer(marshaller),
user = UserSerializer(),
role = RoleSerializer(marshaller),
serverSubscription = ServerSubscriptionSerializer(marshaller),
serverSubscription = ServerSubscriptionSerializer(),
serverSettings = ServerSettingsSerializer(marshaller),
serversAsset = ServerAssetsSerializer(marshaller),
emojis = EmojiSerializer(marshaller),
sticker = StickerSerializer(marshaller),
sticker = StickerSerializer(),
channelPermissionOverwrite = ChannelPermissionOverwriteSerializer(marshaller),
serverMessage = ServerMessageSerializer(marshaller),
privateMessage = PrivateMessageSerializer(marshaller),
embed = EmbedSerializer(marshaller),
embed = EmbedSerializer(),
globalCommandContext = GlobalCommandContextSerializer(marshaller),
guildCommandContext = ServerCommandContextSerializer(marshaller),
poll = PollSerializer(marshaller);
poll = PollSerializer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import 'package:mineral/api/common/embed/message_embed_provider.dart';
import 'package:mineral/api/common/embed/message_embed_type.dart';
import 'package:mineral/infrastructure/commons/helper.dart';
import 'package:mineral/infrastructure/commons/utils.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/serializer.dart';

final class EmbedSerializer implements SerializerContract<MessageEmbed> {
final MarshallerContract _marshaller;

EmbedSerializer(this._marshaller);

@override
MessageEmbed serializeRemote(Map<String, dynamic> json) {
return MessageEmbed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import 'package:mineral/api/common/polls/poll_layout.dart';
import 'package:mineral/api/common/polls/poll_question.dart';
import 'package:mineral/infrastructure/commons/helper.dart';
import 'package:mineral/infrastructure/commons/utils.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/serializer.dart';

final class PollSerializer implements SerializerContract<Poll> {
final MarshallerContract _marshaller;

PollSerializer(this._marshaller);

@override
Poll serializeRemote(Map<String, dynamic> json) {
return Poll(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import 'package:mineral/api/common/premium_tier.dart';
import 'package:mineral/api/server/server_subscription.dart';
import 'package:mineral/infrastructure/commons/utils.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/serializer.dart';

final class ServerSubscriptionSerializer implements SerializerContract<ServerSubscription> {
final MarshallerContract _marshaller;

ServerSubscriptionSerializer(this._marshaller);

@override
ServerSubscription serializeRemote(Map<String, dynamic> json) => _serialize(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/common/sticker.dart';
import 'package:mineral/api/common/types/format_type.dart';
import 'package:mineral/api/common/types/sticker_type.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/serializer.dart';

final class StickerSerializer implements SerializerContract<Sticker> {
final MarshallerContract _marshaller;

StickerSerializer(this._marshaller);

@override
Sticker serializeRemote(Map<String, dynamic> json) => _serialize(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ import 'package:mineral/api/common/presence.dart';
import 'package:mineral/api/private/user.dart';
import 'package:mineral/api/private/user_assets.dart';
import 'package:mineral/infrastructure/commons/helper.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/serializer.dart';

final class UserSerializer implements SerializerContract<User> {
final MarshallerContract _marshaller;

UserSerializer(this._marshaller);

@override
User serializeRemote(Map<String, dynamic> json) => _serialize(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ final class GuildAuditLogEntryCreatePacket implements ListenablePacket {

@override
Future<void> listen(ShardMessage message, DispatchEvent dispatch) async {
final server = await marshaller.dataStore.server.getServer(message.payload['guild_id']);


// dispatch(event: Event.serverPresenceUpdate, params: [member, server, presence]);
// TODO: Implement this packet
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ final class ShardAuthenticationImpl implements ShardAuthentication {
});
}

@override
void heartbeat() {
shard.client.send(jsonEncode({
'op': 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@ final class ShardNetworkErrorImpl implements ShardNetworkError {
if (error case ShardDisconnectError(canBeReconnected: final canBeReconnected)) {
return canBeReconnected ? shard.authentication.resume() : shard.authentication.reconnect();
}

if (error case int when error == 1005) {
return shard.client.disconnect();
}
}
}

0 comments on commit 40b04b2

Please sign in to comment.