Discord-Net-Labs / Discord.Net-Labs

An experimental fork of Discord.Net that implements the newest discord features for testing and development to eventually get merged into Discord.Net
https://labs.discordnet.dev
MIT License
156 stars 42 forks source link

Add callback to rest context #383

Closed quinchs closed 2 years ago

quinchs commented 2 years ago

Summary

This PR adds the InteractionResponseCallback property to RestInteractionContext and introduces the interface IRestInteractionContext. This allows the process of writing the respond function much simpler, ex:


async Task WriteCallback(string payload)
{
    await response.OutputStream.WriteAsync(payload);
}

var context = new RestInteractionContext(client, interaction, WriteCallback);
await interactionService.ExecuteCommandAsync(context, services);
response.StatusCode = 200;
response.Close();

If no callback is passed into the ctor of RestInteractionContext then the default global callback is used, the callbacks are mutually exclusive.

quinchs commented 2 years ago

cc: @Cenngo