Skip to content

Commit a919df1

Browse files
committed
callback
1 parent 19d43d9 commit a919df1

28 files changed

Lines changed: 419 additions & 113 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ApiMessage
99
public List<Embed> Embeds { get; set; } = [];
1010
public long Flags { get; set; }
1111

12-
public List<object> Components { get; set; } = [];
12+
public List<object> Components { get; set; } = [];
1313

1414
public int? Type { get; set; }
1515

src/Disc.NET.Client.SDK/Messages/Components/ActionRowButtonComponentBuilder.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
namespace Disc.NET.Client.SDK.Messages.Components
22
{
3-
public interface IMessageComponent;
3+
public interface IMessageComponent
4+
{
5+
6+
//⚠️ Outro problema(importante)
7+
//Você está usando:
8+
9+
//CustomId = "test_button"
10+
//👉 Isso vai dar problema real quando:
11+
12+
//Dois usuários clicarem
13+
14+
//Ou você tiver múltiplas mensagens
15+
16+
//💥 Porque o callback vai sobrescrever no dictionary
17+
18+
//✅ Solução recomendada(muito importante)
19+
//Use CustomId único:
20+
21+
//CustomId = $"test_button:{Guid.NewGuid()}"
22+
23+
string? CustomId { get; set; }
24+
}
425
}

src/Disc.NET.Client.SDK/Messages/Components/IMessageComponentBuilder.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Disc.NET.Commands/Attributes/SlashCommandAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6-
using Disc.NET.Shared.Enums;
6+
using Disc.NET.Commands.Enums;
77

88
namespace Disc.NET.Commands.Attributes
99
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Disc.NET.Commands.Contexts;
2+
using System.Collections.Concurrent;
3+
4+
namespace Disc.NET.Commands
5+
{
6+
internal static class ComponentCallbackRepository
7+
{
8+
private static readonly ConcurrentDictionary<string, Func<ContextBase, Task>> _callbackAsync = new();
9+
10+
public static void RegisterCallback(string customId, Func<ContextBase, Task> callback)
11+
{
12+
_callbackAsync[customId] = callback;
13+
}
14+
15+
public static void UnregisterCallback(string customId)
16+
{
17+
_callbackAsync.TryRemove(customId, out _);
18+
}
19+
20+
public static async Task<bool> InvokeCallbackAsync(string customId, ContextBase context)
21+
{
22+
if (_callbackAsync.TryGetValue(customId, out var callback))
23+
{
24+
await callback(context);
25+
return true;
26+
}
27+
28+
return false;
29+
}
30+
}
31+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Disc.NET.Commands.Contexts
55
{
6-
public class CommandContext : IContext
6+
public class CommandContext : ContextBase
77
{
88
public string Id { get; set; } = string.Empty;
99
public Author? Author { get; set; }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
namespace Disc.NET.Commands.Contexts
22
{
3-
public interface IContext;
3+
public abstract class ContextBase;
44
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Disc.NET.Commands.Contexts
55
{
6-
public class InteractionContext : IContext
6+
public class InteractionContext : ContextBase
77
{
88
public Member? Member { get; set; }
99
public string Id { get; set; } = string.Empty;

src/Disc.NET.Commands/Enums/InteractionType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Disc.NET.Shared.Enums
1+
namespace Disc.NET.Commands.Enums
22
{
33
public enum InteractionType
44
{

0 commit comments

Comments
 (0)