handle premium server upload size limits

This commit is contained in:
ouwou 2022-07-09 03:05:48 -04:00
parent 02ce353c6d
commit f95d79129e
3 changed files with 31 additions and 6 deletions

View File

@ -223,16 +223,33 @@ Snowflake ChatWindow::GetActiveChannel() const {
}
bool ChatWindow::OnInputSubmit(ChatSubmitParams data) {
int restriction = BaseAttachmentSizeLimit;
const auto nitro = Abaddon::Get().GetDiscordClient().GetUserData().PremiumType;
auto &discord = Abaddon::Get().GetDiscordClient();
int nitro_restriction = BaseAttachmentSizeLimit;
const auto nitro = discord.GetUserData().PremiumType;
if (!nitro.has_value() || nitro == EPremiumType::None) {
restriction = BaseAttachmentSizeLimit;
nitro_restriction = BaseAttachmentSizeLimit;
} else if (nitro == EPremiumType::NitroClassic) {
restriction = NitroClassicAttachmentSizeLimit;
nitro_restriction = NitroClassicAttachmentSizeLimit;
} else if (nitro == EPremiumType::Nitro) {
restriction = NitroAttachmentSizeLimit;
nitro_restriction = NitroAttachmentSizeLimit;
}
int guild_restriction = BaseAttachmentSizeLimit;
if (const auto channel = discord.GetChannel(m_active_channel); channel.has_value() && channel->GuildID.has_value()) {
if (const auto guild = discord.GetGuild(*channel->GuildID); guild.has_value()) {
if (!guild->PremiumTier.has_value() || guild->PremiumTier == GuildPremiumTier::NONE || guild->PremiumTier == GuildPremiumTier::TIER_1) {
guild_restriction = BaseAttachmentSizeLimit;
} else if (guild->PremiumTier == GuildPremiumTier::TIER_2) {
guild_restriction = BoostLevel2AttachmentSizeLimit;
} else if (guild->PremiumTier == GuildPremiumTier::TIER_3) {
guild_restriction = BoostLevel3AttachmentSizeLimit;
}
}
}
int restriction = std::max(nitro_restriction, guild_restriction);
for (const auto &attachment : data.Attachments) {
const auto info = attachment.File->query_info();
if (info && info->get_size() > restriction) {

View File

@ -16,6 +16,13 @@ enum class GuildApplicationStatus {
UNKNOWN,
};
enum class GuildPremiumTier {
NONE = 0,
TIER_1 = 1,
TIER_2 = 2,
TIER_3 = 3,
};
struct GuildApplicationData {
Snowflake UserID;
Snowflake GuildID;
@ -73,7 +80,7 @@ struct GuildData {
std::optional<std::string> VanityURL; // null
std::optional<std::string> Description; // null
std::optional<std::string> BannerHash; // null
std::optional<int> PremiumTier;
std::optional<GuildPremiumTier> PremiumTier;
std::optional<int> PremiumSubscriptionCount;
std::optional<std::string> PreferredLocale;
std::optional<Snowflake> PublicUpdatesChannelID; // null

View File

@ -738,6 +738,7 @@ std::optional<GuildData> Store::GetGuild(Snowflake id) const {
s->Get(2, r.Icon);
s->Get(5, r.OwnerID);
s->Get(20, r.IsUnavailable);
s->Get(27, r.PremiumTier);
s->Reset();