Browse Source

Update channel on SocketInteraction

pull/1923/head
quin lynch 4 years ago
parent
commit
e17794e58e
4 changed files with 21 additions and 33 deletions
  1. +4
    -3
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  2. +4
    -4
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
  3. +4
    -4
      src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
  4. +9
    -22
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs

+ 4
- 3
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

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


var data = (payload as JToken).ToObject<API.Gateway.InteractionCreated>(_serializer); var data = (payload as JToken).ToObject<API.Gateway.InteractionCreated>(_serializer);


SocketChannel channel;
SocketChannel channel = null;
if(data.ChannelId.IsSpecified) if(data.ChannelId.IsSpecified)
{ {
channel = State.GetChannel(data.ChannelId.Value); channel = State.GetChannel(data.ChannelId.Value);
@@ -1795,7 +1795,8 @@ namespace Discord.WebSocket
{ {
channel = State.GetDMChannel(data.User.Value.Id); channel = State.GetDMChannel(data.User.Value.Id);
} }
else

if(channel == null)
{ {
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false); await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
return; return;
@@ -1808,7 +1809,7 @@ namespace Discord.WebSocket
return; return;
} }


var interaction = SocketInteraction.Create(this, data);
var interaction = SocketInteraction.Create(this, data, channel as ISocketMessageChannel);


if (this.AlwaysAcknowledgeInteractions) if (this.AlwaysAcknowledgeInteractions)
await interaction.AcknowledgeAsync().ConfigureAwait(false); await interaction.AcknowledgeAsync().ConfigureAwait(false);


+ 4
- 4
src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs View File

@@ -25,8 +25,8 @@ namespace Discord.WebSocket
/// </summary> /// </summary>
public SocketMessage Message { get; private set; } public SocketMessage Message { get; private set; }


internal SocketMessageComponent(DiscordSocketClient client, Model model)
: base(client, model.Id)
internal SocketMessageComponent(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model.Id, channel)
{ {
var dataModel = model.Data.IsSpecified ? var dataModel = model.Data.IsSpecified ?
(model.Data.Value as JToken).ToObject<DataModel>() (model.Data.Value as JToken).ToObject<DataModel>()
@@ -37,9 +37,9 @@ namespace Discord.WebSocket


} }


new internal static SocketMessageComponent Create(DiscordSocketClient client, Model model)
new internal static SocketMessageComponent Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{ {
var entity = new SocketMessageComponent(client, model);
var entity = new SocketMessageComponent(client, model, channel);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }


+ 4
- 4
src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs View File

@@ -18,8 +18,8 @@ namespace Discord.WebSocket
/// </summary> /// </summary>
new public SocketSlashCommandData Data { get; private set; } new public SocketSlashCommandData Data { get; private set; }


internal SocketSlashCommand(DiscordSocketClient client, Model model)
: base(client, model.Id)
internal SocketSlashCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model.Id, channel)
{ {
var dataModel = model.Data.IsSpecified ? var dataModel = model.Data.IsSpecified ?
(model.Data.Value as JToken).ToObject<DataModel>() (model.Data.Value as JToken).ToObject<DataModel>()
@@ -28,9 +28,9 @@ namespace Discord.WebSocket
Data = SocketSlashCommandData.Create(client, dataModel, model.Id); Data = SocketSlashCommandData.Create(client, dataModel, model.Id);
} }


new internal static SocketInteraction Create(DiscordSocketClient client, Model model)
new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{ {
var entity = new SocketSlashCommand(client, model);
var entity = new SocketSlashCommand(client, model, channel);
entity.Update(model); entity.Update(model);
return entity; return entity;
} }


+ 9
- 22
src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs View File

@@ -54,17 +54,18 @@ namespace Discord.WebSocket
private ulong? GuildId { get; set; } private ulong? GuildId { get; set; }
private ulong? ChannelId { get; set; } private ulong? ChannelId { get; set; }


internal SocketInteraction(DiscordSocketClient client, ulong id)
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel)
: base(client, id) : base(client, id)
{ {
this.Channel = channel;
} }


internal static SocketInteraction Create(DiscordSocketClient client, Model model)
internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{ {
if (model.Type == InteractionType.ApplicationCommand) if (model.Type == InteractionType.ApplicationCommand)
return SocketSlashCommand.Create(client, model);
return SocketSlashCommand.Create(client, model, channel);
if (model.Type == InteractionType.MessageComponent) if (model.Type == InteractionType.MessageComponent)
return SocketMessageComponent.Create(client, model);
return SocketMessageComponent.Create(client, model, channel);
else else
return null; return null;
} }
@@ -92,18 +93,6 @@ namespace Discord.WebSocket
this.User = SocketGlobalUser.Create(this.Discord, this.Discord.State, model.User.Value); this.User = SocketGlobalUser.Create(this.Discord, this.Discord.State, model.User.Value);
} }
} }

if (this.Channel == null)
{
if (model.ChannelId.IsSpecified)
{
this.Channel = Discord.State.GetChannel(model.ChannelId.Value) as ISocketMessageChannel;
}
else
{
this.Channel = Discord.State.GetDMChannel(this.User.Id);
}
}
} }


/// <summary> /// <summary>
@@ -127,9 +116,8 @@ namespace Discord.WebSocket
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception> /// <exception cref="InvalidOperationException">The parameters provided were invalid or the token was invalid.</exception>


public virtual Task<RestUserMessage> RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{ return null; }
public abstract Task<RestUserMessage> RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);


/// <summary> /// <summary>
/// Sends a followup message for this interaction. /// Sends a followup message for this interaction.
@@ -145,10 +133,9 @@ namespace Discord.WebSocket
/// <returns> /// <returns>
/// The sent message. /// The sent message.
/// </returns> /// </returns>
public virtual Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
public abstract Task<RestFollowupMessage> FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{ return null; }
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);


/// <summary> /// <summary>
/// Acknowledges this interaction with the <see cref="InteractionResponseType.DeferredChannelMessageWithSource"/>. /// Acknowledges this interaction with the <see cref="InteractionResponseType.DeferredChannelMessageWithSource"/>.


Loading…
Cancel
Save