Skip to content

Commit

Permalink
chore: more cleanup and more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Dec 16, 2024
1 parent c7fe2bf commit 835f8e5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 139 deletions.
53 changes: 50 additions & 3 deletions DisCatSharp/Entities/Core/DisCatSharpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,48 @@ public IReadOnlyList<DiscordAttachment> Attachments
public IReadOnlyList<DiscordMessageFile> Files
=> this.FilesInternal;

/// <summary>
/// Gets the Allowed Mentions for the message to be sent.
/// </summary>
public List<IMention>? Mentions { get; internal set; }

/// <summary>
/// Whether to send as voice message.
/// You can't use that on your own, it needs DisCatSharp.Experimental.
/// </summary>
internal bool IsVoiceMessage
{
get => this.VOICE_MSG;
set
{
this.VOICE_MSG = value;
this.FlagsChanged = true;
}
}

/// <summary>
/// Whether to send as voice message.
/// </summary>
private bool VOICE_MSG { get; set; }

/// <summary>
/// Whether to send as silent message.
/// </summary>
public bool NotificationsSuppressed
{
get => this.NOTIFICATIONS_SUPPRESSED;
set
{
this.NOTIFICATIONS_SUPPRESSED = value;
this.FlagsChanged = true;
}
}

/// <summary>
/// Whether to send as silent message.
/// </summary>
private bool NOTIFICATIONS_SUPPRESSED { get; set; }

/// <summary>
/// Whether this message should be using UI Kit.
/// </summary>
Expand All @@ -100,18 +142,18 @@ public bool IsUIKit
/// </summary>
public bool EmbedsSuppressed
{
get => this.EMB_SUP;
get => this.EMBEDS_SUPPRESSED;
set
{
this.EMB_SUP = value;
this.EMBEDS_SUPPRESSED = value;
this.FlagsChanged = true;
}
}

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

/// <summary>
/// Clears the components on this builder.
Expand All @@ -129,7 +171,12 @@ public virtual void Clear()
this.EmbedsInternal.Clear();
this.AttachmentsInternal.Clear();
this.ComponentsInternal.Clear();
this.IsVoiceMessage = false;
this.IsUIKit = false;
this.EmbedsSuppressed = false;
this.NotificationsSuppressed = false;
this.FlagsChanged = false;
this.Mentions = null;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,6 @@ public bool IsEphemeral

private bool EPH { get; set; }

/// <summary>
/// Whether to send as voice message.
/// You can't use that on your own, it needs DisCatSharp.Experimental.
/// </summary>
internal bool IsVoiceMessage
{
get => this.VOICE_MSG;
set
{
this.VOICE_MSG = value;
this.FlagsChanged = true;
}
}

private bool VOICE_MSG { get; set; }

/// <summary>
/// Whether to send as silent message.
/// </summary>
public bool NotificationsSuppressed
{
get => this.NOTI_SUP;
set
{
this.NOTI_SUP = value;
this.FlagsChanged = true;
}
}

private bool NOTI_SUP { get; set; }

/// <summary>
/// Mentions to send on this followup message.
/// </summary>
public List<IMention>? Mentions { get; private set; }

