public async Task <Unit> Handle(ApplyJoinRolesCommand request, CancellationToken cancellationToken) { foreach (var guildId in _discordGuildService.GetAllCurrentGuildIds()) { var joinRoles = await _applicationDbContext.JoinRoles .Where(r => r.GuildId == guildId) .ToListAsync(cancellationToken); foreach (var guildMember in _discordGuildMemberService.GetGuildMembers(guildId)) { if (guildMember.IsPending) { continue; } foreach (var r in joinRoles) { try { await _discordGuildRoleService.GrantRoleAsync(guildId, r.RoleId, guildMember.Id, "join role"); } catch (Exception ex) { _logger.LogError(ex, "couldn't grant role to user"); } } } } return(Unit.Value); }
public async Task <Unit> Handle(PopulateBoosterServiceCommand request, CancellationToken cancellationToken) { var availableSlots = await _context.XPAvailableSlots .AsNoTracking() .ToArrayAsync(cancellationToken); var queuedBoosters = await _context.XPQueuedBoosters .AsNoTracking() .ToArrayAsync(cancellationToken); var activeBoosters = await _context.XPActiveBoosters .AsNoTracking() .ToArrayAsync(cancellationToken); _boosterService.AvailableSlots = availableSlots .GroupBy(s => s.GuildId) .ToDictionary(s => s.Key, s => s.ToList()); _boosterService.QueuedBoosters = queuedBoosters .GroupBy(b => b.GuildId) .ToDictionary( k => k.Key, v => new Queue <QueuedBooster>(v.OrderBy(b => b.Position).ToList())); _boosterService.ActiveBoosters = activeBoosters .GroupBy(b => b.GuildId) .ToDictionary(k => k.Key, v => v.ToList()); foreach (var key in _guildService.GetAllCurrentGuildIds()) { _boosterService.AvailableSlots.TryAdd(key, new List <AvailableSlot>()); _boosterService.QueuedBoosters.TryAdd(key, new Queue <QueuedBooster>()); _boosterService.ActiveBoosters.TryAdd(key, new List <ActiveBooster>()); } return(Unit.Value); }
public async Task OtherCollectionsShouldNotBeEmpty_WhenGuildExists(bool withSlot) { ulong guildId = 6; ulong channelId = 7; var slot = new AvailableSlot { Id = 69, GuildId = guildId, ChannelId = channelId }; _dbContext.ConfigureMockDbSet(x => x.XPActiveBoosters); _dbContext.ConfigureMockDbSet(x => x.XPQueuedBoosters); if (withSlot) { _dbContext.ConfigureMockDbSet(x => x.XPAvailableSlots, slot); } else { _dbContext.ConfigureMockDbSet(x => x.XPAvailableSlots); } _discordGuildService.GetAllCurrentGuildIds().Returns(new[] { guildId }); await _appFixture.SendAsync(new PopulateBoosterServiceCommand()); _activeBoosters.Should().NotBeNull(); _queuedBoosters.Should().NotBeNull(); _availableSlots.Should().NotBeNull(); if (withSlot) { _availableSlots[guildId].First().GuildId.Should().Be(guildId); _availableSlots[guildId].First().ChannelId.Should().Be(channelId); } else { _availableSlots[guildId].Should().NotBeNull().And.BeEmpty(); } _activeBoosters[guildId].Should().NotBeNull().And.BeEmpty(); _queuedBoosters[guildId].Should().NotBeNull().And.BeEmpty(); }
public async Task Execute(IJobExecutionContext context) { foreach (var guildId in _guildService.GetAllCurrentGuildIds()) { try { await _mediator.Send(new UnRestrictExpiredChannelsCommand { GuildId = guildId }); } catch (Exception exception) { _logger.LogError(exception, "An error occurred during a un-restricting channels job"); } } }