Skip to content

Commit

Permalink
feat(api): implemented logger
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev committed Jan 6, 2024
1 parent bc8fb88 commit ce9fbf7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/application/kernel/kernel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:mineral/application/http/header.dart';
import 'package:mineral/application/http/http_client.dart';
import 'package:mineral/application/http/http_client_config.dart';
import 'package:mineral/application/logger/logger.dart';
import 'package:mineral/domains/data/data_listener.dart';
import 'package:mineral/domains/data/memory/memory_storage.dart';
import 'package:mineral/domains/data/packets/guild_create_packet.dart';
Expand All @@ -17,13 +18,16 @@ final class Kernel implements KernelContract {
@override
final ShardingConfigContract config;

@override
final LoggerContract logger;

@override
final HttpClientContract httpClient;

@override
final DataListenerContract dataListener;

Kernel({required this.httpClient, required this.config, required this.dataListener}) {
Kernel({required this.logger, required this.httpClient, required this.config, required this.dataListener}) {
httpClient.config.headers.addAll([
Header.authorization('Bot ${config.token}'),
]);
Expand Down Expand Up @@ -60,12 +64,14 @@ final class Kernel implements KernelContract {

final shardConfig = ShardingConfig(token: token, intent: intent, version: shardVersion);

final LoggerContract logger = Logger();

final MemoryStorageContract storage = MemoryStorage();
final DataListenerContract dataListener = DataListener()
..listenPacketClass(ReadyPacket(storage))
..listenPacketClass(ReadyPacket(logger, storage))
..listenPacketClass(MessageCreatePacket(storage))
..listenPacketClass(GuildCreatePacket(storage));

return Kernel(httpClient: http, config: shardConfig, dataListener: dataListener);
return Kernel(logger: logger, httpClient: http, config: shardConfig, dataListener: dataListener);
}
}
8 changes: 7 additions & 1 deletion lib/domains/data/packets/ready_packet.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:convert';

import 'package:mineral/api/common/bot.dart';
import 'package:mineral/application/logger/logger.dart';
import 'package:mineral/domains/data/internal_event_params.dart';
import 'package:mineral/domains/data/memory/memory_storage.dart';
import 'package:mineral/domains/data/types/listenable_packet.dart';
Expand All @@ -9,15 +12,18 @@ final class ReadyPacket implements ListenablePacket {
@override
PacketType get event => PacketType.ready;

final LoggerContract logger;
final MemoryStorageContract storage;

const ReadyPacket(this.storage);
const ReadyPacket(this.logger, this.storage);

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

final client = Bot.fromJson(message.payload);

logger.trace(jsonEncode(message.payload));
dispatch(InternalEventParams(event.toString(), [client]));
}
}
3 changes: 3 additions & 0 deletions lib/domains/shared/types/kernel_contract.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:mineral/application/http/http_client.dart';
import 'package:mineral/application/logger/logger.dart';
import 'package:mineral/domains/data/data_listener.dart';
import 'package:mineral/domains/wss/shard.dart';
import 'package:mineral/domains/wss/sharding_config.dart';
Expand All @@ -8,6 +9,8 @@ abstract interface class KernelContract {

ShardingConfigContract get config;

LoggerContract get logger;

HttpClientContract get httpClient;

DataListenerContract get dataListener;
Expand Down

0 comments on commit ce9fbf7

Please sign in to comment.