/// <summary>
/// Gets the poll for this message.
/// </summary>
Expand Down Expand Up @@ -180,6 +144,7 @@ public DiscordFollowupMessageBuilder WithContent(string content)
/// <returns>The builder to chain calls with.</returns>
public DiscordFollowupMessageBuilder AddEmbed(DiscordEmbed embed)
{
ArgumentNullException.ThrowIfNull(embed, nameof(embed));
this.EmbedsInternal.Add(embed);
return this;
}
Expand Down Expand Up @@ -309,7 +274,6 @@ public DiscordFollowupMessageBuilder AddMentions(IEnumerable<IMention> mentions)
/// </summary>
public DiscordFollowupMessageBuilder AsEphemeral()
{
this.FlagsChanged = true;
this.IsEphemeral = true;
return this;
}
Expand All @@ -319,7 +283,6 @@ public DiscordFollowupMessageBuilder AsEphemeral()
/// </summary>
public DiscordFollowupMessageBuilder SuppressEmbeds()
{
this.FlagsChanged = true;
this.EmbedsSuppressed = true;
return this;
}
Expand All @@ -329,7 +292,6 @@ public DiscordFollowupMessageBuilder SuppressEmbeds()
/// </summary>
internal DiscordFollowupMessageBuilder AsVoiceMessage(bool asVoiceMessage = true)
{
this.FlagsChanged = true;
this.IsVoiceMessage = asVoiceMessage;
return this;
}
Expand All @@ -339,7 +301,6 @@ internal DiscordFollowupMessageBuilder AsVoiceMessage(bool asVoiceMessage = true
/// </summary>
public DiscordFollowupMessageBuilder AsSilentMessage()
{
this.FlagsChanged = true;
this.NotificationsSuppressed = true;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ public DiscordInteractionResponseBuilder()
/// <see cref="DisCatSharp.Entities.DiscordMessageBuilder" />.
/// </summary>
/// <param name="builder">The builder to copy.</param>
public DiscordInteractionResponseBuilder(DiscordMessageBuilder builder)
public DiscordInteractionResponseBuilder(DisCatSharpBuilder builder)
{
this.Content = builder.Content;
this.Mentions = builder.Mentions;
this.EmbedsInternal.AddRange(builder.Embeds);
this.ComponentsInternal.AddRange(builder.Components);
this.EmbedsSuppressed = builder.EmbedsSuppressed;
this.IsUIKit = builder.IsUIKit;
this.FilesInternal.AddRange(builder.Files);
this.AttachmentsInternal.AddRange(builder.Attachments);
}

internal List<DiscordApplicationCommandAutocompleteChoice> ChoicesInternal { get; } = [];
Expand All @@ -55,48 +59,12 @@ public bool IsEphemeral

private bool EPH { get; set; }

/// <summary>
/// Whether to send as silent message.
/// </summary>
public bool NotificationsSuppressed
{
get => this.NOTI_SUP;
set
{
this.NOTI_SUP = value;
this.FlagsChanged = true;
}
}

private bool NOTI_SUP { get; set; }

/// <summary>
/// Whether to send as voice message.
/// You can't use that on your own, it needs DisCatSharp.Experimental.
/// </summary>
internal bool IsVoiceMessage
{
get => this.VOICE_MSG;
set
{
this.VOICE_MSG = value;
this.FlagsChanged = true;
}
}

private bool VOICE_MSG { get; set; }

/// <summary>
/// The choices to send on this interaction response.
/// Mutually exclusive with content, embed, and components.
/// </summary>
public IReadOnlyList<DiscordApplicationCommandAutocompleteChoice> Choices => this.ChoicesInternal;

/// <summary>
/// Mentions to send on this interaction response.
/// </summary>
public List<IMention>? Mentions { get; private set; }

/// <summary>
/// The hints to send on this interaction response.
/// </summary>
Expand Down Expand Up @@ -222,7 +190,6 @@ public DiscordInteractionResponseBuilder WithTts(bool tts)
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder AsEphemeral()
{
this.FlagsChanged = true;
this.IsEphemeral = true;
return this;
}
Expand All @@ -233,7 +200,6 @@ public DiscordInteractionResponseBuilder AsEphemeral()
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder AsUIKitMessage()
{
this.FlagsChanged = true;
this.IsUIKit = true;
return this;
}
Expand All @@ -244,7 +210,6 @@ public DiscordInteractionResponseBuilder AsUIKitMessage()
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder SuppressEmbeds()
{
this.FlagsChanged = true;
this.EmbedsSuppressed = true;
return this;
}
Expand All @@ -255,7 +220,6 @@ public DiscordInteractionResponseBuilder SuppressEmbeds()
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder AsSilentMessage()
{
this.FlagsChanged = true;
this.NotificationsSuppressed = true;
return this;
}
Expand All @@ -265,7 +229,6 @@ public DiscordInteractionResponseBuilder AsSilentMessage()
/// </summary>
internal DiscordInteractionResponseBuilder AsVoiceMessage(bool asVoiceMessage = true)
{
this.FlagsChanged = true;
this.IsVoiceMessage = asVoiceMessage;
return this;
}
Expand All @@ -288,8 +251,8 @@ public DiscordInteractionResponseBuilder WithContent(string content)
/// <returns>The current builder to chain calls with.</returns>
public DiscordInteractionResponseBuilder AddEmbed(DiscordEmbed embed)
{
if (embed != null)
this.EmbedsInternal.Add(embed); // Interactions will 400 silently //
ArgumentNullException.ThrowIfNull(embed, nameof(embed));
this.EmbedsInternal.Add(embed);
return this;
}

Expand Down Expand Up @@ -456,9 +419,6 @@ public override void Clear()
this.Mentions = null;
this.ChoicesInternal.Clear();
this.Poll = null;
this.IsVoiceMessage = false;
this.NotificationsSuppressed = false;
this.EmbedsSuppressed = false;
base.Clear();
}
}
4 changes: 2 additions & 2 deletions DisCatSharp/Entities/Message/DiscordMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public Task<DiscordMessage> ModifyAsync(Optional<string> content, Optional<IEnum
public async Task<DiscordMessage> ModifyAsync(DiscordMessageBuilder builder)
{
builder.Validate(true);
return await this.Discord.ApiClient.EditMessageAsync(this.ChannelId, this.Id, builder.Content, Optional.Some(builder.Embeds.AsEnumerable()), builder.Mentions, builder.Components, builder.Suppressed, builder.Files, builder.Attachments.Count > 0
return await this.Discord.ApiClient.EditMessageAsync(this.ChannelId, this.Id, builder.Content, Optional.Some(builder.Embeds.AsEnumerable()), builder.Mentions, builder.Components, builder.EmbedsSuppressed, builder.Files, builder.Attachments.Count > 0
? Optional.Some(builder.Attachments.AsEnumerable())
: builder.KeepAttachmentsInternal.HasValue
? builder.KeepAttachmentsInternal.Value && this.Attachments is not null ? Optional.Some(this.Attachments.AsEnumerable()) : Array.Empty<DiscordAttachment>()
Expand Down Expand Up @@ -737,7 +737,7 @@ public async Task<DiscordMessage> ModifyAsync(Action<DiscordMessageBuilder> acti
var builder = new DiscordMessageBuilder();
action(builder);
builder.Validate(true);
return await this.Discord.ApiClient.EditMessageAsync(this.ChannelId, this.Id, builder.Content, Optional.Some(builder.Embeds.AsEnumerable()), builder.Mentions, builder.Components, builder.Suppressed, builder.Files, builder.Attachments.Count > 0
return await this.Discord.ApiClient.EditMessageAsync(this.ChannelId, this.Id, builder.Content, Optional.Some(builder.Embeds.AsEnumerable()), builder.Mentions, builder.Components, builder.EmbedsSuppressed, builder.Files, builder.Attachments.Count > 0
? Optional.Some(builder.Attachments.AsEnumerable())
: builder.KeepAttachmentsInternal.HasValue
? builder.KeepAttachmentsInternal.Value && this.Attachments is not null ? Optional.Some(this.Attachments.AsEnumerable()) : Array.Empty<DiscordAttachment>()
Expand Down
21 changes: 2 additions & 19 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; }

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (ubuntu-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Build library (windows-latest)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

Check warning on line 40 in DisCatSharp/Entities/Message/DiscordMessageBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

'DiscordMessageBuilder.IsVoiceMessage' hides inherited member 'DisCatSharpBuilder.IsVoiceMessage'. Use the new keyword if hiding was intended.

/// <summary>
/// Gets the Allowed Mentions for the message to be sent.
/// </summary>
public List<IMention>? Mentions { get; private set; }

/// <summary>
/// Gets the Reply Message ID.
/// </summary>
Expand All @@ -54,11 +49,6 @@ public sealed class DiscordMessageBuilder : DisCatSharpBuilder
/// </summary>
public bool MentionOnReply { get; private set; }

/// <summary>
/// Gets if the embeds should be suppressed.
/// </summary>
public bool Suppressed { get; private set; }

/// <summary>
/// Gets if the Reply will error if the Reply Message Id does not reference a valid message.
/// <para>If set to false, invalid replies are send as a regular message.</para>
Expand Down Expand Up @@ -228,7 +218,7 @@ public DiscordMessageBuilder HasTts(bool isTts)
/// </summary>
public DiscordMessageBuilder SuppressEmbeds(bool suppress = true)
{
this.Suppressed = suppress;
this.EmbedsSuppressed = suppress;
return this;
}

Expand All @@ -238,7 +228,6 @@ public DiscordMessageBuilder SuppressEmbeds(bool suppress = true)
/// <returns>The current builder to chain calls with.</returns>
public DiscordMessageBuilder AsUIKitMessage()
{
this.FlagsChanged = true;
this.IsUIKit = true;
return this;
}
Expand Down Expand Up @@ -268,9 +257,7 @@ public DiscordMessageBuilder AsSilentMessage(bool silent = true)
/// <returns>The current builder to be chained.</returns>
public DiscordMessageBuilder AddEmbed(DiscordEmbed embed)
{
if (embed == null)
return this; //Providing null embeds will produce a 400 response from Discord.//

ArgumentNullException.ThrowIfNull(embed, nameof(embed));
this.EmbedsInternal.Add(embed);
return this;
}
Expand Down Expand Up @@ -472,17 +459,13 @@ public void ClearPoll()
public override void Clear()
{
this.IsTts = false;
this.Mentions = null;
this.ReplyId = null;
this.MentionOnReply = false;
this.Suppressed = false;
this.Sticker = null!;
this.KeepAttachmentsInternal = false;
this.Nonce = null;
this.EnforceNonce = false;
this.Poll = null;
this.IsVoiceMessage = false;
this.IsUIKit = false;
base.Clear();
}

Expand Down
Loading

0 comments on commit 835f8e5

Please sign in to comment.