/
InteractionProperties.cs
101 lines (88 loc) · 3.39 KB
/
InteractionProperties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Discord.Rest
{
/// <summary>
/// Represents a class that contains data present in all interactions to evaluate against at rest-interaction creation.
/// </summary>
public readonly struct InteractionProperties
{
/// <summary>
/// The type of this interaction.
/// </summary>
public InteractionType Type { get; }
/// <summary>
/// Gets the type of application command this interaction represents.
/// </summary>
/// <remarks>
/// This will be <see langword="null"/> if the <see cref="Type"/> is not <see cref="InteractionType.ApplicationCommand"/>.
/// </remarks>
public ApplicationCommandType? CommandType { get; }
/// <summary>
/// Gets the name of the interaction.
/// </summary>
/// <remarks>
/// This will be <see cref="string.Empty"/> if the <see cref="Type"/> is not <see cref="InteractionType.ApplicationCommand"/>.
/// </remarks>
public string Name { get; } = string.Empty;
/// <summary>
/// Gets the custom ID of the interaction.
/// </summary>
/// <remarks>
/// This will be <see cref="string.Empty"/> if the <see cref="Type"/> is not <see cref="InteractionType.MessageComponent"/> or <see cref="InteractionType.ModalSubmit"/>.
/// </remarks>
public string CustomId { get; } = string.Empty;
/// <summary>
/// Gets the guild ID of the interaction.
/// </summary>
/// <remarks>
/// This will be <see langword="null"/> if this interaction was not executed in a guild.
/// </remarks>
public ulong? GuildId { get; }
/// <summary>
/// Gets the channel ID of the interaction.
/// </summary>
/// <remarks>
/// This will be <see langword="null"/> if this interaction is <see cref="InteractionType.Ping"/>.
/// </remarks>
public ulong? ChannelId { get; }
internal InteractionProperties(API.Interaction model)
{
Type = model.Type;
CommandType = null;
if (model.GuildId.IsSpecified)
GuildId = model.GuildId.Value;
else
GuildId = null;
if (model.ChannelId.IsSpecified)
ChannelId = model.ChannelId.Value;
else
ChannelId = null;
switch (Type)
{
case InteractionType.ApplicationCommand:
{
var data = (API.ApplicationCommandInteractionData)model.Data;
CommandType = data.Type;
Name = data.Name;
}
break;
case InteractionType.MessageComponent:
{
var data = (API.MessageComponentInteractionData)model.Data;
CustomId = data.CustomId;
}
break;
case InteractionType.ModalSubmit:
{
var data = (API.ModalInteractionData)model.Data;
CustomId = data.CustomId;
}
break;
}
}
}
}