From 66c209381dc335ffb8b0db64f35d063a61e7551a Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 26 Aug 2021 22:28:33 +0800 Subject: [PATCH] Improve event log --- .../kotlin/event/events/ImageUploadEvent.kt | 12 +++++++++-- .../src/commonMain/kotlin/event/events/bot.kt | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt b/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt index eebc68cd5..f4daa21ac 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/ImageUploadEvent.kt @@ -61,12 +61,20 @@ public sealed class ImageUploadEvent : BotEvent, BotActiveEvent, AbstractEvent() override val target: Contact, override val source: ExternalResource, val image: Image - ) : ImageUploadEvent() + ) : ImageUploadEvent() { + override fun toString(): String { + return "ImageUploadEvent.Succeed(target=$target, source=$source, image=$image)" + } + } public data class Failed @MiraiInternalApi constructor( override val target: Contact, override val source: ExternalResource, val errno: Int, val message: String - ) : ImageUploadEvent() + ) : ImageUploadEvent() { + override fun toString(): String { + return "ImageUploadEvent.Failed(target=$target, source=$source, errno=$errno, message='$message')" + } + } } diff --git a/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt b/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt index 79f4b0d51..0d6d4355d 100644 --- a/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt +++ b/mirai-core-api/src/commonMain/kotlin/event/events/bot.kt @@ -50,6 +50,10 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { public override val cause: Throwable? ) : BotOfflineEvent(), BotActiveEvent, CauseAware { override val reconnect: Boolean get() = false + + override fun toString(): String { + return "BotOfflineEvent.Active(bot=$bot, cause=$cause, reconnect=$reconnect)" + } } /** @@ -61,6 +65,10 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { public val message: String, ) : BotOfflineEvent(), Packet, BotPassiveEvent { override var reconnect: Boolean = bot.configuration.autoReconnectOnForceOffline + + override fun toString(): String { + return "BotOfflineEvent.Force(bot=$bot, title='$title', message='$message', reconnect=$reconnect)" + } } /** @@ -72,6 +80,10 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { public override val cause: Throwable? ) : BotOfflineEvent(), Packet, BotPassiveEvent, CauseAware { override var reconnect: Boolean = true + + override fun toString(): String { + return "BotOfflineEvent.MsfOffline(bot=$bot, cause=$cause, reconnect=$reconnect)" + } } /** @@ -82,6 +94,10 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { public override val cause: Throwable? ) : BotOfflineEvent(), Packet, BotPassiveEvent, CauseAware { override var reconnect: Boolean = true + + override fun toString(): String { + return "BotOfflineEvent.Dropped(bot=$bot, cause=$cause, reconnect=$reconnect)" + } } /** @@ -92,6 +108,10 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() { public override val bot: Bot, override val cause: Throwable?, ) : BotOfflineEvent(), Packet, BotPassiveEvent, CauseAware { override var reconnect: Boolean = true + + override fun toString(): String { + return "BotOfflineEvent.RequireReconnect(bot=$bot, cause=$cause, reconnect=$reconnect)" + } } @MiraiExperimentalApi