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

Commit d5e0e4f

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

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,10 +12,12 @@
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, IHostApplicationLifetime lifetime, IOptions<MilkyConfiguration> options, BotContext bot, EntityConvert convert) : IHostedService
1616
{
1717
private readonly ILogger<EventService> _logger = logger;
1818

19+
private readonly IHostApplicationLifetime _lifetime = lifetime;
20+
1921
private readonly bool _ignoreBotMessage = options.Value.Message.IgnoreBotMessage;
2022

2123
private readonly BotContext _bot = bot;
@@ -55,6 +57,8 @@ private void HandleOfflineEvent(BotContext bot, LgrEvents.BotOfflineEvent @event
5557
{
5658
_logger.LogHandleEventException(nameof(LgrEvents.BotOfflineEvent), e);
5759
}
60+
61+
_lifetime.StopApplication();
5862
}
5963

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

0 commit comments

Comments
 (0)