Skip to content

Commit

Permalink
feat(api): refactor message packet
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev committed Jan 6, 2024
1 parent 59bf703 commit bc8fb88
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/domains/data/packets/message_create_packet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ final class MessageCreatePacket implements ListenablePacket {
PacketType get event => PacketType.messageCreate;

final MemoryStorageContract storage;

const MessageCreatePacket(this.storage);

@override
void listen(Map<String, dynamic> payload) {
final { 'message': ShardMessage message, 'dispatch': Function(InternalEventParams) dispatch } = payload;
final {'message': ShardMessage message, 'dispatch': Function(InternalEventParams) dispatch} =
payload;

final messageInstance = switch(message.payload['guild_id']) {
String() => ServerMessage.fromJson(
server: storage.servers[message.payload['guild_id']]!,
json: message.payload
),
_ => throw 'Not implemented',
};
switch (message.payload['guild_id']) {
case String():
sendServerMessage(dispatch, message.payload);
default:
throw 'Not implemented';
}
}

dispatch(InternalEventParams('ServerMessageEvent', [messageInstance]));
void sendServerMessage(Function(InternalEventParams) dispatch, Map<String, dynamic> json) {
final message = ServerMessage.fromJson(server: storage.servers[json['guild_id']]!, json: json);
dispatch(InternalEventParams('ServerMessageEvent', [message]));
}
}

0 comments on commit bc8fb88

Please sign in to comment.