Browse Source

Closes #11. Added DM support for message components and slash command. Fixed incorrect author for messages

pull/1923/head
quin lynch 4 years ago
parent
commit
cb288ba235
2 changed files with 36 additions and 24 deletions
  1. +24
    -23
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  2. +12
    -1
      src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs

+ 24
- 23
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1785,34 +1785,35 @@ namespace Discord.WebSocket
await _gatewayLogger.DebugAsync("Received Dispatch (INTERACTION_CREATE)").ConfigureAwait(false);

var data = (payload as JToken).ToObject<API.Gateway.InteractionCreated>(_serializer);
if (data.Member.IsSpecified && data.ChannelId.IsSpecified)
{
if (State.GetChannel(data.ChannelId.Value) is SocketGuildChannel channel)
{
var guild = channel.Guild;
if (!guild.IsSynced)
{
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
return;
}

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

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

await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false);
}
else
{
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
return;
}
SocketChannel channel;
if(data.ChannelId.IsSpecified)
{
channel = State.GetChannel(data.ChannelId.Value);
}
else if (data.User.IsSpecified)
{
channel = State.GetDMChannel(data.User.Value.Id);
}
else
{
// DM TODO
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
return;
}

var guild = (channel as SocketGuildChannel)?.Guild;
if (guild != null && !guild.IsSynced)
{
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
return;
}

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

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

await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false);
}
break;
case "APPLICATION_COMMAND_CREATE":


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

@@ -52,7 +52,18 @@ namespace Discord.WebSocket
{
if (this.Message == null)
{
this.Message = SocketMessage.Create(this.Discord, this.Discord.State, this.User, this.Channel, model.Message.Value);
SocketUser author = null;
if (this.Channel is SocketGuildChannel channel)
{
if (model.Message.Value.WebhookId.IsSpecified)
author = SocketWebhookUser.Create(channel.Guild, Discord.State, model.Message.Value.Author.Value, model.Message.Value.WebhookId.Value);
else
author = channel.Guild.GetUser(model.Message.Value.Author.Value.Id);
}
else
author = (this.Channel as SocketChannel).GetUser(model.Message.Value.Author.Value.Id);

this.Message = SocketMessage.Create(this.Discord, this.Discord.State, author, this.Channel, model.Message.Value);
}
else
{


Loading…
Cancel
Save