Create all interaction models

This commit is contained in:
Daan Boerlage 2021-09-20 01:28:26 +02:00
parent 209887e237
commit 60547140ea
Signed by: daan
GPG key ID: FCE070E1E4956606
59 changed files with 1589 additions and 222 deletions

View file

@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Geekbot.Core.Interactions.Resolved;
namespace Geekbot.Core.Interactions.Request
{
/// <see href="https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-structure" />
public record Interaction
{
/// <summary>
/// id of the interaction
/// </summary>
[JsonPropertyName("id")]
public string Id { get; init; }
/// <summary>
/// id of the application this interaction is for
/// </summary>
[JsonPropertyName("application_id")]
public string ApplicationId { get; init; }
/// <summary>
/// the type of interaction
/// </summary>
[JsonPropertyName("type")]
public InteractionType Type { get; init; }
/// <summary>
/// the command data payload
/// </summary>
[JsonPropertyName("data")]
public InteractionData Data { get; init; }
/// <summary>
/// the guild it was sent from
/// </summary>
[JsonPropertyName("guild_id")]
public string GuildId { get; init; }
/// <summary>
/// the channel it was sent from
/// </summary>
[JsonPropertyName("channel_id")]
public string ChannelId { get; init; }
/// <summary>
/// guild member data for the invoking user, including permissions
/// </summary>
[JsonPropertyName("member")]
public Member Member { get; init; }
/// <summary>
/// user object for the invoking user, if invoked in a DM
/// </summary>
[JsonPropertyName("user")]
public User User { get; init; }
/// <summary>
/// a continuation token for responding to the interaction
/// </summary>
[JsonPropertyName("token")]
public string Token { get; init; }
/// <summary>
/// read-only property, always 1
/// </summary>
[JsonPropertyName("version")]
public int Version { get; init; }
/// <summary>
/// object for components, the message they were attached to
/// </summary>
[JsonPropertyName("message")]
public Message Message { get; init; }
}
}

View file

@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Geekbot.Core.Interactions.ApplicationCommand;
using Geekbot.Core.Interactions.MessageComponents;
namespace Geekbot.Core.Interactions.Request
{
/// <see href="https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data-structure" />
public class InteractionData
{
/// <summary>
/// the ID of the invoked command
/// </summary>
/// <remarks>
/// For: Application Command
/// </remarks>
[JsonPropertyName("id")]
public string Id { get; init; }
/// <summary>
/// the name of the invoked command
/// </summary>
/// <remarks>
/// For: Application Command
/// </remarks>
[JsonPropertyName("name")]
public string Name { get; init; }
/// <summary>
/// the type of the invoked command
/// </summary>
/// <remarks>
/// For: Application Command
/// </remarks>
[JsonPropertyName("type")]
public CommandType Type { get; init; }
/// <summary>
/// converted users + roles + channels
/// </summary>
/// <remarks>
/// For: Application Command
/// </remarks>
[JsonPropertyName("resolved")]
public InteractionResolvedData Resolved { get; init; }
/// <summary>
/// of application command interaction data option the params + values from the user
/// </summary>
/// <remarks>
/// For: Application Command
/// </remarks>
[JsonPropertyName("options")]
public List<InteractionOption> Options { get; init; }
/// <summary>
/// the custom_id of the component
/// </summary>
/// <remarks>
/// For: Component
/// </remarks>
[JsonPropertyName("custom_id")]
public string CustomId { get; init; }
/// <summary>
/// the type of the component
/// </summary>
/// <remarks>
/// For: Component
/// </remarks>
[JsonPropertyName("component_type")]
public ComponentType ComponentType { get; init; }
/// <summary>
/// of select option values the values the user selected
/// </summary>
/// <remarks>
/// Component (Select)
/// </remarks>
[JsonPropertyName("values")]
public string Values { get; init; }
/// <summary>
/// id the of user or message targetted by a user or message command
/// </summary>
/// <remarks>
/// For: Application Command
/// Present in: User Command, Message Command
/// </remarks>
[JsonPropertyName("target_id")]
public string TargetId { get; init; }
public string GetTargetNickname()
{
return GetUserNickename(TargetId);
}
public string GetUserNickename(string userId)
{
var username = Resolved.Members[userId].Nick;
if (string.IsNullOrEmpty(username))
{
username = Resolved.Users[userId].Username;
}
return username;
}
}
}

View file

@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Geekbot.Core.Interactions.ApplicationCommand;
namespace Geekbot.Core.Interactions.Request
{
/// <see href="https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-interaction-data-option-structure" />
public record InteractionOption
{
/// <summary>
/// the name of the parameter
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
/// <summary>
/// value of application command option type
/// </summary>
[JsonPropertyName("type")]
public OptionType Type { get; set; }
/// <summary>
/// the value of the pair
/// </summary>
[JsonPropertyName("value")]
public object Value { get; set; }
/// <summary>
/// present if this option is a group or subcommand
/// </summary>
[JsonPropertyName("options")]
public List<InteractionOption> Options { get; set; }
}
}

View file

@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Geekbot.Core.Interactions.Resolved;
namespace Geekbot.Core.Interactions.Request
{
public class InteractionResolvedData
{
[JsonPropertyName("users")]
public Dictionary<string, User> Users { get; set; }
[JsonPropertyName("members")]
public Dictionary<string, Member> Members { get; set; }
[JsonPropertyName("roles")]
public Dictionary<string, Role> Roles { get; set; }
[JsonPropertyName("channels")]
public Dictionary<string, Channel> Channels { get; set; }
[JsonPropertyName("messages")]
public Dictionary<string, Message> Messages { get; set; }
}
}

View file

@ -0,0 +1,10 @@
namespace Geekbot.Core.Interactions.Request
{
/// <see href="https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type" />
public enum InteractionType
{
Ping = 1,
ApplicationCommand = 2,
MessageComponent = 3,
}
}