Skip to content

Commit

Permalink
Remove party searches when a bot dies
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian committed Aug 9, 2024
1 parent fb60f15 commit 674d44f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions GuildWarsPartySearch/Services/BotStatus/BotStatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using GuildWarsPartySearch.Server.Models.Endpoints;
using GuildWarsPartySearch.Server.Services.BotStatus.Models;
using GuildWarsPartySearch.Server.Services.Database;
using GuildWarsPartySearch.Server.Services.Feed;
using System.Collections.Concurrent;
using System.Core.Extensions;
using System.Extensions;
Expand All @@ -13,14 +14,17 @@ public sealed class BotStatusService : IBotStatusService
{
private readonly ConcurrentDictionary<string, Bot> connectedBots = [];

private readonly ILiveFeedService liveFeedService;
private readonly IBotHistoryDatabase database;
private readonly ILogger<BotStatusService> logger;

public BotStatusService(
ILiveFeedService liveFeedService,
IBotHistoryDatabase botHistoryDatabase,
IHostApplicationLifetime lifetime,
ILogger<BotStatusService> logger)
{
this.liveFeedService = liveFeedService.ThrowIfNull();
this.database = botHistoryDatabase.ThrowIfNull();
this.logger = logger.ThrowIfNull();

Expand Down Expand Up @@ -182,6 +186,12 @@ public async Task<bool> RemoveBot(string botId, CancellationToken cancellationTo
}

await this.database.RecordBotActivity(bot, Database.Models.BotActivity.ActivityType.Disconnect, cancellationToken);
await this.liveFeedService.PushUpdate(new Server.Models.PartySearch
{
District = bot.District,
Map = bot.Map,
PartySearchEntries = []
}, cancellationToken);
scopedLogger.LogDebug("Removed bot");
return true;
}
Expand Down

0 comments on commit 674d44f

Please sign in to comment.