Browse Source

Add different events for different interaction types

pull/1923/head
quin lynch 3 years ago
parent
commit
7efb6eede4
4 changed files with 100 additions and 2 deletions
  1. +50
    -1
      src/Discord.Net.WebSocket/BaseSocketClient.Events.cs
  2. +26
    -1
      src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
  3. +5
    -0
      src/Discord.Net.WebSocket/DiscordShardedClient.cs
  4. +19
    -0
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 50
- 1
src/Discord.Net.WebSocket/BaseSocketClient.Events.cs View File

@@ -457,7 +457,7 @@ namespace Discord.WebSocket

//Interactions
/// <summary>
/// Fired when an Interaction is created.
/// Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands.
/// </summary>
/// <remarks>
/// <para>
@@ -475,6 +475,55 @@ namespace Discord.WebSocket
}
internal readonly AsyncEvent<Func<SocketInteraction, Task>> _interactionCreatedEvent = new AsyncEvent<Func<SocketInteraction, Task>>();

/// <summary>
/// Fired when a button is clicked and its interaction is received.
/// </summary>
public event Func<SocketMessageComponent, Task> ButtonExecuted
{
add => _buttonExecuted.Add(value);
remove => _buttonExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketMessageComponent, Task>> _buttonExecuted = new AsyncEvent<Func<SocketMessageComponent, Task>>();

/// <summary>
/// Fired when a select menu is used and its interaction is received.
/// </summary>
public event Func<SocketMessageComponent, Task> SelectMenuExecuted
{
add => _selectMenuExecuted.Add(value);
remove => _selectMenuExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketMessageComponent, Task>> _selectMenuExecuted = new AsyncEvent<Func<SocketMessageComponent, Task>>();
/// <summary>
/// Fired when a slash command is used and its interaction is received.
/// </summary>
public event Func<SocketSlashCommand, Task> SlashCommandExecuted
{
add => _slashCommandExecuted.Add(value);
remove => _slashCommandExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketSlashCommand, Task>> _slashCommandExecuted = new AsyncEvent<Func<SocketSlashCommand, Task>>();

/// <summary>
/// Fired when a user command is used and its interaction is received.
/// </summary>
public event Func<SocketUserCommand, Task> UserCommandExecuted
{
add => _userCommandExecuted.Add(value);
remove => _userCommandExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketUserCommand, Task>> _userCommandExecuted = new AsyncEvent<Func<SocketUserCommand, Task>>();

/// <summary>
/// Fired when a message command is used and its interaction is received.
/// </summary>
public event Func<SocketMessageCommand, Task> MessageCommandExecuted
{
add => _messageCommandExecuted.Add(value);
remove => _messageCommandExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketMessageCommand, Task>> _messageCommandExecuted = new AsyncEvent<Func<SocketMessageCommand, Task>>();

/// <summary>
/// Fired when a guild application command is created.
///</summary>


+ 26
- 1
src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml View File

@@ -709,7 +709,7 @@
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.InteractionCreated">
<summary>
Fired when an Interaction is created.
Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands.
</summary>
<remarks>
<para>
@@ -721,6 +721,31 @@
</para>
</remarks>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.ButtonExecuted">
<summary>
Fired when a button is clicked and its interaction is received.
</summary>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.SelectMenuExecuted">
<summary>
Fired when a select menu is used and its interaction is received.
</summary>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.SlashCommandExecuted">
<summary>
Fired when a slash command is used and its interaction is received.
</summary>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.UserCommandExecuted">
<summary>
Fired when a user command is used and its interaction is received.
</summary>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.MessageCommandExecuted">
<summary>
Fired when a message command is used and its interaction is received.
</summary>
</member>
<member name="E:Discord.WebSocket.BaseSocketClient.ApplicationCommandCreated">
<summary>
Fired when a guild application command is created.


+ 5
- 0
src/Discord.Net.WebSocket/DiscordShardedClient.cs View File

@@ -456,6 +456,11 @@ namespace Discord.WebSocket
client.InviteDeleted += (channel, invite) => _inviteDeletedEvent.InvokeAsync(channel, invite);

client.InteractionCreated += (interaction) => _interactionCreatedEvent.InvokeAsync(interaction);
client.ButtonExecuted += (arg) => _buttonExecuted.InvokeAsync(arg);
client.SelectMenuExecuted += (arg) => _selectMenuExecuted.InvokeAsync(arg);
client.SlashCommandExecuted += (arg) => _slashCommandExecuted.InvokeAsync(arg);
client.UserCommandExecuted += (arg) => _userCommandExecuted.InvokeAsync(arg);
client.MessageCommandExecuted += (arg) => _messageCommandExecuted.InvokeAsync(arg);

client.ThreadUpdated += (thread1, thread2) => _threadUpdated.InvokeAsync(thread1, thread2);
client.ThreadCreated += (thread) => _threadCreated.InvokeAsync(thread);


+ 19
- 0
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -2090,6 +2090,25 @@ namespace Discord.WebSocket
await interaction.DeferAsync().ConfigureAwait(false);

await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false);

switch (interaction)
{
case SocketSlashCommand slashCommand:
await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false);
break;
case SocketMessageComponent messageComponent:
if(messageComponent.Data.Type == ComponentType.SelectMenu)
await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false);
if(messageComponent.Data.Type == ComponentType.Button)
await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false);
break;
case SocketUserCommand userCommand:
await TimedInvokeAsync(_userCommandExecuted, nameof(UserCommandExecuted), userCommand).ConfigureAwait(false);
break;
case SocketMessageCommand messageCommand:
await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false);
break;
}
}
else
{


Loading…
Cancel
Save