diff --git a/CHANGELOG.md b/CHANGELOG.md index cc6d31120..644fba131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 4.0.0-dev.5 + +- Add event parameters +- Prepare integration with `mineral_cli` + # 4.0.0-dev.4 - Add server methods - Add server events diff --git a/lib/src/api/common/image_asset.dart b/lib/src/api/common/image_asset.dart index e19e287ac..9eca634ad 100644 --- a/lib/src/api/common/image_asset.dart +++ b/lib/src/api/common/image_asset.dart @@ -38,7 +38,7 @@ final class ImageAsset { return '$url/${fragments.join('/')}'; } - factory ImageAsset.makeAsset(File file, { String? name }) { + factory ImageAsset.makeAsset(File file, {String? name}) { if (!file.existsSync()) { throw ArgumentError('File does not exist'); } diff --git a/lib/src/api/server/server_assets.dart b/lib/src/api/server/server_assets.dart index b29117dad..822b70ff0 100644 --- a/lib/src/api/server/server_assets.dart +++ b/lib/src/api/server/server_assets.dart @@ -29,24 +29,28 @@ final class ServerAsset { required this.discoverySplash, }); - Future setIcon(File icon, {String? reason}) async { final iconAsset = ImageAsset.makeAsset(icon); - await _serverPart.updateServer(serverId, {'icon': iconAsset.makeUrl()}, reason); + await _serverPart.updateServer( + serverId, {'icon': iconAsset.makeUrl()}, reason); } Future setBanner(File banner, {String? reason}) async { final bannerAsset = ImageAsset.makeAsset(banner); - await _serverPart.updateServer(serverId, {'banner': bannerAsset.makeUrl()}, reason); + await _serverPart.updateServer( + serverId, {'banner': bannerAsset.makeUrl()}, reason); } Future setSplash(File splash, {String? reason}) async { final splashAsset = ImageAsset.makeAsset(splash); - await _serverPart.updateServer(serverId, {'splash': splashAsset.makeUrl()}, reason); + await _serverPart.updateServer( + serverId, {'splash': splashAsset.makeUrl()}, reason); } - Future setDiscoverySplash(File discoverySplash, {String? reason}) async { + Future setDiscoverySplash(File discoverySplash, + {String? reason}) async { final discoverySplashAsset = ImageAsset.makeAsset(discoverySplash); - await _serverPart.updateServer(serverId, {'discovery_splash': discoverySplashAsset.makeUrl()}, reason); + await _serverPart.updateServer( + serverId, {'discovery_splash': discoverySplashAsset.makeUrl()}, reason); } } diff --git a/lib/src/domains/events/event.dart b/lib/src/domains/events/event.dart index 287fbb568..691a73b8b 100644 --- a/lib/src/domains/events/event.dart +++ b/lib/src/domains/events/event.dart @@ -51,45 +51,67 @@ enum Event implements EnhancedEnum, EventType { serverDelete(ServerDeleteEvent, ['Server? server']), serverMessageCreate(ServerMessageCreateEvent, ['ServerMessage message']), serverChannelCreate(ServerChannelCreateEvent, ['ServerChannel channel']), - serverChannelUpdate(ServerChannelUpdateEvent, ['ServerChannel before', 'ServerChannel after']), + serverChannelUpdate(ServerChannelUpdateEvent, + ['ServerChannel before', 'ServerChannel after']), serverChannelDelete(ServerChannelDeleteEvent, ['ServerChannel? channel']), - serverChannelPinsUpdate(ServerChannelPinsUpdateEvent, ['ServerChannel channel']), - privateChannelPinsUpdate(PrivateChannelPinsUpdateEvent, ['PrivateChannel channel']), + serverChannelPinsUpdate( + ServerChannelPinsUpdateEvent, ['ServerChannel channel']), + privateChannelPinsUpdate( + PrivateChannelPinsUpdateEvent, ['PrivateChannel channel']), serverMemberAdd(ServerMemberAddEvent, ['Member member', 'Server server']), serverMemberRemove(ServerMemberRemoveEvent, ['Member member']), serverBanAdd(ServerBanAddEvent, ['ServerBan ban']), serverBanRemove(ServerBanRemoveEvent, ['ServerBan ban']), - serverMemberUpdate( - ServerMemberUpdateEvent, ['ServerMember? before', 'Member after', 'Server server']), - serverPresenceUpdate(ServerPresenceUpdateEvent, ['Member member', 'Server server', 'Presence presence']), - serverEmojisUpdate(ServerEmojisUpdateEvent, ['EmojiManager emojisManager', 'Server server']), - serverStickersUpdate(ServerStickersUpdateEvent, ['StickerManager stickerManager', 'Server server']), + serverMemberUpdate(ServerMemberUpdateEvent, + ['ServerMember? before', 'Member after', 'Server server']), + serverPresenceUpdate(ServerPresenceUpdateEvent, + ['Member member', 'Server server', 'Presence presence']), + serverEmojisUpdate( + ServerEmojisUpdateEvent, ['EmojiManager emojisManager', 'Server server']), + serverStickersUpdate(ServerStickersUpdateEvent, + ['StickerManager stickerManager', 'Server server']), serverRoleCreate(ServerRolesCreateEvent, ['Role role', 'Server server']), - serverRoleUpdate(ServerRolesUpdateEvent, ['Role before', 'Role after', 'Server server']), + serverRoleUpdate( + ServerRolesUpdateEvent, ['Role before', 'Role after', 'Server server']), serverRoleDelete(ServerRolesDeleteEvent, ['Role? role', 'Server server']), serverButtonClick(ServerButtonClickEvent, ['ServerButtonContext ctx']), serverDialogSubmit(ServerDialogSubmitEvent, ['ServerDialogContext ctx']), - serverChannelSelect(ServerChannelSelectEvent, ['ServerSelectContext ctx', 'List channels']), - serverRoleSelect(ServerRoleSelectEvent, ['ServerSelectContext ctx', 'List roles']), - serverMemberSelect(ServerMemberSelectEvent, ['ServerSelectContext ctx', 'List members']), - serverTextSelect(ServerTextSelectEvent, ['ServerSelectContext ctx', 'List values']), - serverThreadCreate(ServerThreadCreateEvent, ['ThreadChannel channel', 'Server server']), - serverThreadUpdate(ServerThreadUpdateEvent, ['ThreadChannel before', 'ThreadChannel after', 'Server server']), - serverThreadDelete(ServerThreadDeleteEvent, ['ThreadChannel thread', 'Server server']), - serverThreadMemberUpdate(ServerThreadMemberUpdateEvent, ['ThreadChannel thread', 'Server server', 'Member member']), - serverThreadMemberAdd(ServerThreadMemberAddEvent, ['ThreadChannel thread', 'Server server', 'Member member']), - serverThreadMemberRemove(ServerThreadMemberRemoveEvent, ['ThreadChannel thread', 'Server server', 'Member member']), - serverThreadListSync(ServerThreadListSyncEvent, ['List threads', 'Server server']), + serverChannelSelect(ServerChannelSelectEvent, + ['ServerSelectContext ctx', 'List channels']), + serverRoleSelect( + ServerRoleSelectEvent, ['ServerSelectContext ctx', 'List roles']), + serverMemberSelect(ServerMemberSelectEvent, + ['ServerSelectContext ctx', 'List members']), + serverTextSelect(ServerTextSelectEvent, + ['ServerSelectContext ctx', 'List values']), + serverThreadCreate( + ServerThreadCreateEvent, ['ThreadChannel channel', 'Server server']), + serverThreadUpdate(ServerThreadUpdateEvent, + ['ThreadChannel before', 'ThreadChannel after', 'Server server']), + serverThreadDelete( + ServerThreadDeleteEvent, ['ThreadChannel thread', 'Server server']), + serverThreadMemberUpdate(ServerThreadMemberUpdateEvent, + ['ThreadChannel thread', 'Server server', 'Member member']), + serverThreadMemberAdd(ServerThreadMemberAddEvent, + ['ThreadChannel thread', 'Server server', 'Member member']), + serverThreadMemberRemove(ServerThreadMemberRemoveEvent, + ['ThreadChannel thread', 'Server server', 'Member member']), + serverThreadListSync(ServerThreadListSyncEvent, + ['List threads', 'Server server']), // private privateMessageCreate(PrivateMessageCreateEvent, ['PrivateMessage message']), privateChannelCreate(PrivateChannelCreateEvent, ['PrivateChannel channel']), - privateChannelUpdate(PrivateChannelUpdateEvent, ['PrivateChannel before', 'PrivateChannel after']), + privateChannelUpdate(PrivateChannelUpdateEvent, + ['PrivateChannel before', 'PrivateChannel after']), privateChannelDelete(PrivateChannelDeleteEvent, ['PrivateChannel? channel']), privateButtonClick(PrivateButtonClickEvent, ['PrivateButtonContext ctx']), privateDialogSubmit(PrivateDialogSubmitEvent, ['PrivateDialogContext ctx']), - privateUserSelect(PrivateUserSelectEvent, ['PrivateSelectContext ctx', 'List users']), - privateTextSelect(PrivateTextSelectEvent, ['PrivateSelectContext ctx', 'List values']),; + privateUserSelect( + PrivateUserSelectEvent, ['PrivateSelectContext ctx', 'List users']), + privateTextSelect(PrivateTextSelectEvent, + ['PrivateSelectContext ctx', 'List values']), + ; @override final Type value; diff --git a/lib/src/infrastructure/commons/file.dart b/lib/src/infrastructure/commons/file.dart index ee5f520f3..f7dc9b6e6 100644 --- a/lib/src/infrastructure/commons/file.dart +++ b/lib/src/infrastructure/commons/file.dart @@ -50,7 +50,10 @@ extension JsonFile on File { } extension YamlWriter on Map { - void writeAsYaml({required StringBuffer buffer, required List payload, int spacing = 2}) { + void writeAsYaml( + {required StringBuffer buffer, + required List payload, + int spacing = 2}) { for (final entry in payload) { final spaces = ' ' * spacing; diff --git a/lib/src/infrastructure/internals/packets/listeners/guild_update_packet.dart b/lib/src/infrastructure/internals/packets/listeners/guild_update_packet.dart index c472480fc..a88f0caf1 100644 --- a/lib/src/infrastructure/internals/packets/listeners/guild_update_packet.dart +++ b/lib/src/infrastructure/internals/packets/listeners/guild_update_packet.dart @@ -22,7 +22,8 @@ final class GuildUpdatePacket implements ListenablePacket { ? await marshaller.serializers.server.serialize(rawServer) : null; - final rawAfter = await marshaller.serializers.server.normalize(message.payload); + final rawAfter = + await marshaller.serializers.server.normalize(message.payload); final after = await marshaller.serializers.server.serialize(rawAfter); dispatch(event: Event.serverUpdate, params: [before, after]); diff --git a/lib/src/infrastructure/services/logger/logger.dart b/lib/src/infrastructure/services/logger/logger.dart index 511aaa4ae..071c0441d 100644 --- a/lib/src/infrastructure/services/logger/logger.dart +++ b/lib/src/infrastructure/services/logger/logger.dart @@ -31,18 +31,22 @@ final class Logger implements LoggerContract { final level = _env.get(AppEnv.logLevel); final dartEnv = _env.get(AppEnv.dartEnv); - final bool logLevel = LogLevel.values.map((level) => level.name).contains(level.toUpperCase()); + final bool logLevel = LogLevel.values + .map((level) => level.name) + .contains(level.toUpperCase()); if (!logLevel) { throw Exception( 'Invalid LOG_LEVEL environment variable, please include in ${LogLevel.values.map((level) => level.name.toLowerCase())}'); } - logging.Logger.root.level = - LogLevel.values.firstWhere((element) => element.name == level.toUpperCase()).value; + logging.Logger.root.level = LogLevel.values + .firstWhere((element) => element.name == level.toUpperCase()) + .value; logging.Logger.root.onRecord.listen((record) { final time = '[${DateFormat.Hms().format(record.time)}]'; - List makeMessage(String messageType, Color messageColor, List message) { + List makeMessage( + String messageType, Color messageColor, List message) { return [ SetStyles(Style.foreground(Color.brightBlack)), Print(time), @@ -57,13 +61,18 @@ final class Logger implements LoggerContract { } final message = switch (record.level) { - logging.Level.FINEST => makeMessage('trace', Color.white, - [SetStyles(Style.foreground(Color.brightBlack)), Print(record.message)]), - logging.Level.SHOUT => makeMessage('fatal', Color.brightRed, [Print(record.message)]), - logging.Level.SEVERE => makeMessage('error', Color.red, [Print(record.message)]), - logging.Level.WARNING => makeMessage('warn', Color.yellow, [Print(record.message)]), - logging.Level.INFO => - makeMessage('info', Color.fromRGB(140, 169, 238), [Print(record.message)]), + logging.Level.FINEST => makeMessage('trace', Color.white, [ + SetStyles(Style.foreground(Color.brightBlack)), + Print(record.message) + ]), + logging.Level.SHOUT => + makeMessage('fatal', Color.brightRed, [Print(record.message)]), + logging.Level.SEVERE => + makeMessage('error', Color.red, [Print(record.message)]), + logging.Level.WARNING => + makeMessage('warn', Color.yellow, [Print(record.message)]), + logging.Level.INFO => makeMessage( + 'info', Color.fromRGB(140, 169, 238), [Print(record.message)]), _ => makeMessage('unknown', Color.blue, [Print(record.message)]), }; diff --git a/pubspec.yaml b/pubspec.yaml index dbe6ce1c3..8c471acd6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mineral description: Mineral is a Discord framework for designing discord bots in Dart. -version: 4.0.0-dev.4 +version: 4.0.0-dev.5 repository: https://github.com/mineral-dart/core # homepage: https://www.example.com