Skip to content

Commit 91a45af

Browse files
committed
reply message
1 parent f7ef36f commit 91a45af

9 files changed

Lines changed: 70 additions & 48 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ private static string GetApiMessageJson(ApiMessage apiMessage, DiscNetSerializer
8989
apiMessage.Content,
9090
apiMessage.Embeds,
9191
apiMessage.Flags,
92-
Components = apiMessage.MountComponents()
92+
apiMessage.Type,
93+
apiMessage.MessageReference,
94+
Components = apiMessage.MountComponents()
9395
};
9496

9597
return serializer.Serialize(message);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Disc.NET.Client.SDK.Messages;
99

1010
public class ApiMessage
1111
{
12+
public string? MessageId { get; set; }
1213
public string Content { get; set; } = string.Empty;
1314
public List<Embed> Embeds { get; set; } = [];
1415

@@ -20,6 +21,10 @@ public class ApiMessage
2021
[JsonIgnore]
2122
public List<IMessageComponentBuilder> Components { get; set; } = [];
2223

24+
public int? Type { get; set; }
25+
26+
public ApiMessage? MessageReference { get; set; }
27+
2328
public List<object> MountComponents()
2429
{
2530
var results = new List<object>();
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
using Disc.NET.Client.SDK;
2-
using Disc.NET.Client.SDK.Interfaces;
3-
using Disc.NET.Client.SDK.Messages;
4-
using Disc.NET.Commands.Contexts.Models;
5-
using Disc.NET.Shared.Configurations;
1+
using Disc.NET.Commands.Contexts.Models;
2+
using Disc.NET.Commands.Responses;
63

74
namespace Disc.NET.Commands.Contexts
85
{
96
public class CommandContext : IContext
107
{
11-
public string Id { get; set; } = string.Empty;
8+
public string Id { get; set; } = string.Empty;
129
public Author? Author { get; set; }
1310

14-
public int ChannelType { get; set; }
11+
public int ChannelType { get; set; }
1512
public string ChannelId { get; set; } = string.Empty;
1613
public string GuildId { get; set; } = string.Empty;
1714
public string? Content { get; set; } = string.Empty;
@@ -22,15 +19,5 @@ public class CommandContext : IContext
2219

2320
public CommandResponse Response { get; set; }
2421
}
25-
26-
public class CommandResponse(AppConfiguration appConfiguration)
27-
{
28-
private readonly IClient _client = ClientSingleton.GetInstance(appConfiguration);
29-
public string ChannelId { get; set; } = string.Empty;
30-
31-
public async Task SendMessageAsync(ApiMessage message, CancellationToken cancellation = default)
32-
{
33-
await _client.SendMessageAsync(ChannelId, message, cancellation);
34-
}
35-
}
3622
}
23+
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Disc.NET.Commands.Contexts
1+
namespace Disc.NET.Commands.Contexts
82
{
9-
public interface IContext
10-
{
11-
12-
}
3+
public interface IContext;
134
}
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using Disc.NET.Client.SDK;
2-
using Disc.NET.Client.SDK.Interfaces;
3-
using Disc.NET.Client.SDK.Messages;
4-
using Disc.NET.Commands.Contexts.Models;
5-
using Disc.NET.Shared.Configurations;
1+
using Disc.NET.Commands.Contexts.Models;
2+
using Disc.NET.Commands.Responses;
63

74
namespace Disc.NET.Commands.Contexts
85
{
@@ -18,15 +15,4 @@ public class InteractionContext : IContext
1815
public InteractionResponse Response { get; set; }
1916
}
2017

21-
public class InteractionResponse(AppConfiguration appConfiguration)
22-
{
23-
private readonly IClient _client = ClientSingleton.GetInstance(appConfiguration);
24-
public string ChannelId { get; set; } = string.Empty;
25-
26-
public async Task SendMessageAsync(ApiMessage message, CancellationToken cancellation = default)
27-
{
28-
await _client.SendMessageAsync(ChannelId, message, cancellation);
29-
}
30-
}
31-
3218
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Disc.NET.Client.SDK;
2+
using Disc.NET.Client.SDK.Interfaces;
3+
using Disc.NET.Client.SDK.Messages;
4+
using Disc.NET.Shared.Configurations;
5+
6+
namespace Disc.NET.Commands.Responses
7+
{
8+
public class CommandResponse(AppConfiguration appConfiguration)
9+
{
10+
private readonly IClient _client = ClientSingleton.GetInstance(appConfiguration);
11+
public string ChannelId { get; set; } = string.Empty;
12+
public string MessageId { get; set; } = string.Empty;
13+
14+
15+
public async Task SendMessageAsync(ApiMessage message, CancellationToken cancellation = default)
16+
{
17+
await _client.SendMessageAsync(ChannelId, message, cancellation);
18+
}
19+
20+
public async Task ReplyAsync(ApiMessage message, CancellationToken cancellation = default)
21+
{
22+
23+
message.Type = 19;
24+
message.MessageReference = new ApiMessage()
25+
{
26+
MessageId = MessageId
27+
};
28+
await _client.SendMessageAsync(ChannelId, message, cancellation);
29+
}
30+
}
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Disc.NET.Client.SDK;
2+
using Disc.NET.Client.SDK.Interfaces;
3+
using Disc.NET.Client.SDK.Messages;
4+
using Disc.NET.Shared.Configurations;
5+
6+
namespace Disc.NET.Commands.Responses
7+
{
8+
public class InteractionResponse(AppConfiguration appConfiguration)
9+
{
10+
private readonly IClient _client = ClientSingleton.GetInstance(appConfiguration);
11+
public string ChannelId { get; set; } = string.Empty;
12+
13+
public async Task SendMessageAsync(ApiMessage message, CancellationToken cancellation = default)
14+
{
15+
await _client.SendMessageAsync(ChannelId, message, cancellation);
16+
}
17+
}
18+
}

src/Disc.NET/Handlers/HandlerCommandBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text.Json;
88
using Autofac;
99
using Autofac.Core;
10+
using Disc.NET.Commands.Responses;
1011
using Disc.NET.Configuration;
1112

1213
namespace Disc.NET.Handlers
@@ -68,7 +69,8 @@ protected override CommandContext BuildCommandContext(JsonDocument contextJson,
6869
context.Type = contextJson.GetIntProperty("type") ?? 0;
6970
context.Response = new CommandResponse(appConfiguration)
7071
{
71-
ChannelId = context.ChannelId
72+
ChannelId = context.ChannelId,
73+
MessageId = context.Id
7274
};
7375
return context;
7476
}

tests/GenericBot/PrefixPrefixCommandTest.cs

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

1212
public async Task RunAsync(CommandContext context, List<string> @params)
1313
{
14-
await context.Response.SendMessageAsync(new ApiMessage()
14+
await context.Response.ReplyAsync(new ApiMessage()
1515
{
1616
Content = "Olá Mundo",
1717
Embeds =

0 commit comments

Comments
 (0)