Skip to content

Commit

Permalink
fix: fix mistakes - oppsie~
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Dec 16, 2024
1 parent 683268c commit 76c92e8
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 82 deletions.
54 changes: 50 additions & 4 deletions DisCatSharp/Entities/Core/DisCatSharpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public class DisCatSharpBuilder
/// </summary>
internal string? ContentInternal { get; set; }

/// <summary>
/// Whether flags were changed.
/// </summary>
internal bool FlagsChanged { get; set; } = false;

/// <summary>
/// The components of this builder.
/// </summary>
public IReadOnlyList<DiscordComponent> Components => this.ComponentsInternal;
public IReadOnlyList<DiscordComponent> Components
=> this.ComponentsInternal;

/// <summary>
/// The content of this builder.
Expand All @@ -56,17 +62,56 @@ public string? Content
/// <summary>
/// The embeds for this builder.
/// </summary>
public IReadOnlyList<DiscordEmbed> Embeds => this.EmbedsInternal;
public IReadOnlyList<DiscordEmbed> Embeds
=> this.EmbedsInternal;

/// <summary>
/// The attachments of this builder.
/// </summary>
public IReadOnlyList<DiscordAttachment> Attachments => this.AttachmentsInternal;
public IReadOnlyList<DiscordAttachment> Attachments
=> this.AttachmentsInternal;

/// <summary>
/// The files of this builder.
/// </summary>
public IReadOnlyList<DiscordMessageFile> Files => this.FilesInternal;
public IReadOnlyList<DiscordMessageFile> Files
=> this.FilesInternal;

/// <summary>
/// Whether this message should be using UI Kit.
/// </summary>
public bool IsUIKit
{
get => this.UI_KIT;
set
{
this.UI_KIT = value;
this.FlagsChanged = true;
}
}

/// <summary>
/// Whether this is using UI Kit.
/// </summary>
private bool UI_KIT { get; set; }

/// <summary>
/// Whether to suppress embeds.
/// </summary>
public bool EmbedsSuppressed
{
get => this.EMB_SUP;
set
{
this.EMB_SUP = value;
this.FlagsChanged = true;
}
}

/// <summary>
/// Whether embeds are suppressed.
/// </summary>
private bool EMB_SUP { get; set; }

