Skip to content

Commit d27bb49

Browse files
authored
Revert "[Feature] Components V2 (#3065)" (#3100)
This reverts commit ba78e0c.
1 parent ba78e0c commit d27bb49

File tree

102 files changed

+691
-2851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+691
-2851
lines changed

src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public interface IDiscordInteraction : ISnowflakeEntity
132132
/// A task that represents an asynchronous send operation for delivering the message.
133133
/// </returns>
134134
Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null,
135-
MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
135+
MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
136136

137137
/// <summary>
138138
/// Responds to this interaction with a file attachment.
@@ -154,8 +154,7 @@ Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false,
154154
/// </returns>
155155
#if NETCOREAPP3_0_OR_GREATER
156156
async Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
157-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
158-
MessageFlags flags = MessageFlags.None)
157+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
159158
{
160159
using (var file = new FileAttachment(fileStream, fileName))
161160
{
@@ -164,8 +163,7 @@ async Task RespondWithFileAsync(Stream fileStream, string fileName, string text
164163
}
165164
#else
166165
Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
167-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null
168-
, MessageFlags flags = MessageFlags.None);
166+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
169167
#endif
170168
/// <summary>
171169
/// Responds to this interaction with a file attachment.
@@ -187,8 +185,7 @@ Task RespondWithFileAsync(Stream fileStream, string fileName, string text = null
187185
/// </returns>
188186
#if NETCOREAPP3_0_OR_GREATER
189187
async Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
190-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
191-
MessageFlags flags = MessageFlags.None)
188+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
192189
{
193190
using (var file = new FileAttachment(filePath, fileName))
194191
{
@@ -197,8 +194,7 @@ async Task RespondWithFileAsync(string filePath, string fileName = null, string
197194
}
198195
#else
199196
Task RespondWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
200-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
201-
MessageFlags flags = MessageFlags.None);
197+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
202198
#endif
203199
/// <summary>
204200
/// Responds to this interaction with a file attachment.
@@ -219,13 +215,11 @@ Task RespondWithFileAsync(string filePath, string fileName = null, string text =
219215
/// </returns>
220216
#if NETCOREAPP3_0_OR_GREATER
221217
Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
222-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
223-
MessageFlags flags = MessageFlags.None)
224-
=> RespondWithFilesAsync([attachment], text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
218+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
219+
=> RespondWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll);
225220
#else
226221
Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
227-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
228-
MessageFlags flags = MessageFlags.None);
222+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
229223
#endif
230224
/// <summary>
231225
/// Responds to this interaction with a collection of file attachments.
@@ -245,9 +239,7 @@ Task RespondWithFileAsync(FileAttachment attachment, string text = null, Embed[]
245239
/// contains the sent message.
246240
/// </returns>
247241
Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
248-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
249-
MessageFlags flags = MessageFlags.None);
250-
242+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
251243
/// <summary>
252244
/// Sends a followup message for this interaction.
253245
/// </summary>
@@ -265,9 +257,7 @@ Task RespondWithFilesAsync(IEnumerable<FileAttachment> attachments, string text
265257
/// contains the sent message.
266258
/// </returns>
267259
Task<IUserMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
268-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
269-
MessageFlags flags = MessageFlags.None);
270-
260+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
271261
/// <summary>
272262
/// Sends a followup message for this interaction.
273263
/// </summary>
@@ -288,19 +278,17 @@ Task<IUserMessage> FollowupAsync(string text = null, Embed[] embeds = null, bool
288278
/// </returns>
289279
#if NETCOREAPP3_0_OR_GREATER
290280
async Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
291-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
281+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
292282
{
293283
using (var file = new FileAttachment(fileStream, fileName))
294284
{
295-
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
285+
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
296286
}
297287
}
298288
#else
299289
Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
300-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
301-
MessageFlags flags = MessageFlags.None);
290+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
302291
#endif
303-
304292
/// <summary>
305293
/// Sends a followup message for this interaction.
306294
/// </summary>
@@ -321,17 +309,16 @@ Task<IUserMessage> FollowupWithFileAsync(Stream fileStream, string fileName, str
321309
/// </returns>
322310
#if NETCOREAPP3_0_OR_GREATER
323311
async Task<IUserMessage> FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
324-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null,
325-
MessageFlags flags = MessageFlags.None)
312+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
326313
{
327314
using (var file = new FileAttachment(filePath, fileName))
328315
{
329-
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags).ConfigureAwait(false);
316+
return await FollowupWithFileAsync(file, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll).ConfigureAwait(false);
330317
}
331318
}
332319
#else
333320
Task<IUserMessage> FollowupWithFileAsync(string filePath, string fileName = null, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
334-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
321+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
335322
#endif
336323
/// <summary>
337324
/// Sends a followup message for this interaction.
@@ -352,11 +339,11 @@ Task<IUserMessage> FollowupWithFileAsync(string filePath, string fileName = null
352339
/// </returns>
353340
#if NETCOREAPP3_0_OR_GREATER
354341
Task<IUserMessage> FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
355-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None)
356-
=> FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll, flags);
342+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null)
343+
=> FollowupWithFilesAsync(new FileAttachment[] { attachment }, text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options, poll);
357344
#else
358345
Task<IUserMessage> FollowupWithFileAsync(FileAttachment attachment, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
359-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
346+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
360347
#endif
361348
/// <summary>
362349
/// Sends a followup message for this interaction.
@@ -376,7 +363,7 @@ Task<IUserMessage> FollowupWithFileAsync(FileAttachment attachment, string text
376363
/// contains the sent message.
377364
/// </returns>
378365
Task<IUserMessage> FollowupWithFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
379-
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null, MessageFlags flags = MessageFlags.None);
366+
AllowedMentions allowedMentions = null, MessageComponent components = null, Embed embed = null, RequestOptions options = null, PollProperties poll = null);
380367
/// <summary>
381368
/// Gets the original response for this interaction.
382369
/// </summary>
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
using System.Collections.Generic;
22

