private void AddFriendOrGuestMenuComponents(List <ExpectedChannelMessage> messages) { if (messages.Count != 2) { throw new ArgumentException("Unexpected amount of messages received.", nameof(messages)); } // Friend or Guest menu foreach (var(customId, label) in Constants.FriendOrGuestMenu.GetOptions()) { messages[0].Components.Add(new ButtonComponent(customId, 0, label, InteractionButtonStyle.Primary)); } // Game interest menu DiscordAccess.EnsureDisplayNamesAreSet(_gameRoleProvider.Games); var games = _gameRoleProvider.Games // Only those games with the GameInterestRoleId set can be used here .Where(m => m.GameInterestRoleId != null) .OrderBy(m => m.DisplayName) .Take(25) .ToDictionary(m => m.GameInterestRoleId.ToString() !, m => m.DisplayName ?? "<UNKNOWN>"); messages[1].Components.Add(new SelectMenuComponent(Constants.GameInterestMenu.CustomId, 0, "Select game interests ...", games, true)); }
private void AddGamesRolesMenuComponents(List <ExpectedChannelMessage> messages) { if (messages.Count != 1) { throw new ArgumentException("Unexpected amount of messages received.", nameof(messages)); } DiscordAccess.EnsureDisplayNamesAreSet(_gameRoleProvider.Games); var games = _gameRoleProvider.Games // Only those games with the flag IncludeInGamesMenu enabled can be used here .Where(m => m.IncludeInGamesMenu) .OrderBy(m => m.DisplayName) .Take(125) .ToDictionary(m => m.PrimaryGameDiscordRoleId.ToString(), m => m.DisplayName ?? "<UNKNOWN>"); var customIds = Enumerable.Range(0, (int)Math.Ceiling(games.Count / 25m)) .Select(_ => Guid.NewGuid().ToString("D")) .ToArray(); _gameRoleProvider.GamesRolesCustomIds = customIds; byte actionRowNumber = 0; foreach (var customId in customIds) { messages[0].Components.Add(new SelectMenuComponent(customId, actionRowNumber, "Select games ...", games.Skip(actionRowNumber * 25) .Take(25) .ToDictionary(m => m.Key, m => m.Value), true)); actionRowNumber++; } }
private async Task CreateMessagesInChannel(DiscordChannelId channelID, ExpectedChannelMessages messages) { if (!_channelSemaphores.TryGetValue(channelID, out var semaphore)) { semaphore = new SemaphoreSlim(1, 1); _channelSemaphores.Add(channelID, semaphore); } var channelLocationAndName = DiscordAccess.GetChannelLocationAndName(channelID); try { _logger.LogInformation("{Channel} - Waiting for channel-edit-semaphore ...", channelLocationAndName); await semaphore.WaitAsync(); _logger.LogInformation("{Channel} - Got channel-edit-semaphore.", channelLocationAndName); _logger.LogInformation("{Channel} - Deleting existing bot messages in the channel ...", channelLocationAndName); await DiscordAccess.DeleteBotMessagesInChannel(channelID); _logger.LogInformation("{Channel} - Creating new messages in the channel ...", channelLocationAndName); await DiscordAccess.CreateBotMessagesInChannelAsync(channelID, messages.ToArray()); } catch (Exception e) { _logger.LogError(e, "{Channel} - Failed to create all messages for channel.", channelLocationAndName); } finally { _logger.LogInformation("{Channel} - Releasing channel-edit-semaphore ...", channelLocationAndName); semaphore.Release(); _logger.LogInformation("{Channel} - Channel-edit-semaphore released.", channelLocationAndName); } }