/// <summary>
/// Clears the components on this builder.
Expand All @@ -84,6 +129,7 @@ public virtual void Clear()
this.EmbedsInternal.Clear();
this.AttachmentsInternal.Clear();
this.ComponentsInternal.Clear();
this.FlagsChanged = false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public DiscordMediaGalleryComponent(IEnumerable<DiscordMediaGalleryItem> items)
/// <summary>
/// The content for the media gallery.
/// </summary>
[JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("items", NullValueHandling = NullValueHandling.Ignore)]
public IReadOnlyList<DiscordMediaGalleryItem> Items { get; internal set; } = [];
}
53 changes: 27 additions & 26 deletions DisCatSharp/Entities/Interaction/DiscordFollowupMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace DisCatSharp.Entities;
/// </summary>
public sealed class DiscordFollowupMessageBuilder : DisCatSharpBuilder
{
/// <summary>
/// Whether flags were changed.
/// </summary>
internal bool FlagsChanged = false;

/// <summary>
/// Whether this followup message is text-to-speech.
/// </summary>
Expand All @@ -37,21 +32,6 @@ public bool IsEphemeral

private bool EPH { get; set; }

/// <summary>
/// Whether to suppress embeds.
/// </summary>
public bool EmbedsSuppressed
{
get => this.EMB_SUP;
set
{
this.EMB_SUP = value;
this.FlagsChanged = true;
}
}

private bool EMB_SUP { get; set; }

/// <summary>
/// Whether to send as voice message.
/// You can't use that on your own, it needs DisCatSharp.Experimental.
Expand Down Expand Up @@ -128,14 +108,35 @@ public DiscordFollowupMessageBuilder AddComponents(IEnumerable<DiscordActionRowC
/// <exception cref="ArgumentException"><paramref name="components" /> contained more than 5 components.</exception>
public DiscordFollowupMessageBuilder AddComponents(IEnumerable<DiscordComponent> components)
{
var compArr = components.ToArray();
var count = compArr.Length;
var cmpArr = components.ToArray();
var count = cmpArr.Length;

if (count > 5)
throw new ArgumentException("Cannot add more than 5 components per action row!");
if (this.IsUIKit)
{
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 10:
throw new ArgumentException("Cannot add more than 10 components!");
}

this.ComponentsInternal.AddRange(cmpArr);
}
else
{
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 5:
throw new ArgumentException("Cannot add more than 5 components per action row!");
}

var comp = new DiscordActionRowComponent(cmpArr);
this.ComponentsInternal.Add(comp);
}

var arc = new DiscordActionRowComponent(compArr);
this.ComponentsInternal.Add(arc);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public sealed class DiscordInteractionResponseBuilder : DisCatSharpBuilder
{
private readonly List<DiscordInteractionCallbackHint> _callbackHints = [];

/// <summary>
/// Whether flags were changed.
/// </summary>
internal bool FlagsChanged = false;

/// <summary>
/// Constructs a new empty interaction response builder.
/// </summary>
Expand Down Expand Up @@ -60,21 +55,6 @@ public bool IsEphemeral

private bool EPH { get; set; }

/// <summary>
/// Whether to suppress embeds.
/// </summary>
public bool EmbedsSuppressed
{
get => this.EMB_SUP;
set
{
this.EMB_SUP = value;
this.FlagsChanged = true;
}
}

private bool EMB_SUP { get; set; }

/// <summary>
/// Whether to send as silent message.
/// </summary>
Expand Down Expand Up @@ -182,14 +162,35 @@ public DiscordInteractionResponseBuilder AddComponents(IEnumerable<DiscordAction
/// <exception cref="ArgumentException">Thrown when passing more than 5 components.</exception>
public DiscordInteractionResponseBuilder AddComponents(IEnumerable<DiscordComponent> components)
{
var compArr = components.ToArray();
var count = compArr.Length;
var cmpArr = components.ToArray();
var count = cmpArr.Length;

if (count > 5)
throw new ArgumentException("Cannot add more than 5 components per action row!");
if (this.IsUIKit)
{
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 10:
throw new ArgumentException("Cannot add more than 10 components!");
}

this.ComponentsInternal.AddRange(cmpArr);
}
else
{
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 5:
throw new ArgumentException("Cannot add more than 5 components per action row!");
}

var comp = new DiscordActionRowComponent(cmpArr);
this.ComponentsInternal.Add(comp);
}

var arc = new DiscordActionRowComponent(compArr);
this.ComponentsInternal.Add(arc);
return this;
}

Expand Down Expand Up @@ -226,6 +227,17 @@ public DiscordInteractionResponseBuilder AsEphemeral()
return this;
}

/// <summary>
/// Sets that this builder should be using UI Kit.
/// </summary>
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder AsUIKitMessage()
{
this.FlagsChanged = true;
this.IsUIKit = true;
return this;
}

/// <summary>
/// Sets the interaction response to suppress embeds.
/// </summary>
Expand Down
13 changes: 5 additions & 8 deletions DisCatSharp/Entities/Message/DiscordMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public sealed class DiscordMessageBuilder : DisCatSharpBuilder
/// </summary>
public bool IsVoiceMessage { get; private set; }

/// <summary>
/// Whether to send with ui kit.
/// </summary>
public bool IsUIKit { get; private set; }

/// <summary>
/// Gets the Allowed Mentions for the message to be sent.
/// </summary>
Expand Down Expand Up @@ -238,11 +233,13 @@ public DiscordMessageBuilder SuppressEmbeds(bool suppress = true)
}

