public static async Task <ServerConnection> CreateAsync(Player player, ConnectionProperties properties = null) { properties ??= ConnectionProperties.Default; PlayerChannel channel = await player.GetOrCreateChannelAsync(); Logger.Debug($"Creating connection with ID of {channel.Id} for {player.User.Id}"); IUserMessage message = await channel.SendAsync(Check.NotNull(properties.ContentOverride)?properties.ContentOverride?.ToString() : $"> ⚠️ Could not find a channel at the specified frequency ({properties.Frequency})."); if (message == null) { throw new Exception("This user is unable to receive messages"); } return(new ServerConnection { Server = player.Server, RefreshRate = TimeSpan.FromSeconds(1), Type = ConnectionType.Direct, RefreshCounter = 4, BlockInput = false, UserId = player.User.Id, DeleteMessages = properties.CanDeleteMessages, Channel = channel.Source, Message = message, ChannelId = channel.Id, Frequency = properties.Frequency, LastRefreshed = DateTime.UtcNow, State = properties.State, ContentOverride = properties.ContentOverride, Inputs = properties.Inputs, Origin = properties.Origin }); }
/// <summary> /// Gets or creates the direct message channel for this <see cref="Player"/>. /// </summary> public async Task <PlayerChannel> GetOrCreateChannelAsync() { return(Channel ??= await PlayerChannel.CreateAsync(User)); }