async Task IRoleRemover.RemoveBasementRolesAsync() { var basementRoleId = (DiscordRoleId)_dynamicConfiguration.DiscordMapping["BasementRoleId"]; // If there are any users from the last check, free them this round. foreach (var discordUserID in _usersToFreeFromBasement) { if (!_discordAccess.CanManageRolesForUser(discordUserID)) { continue; } var(success, roleName) = await _discordAccess.TryRevokeNonMemberRole(discordUserID, basementRoleId); if (success) { await _discordAccess.LogToDiscord($"Automatically removed role `{roleName}` from <@{discordUserID}>."); continue; } var leaderMention = _discordAccess.GetRoleMention("Leader"); await _discordAccess.LogToDiscord($"{leaderMention}: failed to remove role `{roleName}` from <@{discordUserID}>"); } // Gather users that should be freed next round. _usersToFreeFromBasement.Clear(); var usersInBasement = _discordAccess.GetUsersIdsInRole(basementRoleId); if (usersInBasement.Any()) { _usersToFreeFromBasement.AddRange(usersInBasement); } }
public async Task SetGameInterestRoleAsync(IRole game, IRole?interestRole = null) { if (!_userStore.TryGetUser((DiscordUserId)Context.User.Id, out var user)) { await RespondAsync("Couldn't find you in the user store. Game was not edited."); return; } // Update _discordAccess.EnsureDisplayNamesAreSet(_gameRoleProvider.Games); var(success, message, updatedGame) = await _gameRoleProvider.UpdateGameAsync(user !.InternalUserId, (DiscordRoleId)game.Id, g => g.GameInterestRoleId = interestRole == null ?null : (DiscordRoleId)interestRole.Id); if (success && updatedGame != null) { // When the game was edited successfully, log the add var logMessage = $"{Context.User.Username} changed the property **{nameof(AvailableGame.GameInterestRoleId)}** of the game " + $"**{updatedGame.DisplayName}** ({game.Mention}) to **{(interestRole == null ? "<NULL>" : interestRole.Mention)}**."; _logger.LogInformation(logMessage); await _discordAccess.LogToDiscord(logMessage); // If the game can be used as "interest role", send an additional message. if (updatedGame.GameInterestRoleId != null) { var leaderMention = _discordAccess.GetRoleMention(Constants.RoleNames.LeaderRoleName); var gameInterestNotification = $"{leaderMention} The game '{updatedGame.DisplayName}' can now be used as \"game interest\" in the infos and roles channel."; await _discordAccess.LogToDiscord(gameInterestNotification); } } await RespondAsync(message); }