/// <summary>
/// Sets the message to be send with ui kit.
/// Sets that this builder should be using UI Kit.
/// </summary>
public DiscordMessageBuilder AsUiKitMessage(bool asUiKitMessage = true)
/// <returns>The current builder to chain calls with.</returns>
public DiscordMessageBuilder AsUIKitMessage()
{
this.IsUIKit = asUiKitMessage;
this.FlagsChanged = true;
this.IsUIKit = true;
return this;
}

Expand Down
50 changes: 33 additions & 17 deletions DisCatSharp/Entities/Webhook/DiscordWebhookBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ public sealed class DiscordWebhookBuilder : DisCatSharpBuilder
{
private readonly List<ulong> _appliedTags = [];

/// <summary>
/// Whether flags were changed.
/// </summary>
internal bool FlagsChanged = false;

/// <summary>
/// Whether to keep previous attachments.
/// </summary>
Expand All @@ -47,11 +42,6 @@ public DiscordWebhookBuilder()
/// </summary>
public bool IsTts { get; private set; }

/// <summary>
/// Whether to suppress embeds.
/// </summary>
public bool EmbedsSuppressed { get; private set; }

/// <summary>
/// Whether to send as silent message.
/// </summary>
Expand Down Expand Up @@ -152,17 +142,43 @@ public DiscordWebhookBuilder AddComponents(IEnumerable<DiscordComponent> compone
var cmpArr = components.ToArray();
var count = cmpArr.Length;

switch (count)
if (this.IsUIKit)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 5:
throw new ArgumentException("Cannot add more than 5 components per action row!");
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 10:
throw new ArgumentException("Cannot add more than 10 components!");
}

this.ComponentsInternal.AddRange(cmpArr);
}
else
{
switch (count)
{
case 0:
throw new ArgumentOutOfRangeException(nameof(components), "You must provide at least one component");
case > 5:
throw new ArgumentException("Cannot add more than 5 components per action row!");
}

var comp = new DiscordActionRowComponent(cmpArr);
this.ComponentsInternal.Add(comp);
}

var comp = new DiscordActionRowComponent(cmpArr);
this.ComponentsInternal.Add(comp);
return this;
}

/// <summary>
/// Sets that this builder should be using UI Kit.
/// </summary>
/// <returns>The current builder to chain calls with.</returns>
public DiscordWebhookBuilder AsUIKitMessage()
{
this.FlagsChanged = true;
this.IsUIKit = true;
return this;
}

Expand Down
6 changes: 6 additions & 0 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5331,6 +5331,8 @@ internal async Task<DiscordMessage> EditWebhookMessageAsync(ulong webhookId, str
flags |= MessageFlags.SuppressedEmbeds;
if (builder.NotificationsSuppressed)
flags |= MessageFlags.SuppressNotifications;
if (builder.IsUIKit)
flags |= MessageFlags.UIKit;

var pld = new RestWebhookMessageEditPayload
{
Expand Down Expand Up @@ -7051,6 +7053,8 @@ internal async Task<DiscordInteractionCallbackResponse> CreateInteractionRespons
flags |= MessageFlags.SuppressedEmbeds;
if (builder.NotificationsSuppressed)
flags |= MessageFlags.SuppressNotifications;
if (builder.IsUIKit)
flags |= MessageFlags.UIKit;
}

var data = builder is not null
Expand Down Expand Up @@ -7285,6 +7289,8 @@ internal async Task<DiscordMessage> CreateFollowupMessageAsync(ulong application
flags |= MessageFlags.SuppressedEmbeds;
if (builder.NotificationsSuppressed)
flags |= MessageFlags.SuppressNotifications;
if (builder.IsUIKit)
flags |= MessageFlags.UIKit;

var values = new Dictionary<string, string>();
var pld = new RestFollowupMessageCreatePayload
Expand Down

0 comments on commit 76c92e8

Please sign in to comment.