internal async Task SendAsync(DiscordFrameType type, object payload) { if (this.Pipe == null || !this.Pipe.IsConnected) { return; } var result = new DiscordFrame() .WithType(type) .WithPayload(payload) .GetBytes(); await this.RequireConnectedAsync().ConfigureAwait(false); await this.Pipe.WriteAsync(result, 0, result.Length).ConfigureAwait(false); }
internal async Task SendCommandAsync(DiscordFrameType type, DiscordCommand command, DiscordCommandCallback callback = null) { if (this.Pipe == null || !this.Pipe.IsConnected) { return; } var result = new DiscordFrame() .WithType(type) .WithPayload(command) .GetBytes(); if (callback != null) { this.Callbacks.AddOrUpdate(command.Nonce, callback, (key, old) => callback); } await this.RequireConnectedAsync().ConfigureAwait(false); await this.Pipe.WriteAsync(result, 0, result.Length).ConfigureAwait(false); }
public DiscordFrame WithType(DiscordFrameType type) { this.Type = type; return(this); }