Add MaxUploadLimit to guilds (#2001)
This commit is contained in:
@@ -354,6 +354,11 @@ namespace Discord
|
||||
/// </returns>
|
||||
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>
|
||||
/// Modifies this guild.
|
||||
/// </summary>
|
||||
|
||||
@@ -372,6 +372,16 @@ namespace Discord.Rest
|
||||
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
|
||||
if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue)
|
||||
{
|
||||
|
||||
@@ -124,6 +124,15 @@ namespace Discord.Rest
|
||||
{
|
||||
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
|
||||
|
||||
#region Bans
|
||||
|
||||
@@ -99,6 +99,9 @@ namespace Discord.Rest
|
||||
};
|
||||
}
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ulong MaxUploadLimit
|
||||
=> GuildHelper.GetUploadLimit(this);
|
||||
/// <inheritdoc />
|
||||
public NsfwLevel NsfwLevel { get; private set; }
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -201,6 +201,9 @@ namespace Discord.WebSocket
|
||||
};
|
||||
}
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public ulong MaxUploadLimit
|
||||
=> GuildHelper.GetUploadLimit(this);
|
||||
/// <summary>
|
||||
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user