Add MaxUploadLimit to guilds (#2001)

This commit is contained in:
Quin Lynch
2021-12-24 15:58:01 -04:00
committed by GitHub
parent 2a416a355c
commit 7745558bdc
5 changed files with 30 additions and 0 deletions

View File

@@ -354,6 +354,11 @@ namespace Discord
/// </returns> /// </returns>
bool IsBoostProgressBarEnabled { get; } bool IsBoostProgressBarEnabled { get; }
/// <summary>
/// Gets the upload limit in bytes for this guild. This number is dependent on the guild's boost status.
/// </summary>
ulong MaxUploadLimit { get; }
/// <summary> /// <summary>
/// Modifies this guild. /// Modifies this guild.
/// </summary> /// </summary>

View File

@@ -372,6 +372,16 @@ namespace Discord.Rest
Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null"); Preconditions.NotNullOrEmpty(attachment.FileName, nameof(attachment.FileName), "File Name must not be empty or null");
} }
if (channel is ITextChannel guildTextChannel)
{
var contentSize = (ulong)attachments.Sum(x => x.Stream.Length);
if (contentSize > guildTextChannel.Guild.MaxUploadLimit)
{
throw new ArgumentOutOfRangeException(nameof(attachments), $"Collective file size exceeds the max file size of {guildTextChannel.Guild.MaxUploadLimit} bytes in that guild!");
}
}
// check that user flag and user Id list are exclusive, same with role flag and role Id list // check that user flag and user Id list are exclusive, same with role flag and role Id list
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
{ {

View File

@@ -124,6 +124,15 @@ namespace Discord.Rest
{ {
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
} }
public static ulong GetUploadLimit(IGuild guild)
{
return guild.PremiumTier switch
{
PremiumTier.Tier2 => 50ul * 1000000,
PremiumTier.Tier3 => 100ul * 1000000,
_ => 8ul * 1000000
};
}
#endregion #endregion
#region Bans #region Bans

View File

@@ -99,6 +99,9 @@ namespace Discord.Rest
}; };
} }
} }
/// <inheritdoc/>
public ulong MaxUploadLimit
=> GuildHelper.GetUploadLimit(this);
/// <inheritdoc /> /// <inheritdoc />
public NsfwLevel NsfwLevel { get; private set; } public NsfwLevel NsfwLevel { get; private set; }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -201,6 +201,9 @@ namespace Discord.WebSocket
}; };
} }
} }
/// <inheritdoc/>
public ulong MaxUploadLimit
=> GuildHelper.GetUploadLimit(this);
/// <summary> /// <summary>
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild.
/// </summary> /// </summary>