private async void HandleOnChatRequestToJoinVoiceChannel(object args) { var request = args as OnChatRequestToJoinVoiceChannel; var userChannels = await _channelPersistence.GetDiscordUserChannelsAsync(request.UserId); var lastActiveChannel = userChannels.OrderByDescending(x => x.Expiry).FirstOrDefault(); if (lastActiveChannel != null) { var joinedGameEvent = new OnJoinedGameEvent() { ChannelName = lastActiveChannel.Name, VoiceUserId = request.UserId }; await _messageBus.PublishAsync(joinedGameEvent); } }
private async void OnJoinedGameEventReceived(OnJoinedGameEvent args) { await LogsTextChannel.SendMessageAsync($"Received join game '{args.ChannelName}' for player '{args.VoiceUserId}'"); ulong channelId = 0; lock (_getChannelLock) { channelId = DefaultServer.VoiceChannels.FirstOrDefault(v => string.Equals(v.Name, args.ChannelName, StringComparison.OrdinalIgnoreCase))?.Id ?? DefaultServer.CreateVoiceChannelAsync(args.ChannelName).GetAwaiter().GetResult().Id; } var user = DefaultServer.GetUser(args.VoiceUserId); if (user != null) { await user.ModifyAsync(x => x.ChannelId = channelId); await LogsTextChannel.SendMessageAsync($"User '{user.Username}' has been moved to '{args.ChannelName}' with id '{channelId}'"); } }
public async Task JoinGameAsync(GameInfoDto game) { ChannelIdentifier channelIdentifier = _hashService.GenerateChannelIdentifier(game.Hash); var channel = new Channel() { Id = channelIdentifier.Id, Expiry = DateTimeOffset.UtcNow.AddMinutes(45).ToUnixTimeSeconds(), Name = channelIdentifier.Name }; await _channelPersistence.PersistChannelAsync(channel); await _channelPersistence.PersistUserInChannelAsync(channel.Id, game.User); var joinedGameEvent = new OnJoinedGameEvent() { ChannelName = channel.Name, VoiceUserId = game.User.Discord.UserId }; await _messageBus.PublishAsync(joinedGameEvent); }