public void Constructor_Always_PropertiesAreGiven() { var mockGuildUser = new Mock <ISocketGuildUser>(); var uut = new UserJoinedNotification(mockGuildUser.Object); uut.GuildUser.ShouldBeSameAs(mockGuildUser.Object); }
public Task HandleNotificationAsync( UserJoinedNotification notification, CancellationToken cancellationToken) { var guild = notification.GuildUser.Guild; using var logScope = UserMetricsLogMessages.BeginGuildScope(_logger, guild.Id); UserMetricsLogMessages.UserJoinedHandling(_logger); DoGuildStats(UserJoinedCounterName, guild); UserMetricsLogMessages.UserJoinedHandled(_logger); return(Task.CompletedTask); }
public async Task Handle(UserJoinedNotification notification, CancellationToken cancellationToken) { var user = await _db.Users.FindAsync(notification.GuildUser.Id); if (user is null) { user = new User(notification.GuildUser); await _db.Users.AddAsync(user, cancellationToken); } var guild = notification.GuildUser.Guild; if (guild.Id != GuildId) { _logger.LogInformation("Received a join event for {0} but did not match Id {1}", notification.GuildUser, notification); return; } await notification.GuildUser.AddRolesAsync(_joinRoles.Select(r => guild.GetRole(r))); _logger.LogInformation("Added roles {0} to user {1}", _joinRoles, notification.GuildUser); }