3-
namespace Discord;
4-
5-
/// <summary>
6-
/// Represents a <see cref="IMessageComponent"/> Row for child components to live in.
7-
/// </summary>
8-
public class ActionRowComponent : IMessageComponent
3+
namespace Discord
94
{
10-
/// <inheritdoc/>
11-
public ComponentType Type => ComponentType.ActionRow;
12-
13-
/// <inheritdoc/>
14-
public int? Id { get; internal set; }
15-
165
/// <summary>
17-
/// Gets the child components in this row.
6+
/// Represents a <see cref="IMessageComponent"/> Row for child components to live in.
187
/// </summary>
19-
public IReadOnlyCollection<IMessageComponent> Components { get; internal set; }
8+
public class ActionRowComponent : IMessageComponent
9+
{
10+
/// <inheritdoc/>
11+
public ComponentType Type => ComponentType.ActionRow;
2012

21-
internal ActionRowComponent() { }
13+
/// <summary>
14+
/// Gets the child components in this row.
15+
/// </summary>
16+
public IReadOnlyCollection<IMessageComponent> Components { get; internal set; }
2217

23-
internal ActionRowComponent(IReadOnlyCollection<IMessageComponent> components)
24-
{
25-
Components = components;
18+
internal ActionRowComponent() { }
19+
20+
internal ActionRowComponent(List<IMessageComponent> components)
21+
{
22+
Components = components;
23+
}
24+
25+
string IMessageComponent.CustomId => null;
2626
}
2727
}

src/Discord.Net.Core/Entities/Interactions/MessageComponents/Builders/ActionRowBuilder.cs

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ namespace Discord;
88
/// <summary>
99
/// Represents a class used to build Action rows.
1010
/// </summary>
11-
public class ActionRowBuilder : IMessageComponentBuilder, IInteractableComponentContainer
11+
public class ActionRowBuilder
1212
{
13-
public ComponentType Type => ComponentType.ActionRow;
14-
15-
public int? Id { get; set; }
16-
1713
/// <summary>
1814
/// The max amount of child components this row can hold.
1915
/// </summary>
@@ -24,7 +20,7 @@ public class ActionRowBuilder : IMessageComponentBuilder, IInteractableComponent
2420
/// </summary>
2521
/// <exception cref="ArgumentNullException" accessor="set"><see cref="Components"/> cannot be null.</exception>
2622
/// <exception cref="ArgumentException" accessor="set"><see cref="Components"/> count exceeds <see cref="MaxChildCount"/>.</exception>
27-
public List<IMessageComponentBuilder> Components
23+
public List<IMessageComponent> Components
2824
{
2925
get => _components;
3026
set
@@ -41,29 +37,15 @@ public List<IMessageComponentBuilder> Components
4137
}
4238
}
4339

44-
45-
public ActionRowBuilder AddComponents(params IMessageComponentBuilder[] components)
46-
{
47-
foreach (var component in components)
48-
AddComponent(component);
49-
return this;
50-
}
51-
52-
public ActionRowBuilder WithComponents(IEnumerable<IMessageComponentBuilder> components)
53-
{
54-
Components = components.ToList();
55-
return this;
56-
}
57-
58-
private List<IMessageComponentBuilder> _components = new ();
40+
private List<IMessageComponent> _components = new List<IMessageComponent>();
5941

6042
/// <summary>
6143
/// Adds a list of components to the current row.
6244
/// </summary>
6345
/// <param name="components">The list of components to add.</param>
6446
/// <inheritdoc cref="Components"/>
6547
/// <returns>The current builder.</returns>
66-
public ActionRowBuilder WithComponents(List<IMessageComponentBuilder> components)
48+
public ActionRowBuilder WithComponents(List<IMessageComponent> components)
6749
{
6850
Components = components;
6951
return this;
@@ -75,7 +57,7 @@ public ActionRowBuilder WithComponents(List<IMessageComponentBuilder> components
7557
/// <param name="component">The component to add.</param>
7658
/// <exception cref="InvalidOperationException">Components count reached <see cref="MaxChildCount"/></exception>
7759
/// <returns>The current builder.</returns>
78-
public ActionRowBuilder AddComponent(IMessageComponentBuilder component)
60+
public ActionRowBuilder AddComponent(IMessageComponent component)
7961
{
8062
if (Components.Count >= MaxChildCount)
8163
throw new InvalidOperationException($"Components count reached {MaxChildCount}");
@@ -121,11 +103,13 @@ public ActionRowBuilder WithSelectMenu(SelectMenuBuilder menu)
121103
{
122104
if (menu.Options is not null && menu.Options.Distinct().Count() != menu.Options.Count)
123105
throw new InvalidOperationException("Please make sure that there is no duplicates values.");
124-
106+
107+
var builtMenu = menu.Build();
108+
125109
if (Components.Count != 0)
126110
throw new InvalidOperationException($"A Select Menu cannot exist in a pre-occupied ActionRow.");
127111

128-
AddComponent(menu);
112+
AddComponent(builtMenu);
129113

130114
return this;
131115
}
@@ -168,13 +152,15 @@ public ActionRowBuilder WithButton(
168152
/// <returns>The current builder.</returns>
169153
public ActionRowBuilder WithButton(ButtonBuilder button)
170154
{
155+
var builtButton = button.Build();
156+
171157
if (Components.Count >= 5)
172158
throw new InvalidOperationException($"Components count reached {MaxChildCount}");
173159

174160
if (Components.Any(x => x.Type.IsSelectType()))
175161
throw new InvalidOperationException($"A button cannot be added to a row with a SelectMenu");
176162

177-
AddComponent(button);
163+
AddComponent(builtButton);
178164

179165
return this;
180166
}
@@ -185,11 +171,10 @@ public ActionRowBuilder WithButton(ButtonBuilder button)
185171
/// <returns>A <see cref="ActionRowComponent"/> that can be used within a <see cref="ComponentBuilder"/></returns>
186172
public ActionRowComponent Build()
187173
{
188-
return new ActionRowComponent(_components.Select(x => x.Build()).ToList());
174+
return new ActionRowComponent(_components);
189175
}
190-
IMessageComponent IMessageComponentBuilder.Build() => Build();
191176

192-
internal bool CanTakeComponent(IMessageComponentBuilder component)
177+
internal bool CanTakeComponent(IMessageComponent component)
193178
{
194179
switch (component.Type)
195180
{
@@ -210,11 +195,4 @@ internal bool CanTakeComponent(IMessageComponentBuilder component)
210195
return false;
211196
}
212197
}
213-
214-
215-
IComponentContainer IComponentContainer.AddComponent(IMessageComponentBuilder component) => AddComponent(component);
216-
217-
IComponentContainer IComponentContainer.AddComponents(params IMessageComponentBuilder[] components) => AddComponents(components);
218-
219-
IComponentContainer IComponentContainer.WithComponents(IEnumerable<IMessageComponentBuilder> components) => WithComponents(components);
220198
}

0 commit comments

Comments
 (0)