Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ public interface IGuild : IDeletable, ISnowflakeEntity
/// </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>
Expand Down
10 changes: 10 additions & 0 deletions src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ public static async Task<RestUserMessage> SendFilesAsync(IMessageChannel channel
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)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
{
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
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public int MaxBitrate
};
}
}
/// <inheritdoc/>
public ulong MaxUploadLimit
=> GuildHelper.GetUploadLimit(this);
/// <inheritdoc />
public NsfwLevel NsfwLevel { get; private set; }
/// <inheritdoc />
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public int MaxBitrate
};
}
}
/// <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>
Expand Down