Skip to content
This repository was archived by the owner on May 27, 2026. It is now read-only.

Commit 9e29056

Browse files
committed
feat: stop application when bot offline
1 parent c4f13fa commit 9e29056

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Lagrange.Milky/Event/EventService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
namespace Lagrange.Milky.Event;
1414

15-
public class EventService(ILogger<EventService> logger, IOptions<MilkyConfiguration> options, BotContext bot, EntityConvert convert) : IHostedService
15+
public class EventService(ILogger<EventService> logger, IOptions<MilkyConfiguration> options, IHost host, BotContext bot, EntityConvert convert) : IHostedService
1616
{
1717
private readonly ILogger<EventService> _logger = logger;
1818

1919
private readonly bool _ignoreBotMessage = options.Value.Message.IgnoreBotMessage;
2020

21+
private readonly IHost _host = host;
22+
2123
private readonly BotContext _bot = bot;
2224
private readonly EntityConvert _convert = convert;
2325

@@ -55,6 +57,8 @@ private void HandleOfflineEvent(BotContext bot, LgrEvents.BotOfflineEvent @event
5557
{
5658
_logger.LogHandleEventException(nameof(LgrEvents.BotOfflineEvent), e);
5759
}
60+
61+
_host.StopAsync().ContinueWith(_ => Environment.Exit(1));
5862
}
5963

6064
private void HandleMessageEvent(BotContext bot, LgrEvents.BotMessageEvent @event)

0 commit comments

Comments
 (0)