Skip to content

Commit 86c936e

Browse files
committed
interaction responding with callback
1 parent 4b35968 commit 86c936e

20 files changed

Lines changed: 76 additions & 54 deletions

File tree

src/Disc.NET.Client.SDK/Client.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ public async Task InteractionRespondingAsync(string interactionId, string intera
5353
await PostAsync(responseJson, url, cancellation);
5454
}
5555

56+
public async Task InteractionRespondingAsync(string interactionId, string interactionToken, ApiMessage message,
57+
bool isEphemeral = false, CancellationToken cancellation = default)
58+
{
59+
var teste = _serializer.Serialize(new Teste()
60+
{
61+
Type = message.Type!.Value,
62+
Data = message
63+
});
64+
var url = $"https://discord.com/api/v10/interactions/{interactionId}/{interactionToken}/callback";
65+
66+
await PostAsync(teste, url, cancellation);
67+
}
68+
69+
5670
private async Task SendMessageAsync(ApiMessage message, string channelId, CancellationToken cancellation = default)
5771
{
5872
var messageJson = _serializer.Serialize(message);
@@ -74,6 +88,6 @@ private async Task PostAsync(string json, string uri, CancellationToken cancella
7488
var error = await response.Content.ReadAsStringAsync(cancellation).ConfigureAwait(false);
7589
throw new DiscNetClientSdkException(error, response.StatusCode);
7690
}
77-
}
91+
}
7892

7993
}

src/Disc.NET.Client.SDK/Interfaces/IClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public interface IClient
1414

1515
Task InteractionRespondingAsync(string interactionId, string interactionToken, string responseJson, CancellationToken cancellation = default);
1616

17+
Task InteractionRespondingAsync(string interactionId, string interactionToken, ApiMessage message, bool isEphemeral = false, CancellationToken cancellation = default);
18+
1719
}

src/Disc.NET.Client.SDK/Messages/ApiMessage.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ public class ApiMessage
1616
public ApiMessage? MessageReference { get; set; }
1717

1818
// https://discord.com/developers/docs/resources/message#message-object
19+
}
20+
21+
class Teste
22+
{
23+
public int Type { get; set; }
24+
public ApiMessage Data { get; set; }
1925
}

src/Disc.NET.Client.SDK/Messages/Components/Buttons/ButtonComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ButtonComponent : IMessageComponent
1111

1212
// emoji
1313

14-
public string? CustomId { get; set; }
14+
public required string CustomId { get; set; }
1515
public string? SkuId { get; set; }
1616
public string? Url { get; set; }
1717

src/Disc.NET.Commands/Contexts/InteractionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class InteractionContext : ContextBase
1212
public Channel? Channel { get; set; }
1313
public int Type { get; set; }
1414
public int Context { get; set; }
15-
15+
public string Token { get; set; } = string.Empty;
1616
public InteractionData? Data { get; set; }
1717
public InteractionResponse Response { get; set; }
1818
}

src/Disc.NET.Commands/IPrefixCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace Disc.NET.Commands
44
{
55
public interface IPrefixCommand : ICommand<CommandContext>
66
{
7-
Task RunAsync(CommandContext context, List<string> @params);
7+
Task RunAsync(CommandContext context, CancellationToken cancellationToken = default);
88
}
99
}

src/Disc.NET.Commands/ISlashCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace Disc.NET.Commands
44
{
55
public interface ISlashCommand : ICommand<InteractionContext>
66
{
7-
Task RunAsync(InteractionContext context, SlashCommandParamsResult @params);
8-
List<SlashCommandOptions> BuildOptions() => [];
9-
7+
Task RunAsync(InteractionContext context, CancellationToken cancellation = default);
108
}
119
}

src/Disc.NET.Commands/Message.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ namespace Disc.NET.Commands
1010
{
1111
public class Message : ApiMessage
1212
{
13+
1314
public List<MessageFlag>? MessageFlags { get; set; }
1415

1516
public List<IActionRowBuilder> ActionRows { get; set; } = [];
16-
17+
1718
public ApiMessage Build()
1819
{
1920
Flags = MessageFlags?.Aggregate(0L, (current, flag) => current | (long)flag) ?? 0L;
2021
Components = MountActionRows();
22+
Type ??= 4;
2123
return this;
2224
}
2325

src/Disc.NET.Commands/MessageBuilders/ActionRowButtonBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Disc.NET.Commands.MessageBuilders
66
{
7+
8+
// Think if it`s possible create a generic action row builder where component can be button, selects etc...
79
public sealed class ActionRowButtonBuilder : ActiorRowBuilderBase, IActionRowBuilder
810
{
911
public string? Id { get; }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
using Disc.NET.Client.SDK;
22
using Disc.NET.Client.SDK.Interfaces;
3+
using Disc.NET.Shared.Serializer;
34

45
namespace Disc.NET.Commands.Responses
56
{
67
public class InteractionResponse
78
{
89
private readonly IClient _client = ClientSingleton.GetInstance();
10+
private readonly DiscNetSerializer _serializer = DiscNetSerializer.GetInstance();
911
public string ChannelId { get; set; } = string.Empty;
12+
public string InteractionId { get; set; } = string.Empty;
13+
public string InteractionToken { get; set; } = string.Empty;
1014

1115
public async Task SendMessageAsync(Message message, CancellationToken cancellation = default)
1216
{
1317
await _client.SendMessageAsync(ChannelId, message.Build(), cancellation);
1418
}
19+
20+
public async Task InteractionRespondingAsync(Message message, bool ephemeral = false, CancellationToken cancellation = default)
21+
{
22+
await _client.InteractionRespondingAsync
23+
(
24+
InteractionId,
25+
InteractionToken,
26+
message.Build(),
27+
ephemeral,
28+
cancellation
29+
);
30+
}
1531
}
1632
}

0 commit comments

Comments
 (0)