forked from jmug/stoatchat
refactor(core/config): move limits to 'global' key
This commit is contained in:
@@ -46,21 +46,41 @@ webhooks_enabled = false
|
|||||||
|
|
||||||
[features.limits]
|
[features.limits]
|
||||||
|
|
||||||
[features.limits.default]
|
[features.limits.global]
|
||||||
outgoing_friend_requests = 10
|
|
||||||
|
|
||||||
group_size = 100
|
group_size = 100
|
||||||
bots = 5
|
|
||||||
message_length = 2000
|
|
||||||
message_embeds = 5
|
|
||||||
message_replies = 5
|
message_replies = 5
|
||||||
message_attachments = 5
|
|
||||||
message_reactions = 20
|
message_reactions = 20
|
||||||
servers = 100
|
|
||||||
server_emoji = 100
|
server_emoji = 100
|
||||||
server_roles = 200
|
server_roles = 200
|
||||||
server_channels = 200
|
server_channels = 200
|
||||||
|
|
||||||
|
new_user_days = 3
|
||||||
|
|
||||||
|
[features.limits.new_user]
|
||||||
|
outgoing_friend_requests = 5
|
||||||
|
|
||||||
|
bots = 2
|
||||||
|
message_length = 2000
|
||||||
|
message_embeds = 5
|
||||||
|
message_attachments = 5
|
||||||
|
servers = 100
|
||||||
|
|
||||||
|
attachment_size = 20000000
|
||||||
|
avatar_size = 4000000
|
||||||
|
background_size = 6000000
|
||||||
|
icon_size = 2500000
|
||||||
|
banner_size = 6000000
|
||||||
|
emoji_size = 500000
|
||||||
|
|
||||||
|
[features.limits.default]
|
||||||
|
outgoing_friend_requests = 10
|
||||||
|
|
||||||
|
bots = 5
|
||||||
|
message_length = 2000
|
||||||
|
message_embeds = 5
|
||||||
|
message_attachments = 5
|
||||||
|
servers = 100
|
||||||
|
|
||||||
attachment_size = 20000000
|
attachment_size = 20000000
|
||||||
avatar_size = 4000000
|
avatar_size = 4000000
|
||||||
background_size = 6000000
|
background_size = 6000000
|
||||||
|
|||||||
@@ -105,21 +105,27 @@ pub struct Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct FeaturesLimits {
|
pub struct GlobalLimits {
|
||||||
pub outgoing_friend_requests: usize,
|
|
||||||
|
|
||||||
pub group_size: usize,
|
pub group_size: usize,
|
||||||
pub bots: usize,
|
|
||||||
pub message_length: usize,
|
|
||||||
pub message_replies: usize,
|
pub message_replies: usize,
|
||||||
pub message_attachments: usize,
|
|
||||||
pub message_embeds: usize,
|
|
||||||
pub message_reactions: usize,
|
pub message_reactions: usize,
|
||||||
pub servers: usize,
|
|
||||||
pub server_emoji: usize,
|
pub server_emoji: usize,
|
||||||
pub server_roles: usize,
|
pub server_roles: usize,
|
||||||
pub server_channels: usize,
|
pub server_channels: usize,
|
||||||
|
|
||||||
|
pub new_user_days: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct FeaturesLimits {
|
||||||
|
pub outgoing_friend_requests: usize,
|
||||||
|
|
||||||
|
pub bots: usize,
|
||||||
|
pub message_length: usize,
|
||||||
|
pub message_attachments: usize,
|
||||||
|
pub message_embeds: usize,
|
||||||
|
pub servers: usize,
|
||||||
|
|
||||||
pub attachment_size: usize,
|
pub attachment_size: usize,
|
||||||
pub avatar_size: usize,
|
pub avatar_size: usize,
|
||||||
pub background_size: usize,
|
pub background_size: usize,
|
||||||
@@ -130,6 +136,9 @@ pub struct FeaturesLimits {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
pub struct FeaturesLimitsCollection {
|
pub struct FeaturesLimitsCollection {
|
||||||
|
pub global: GlobalLimits,
|
||||||
|
|
||||||
|
pub new_user: FeaturesLimits,
|
||||||
pub default: FeaturesLimits,
|
pub default: FeaturesLimits,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
|||||||
@@ -201,9 +201,9 @@ impl Channel {
|
|||||||
update_server: bool,
|
update_server: bool,
|
||||||
) -> Result<Channel> {
|
) -> Result<Channel> {
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
if server.channels.len() > config.features.limits.default.server_channels {
|
if server.channels.len() > config.features.limits.global.server_channels {
|
||||||
return Err(create_error!(TooManyChannels {
|
return Err(create_error!(TooManyChannels {
|
||||||
max: config.features.limits.default.server_channels,
|
max: config.features.limits.global.server_channels,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -263,9 +263,9 @@ impl Channel {
|
|||||||
data.users.insert(owner_id.to_string());
|
data.users.insert(owner_id.to_string());
|
||||||
|
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
if data.users.len() > config.features.limits.default.group_size {
|
if data.users.len() > config.features.limits.global.group_size {
|
||||||
return Err(create_error!(GroupTooLarge {
|
return Err(create_error!(GroupTooLarge {
|
||||||
max: config.features.limits.default.group_size,
|
max: config.features.limits.global.group_size,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,9 +346,9 @@ impl Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
if recipients.len() >= config.features.limits.default.group_size {
|
if recipients.len() >= config.features.limits.global.group_size {
|
||||||
return Err(create_error!(GroupTooLarge {
|
return Err(create_error!(GroupTooLarge {
|
||||||
max: config.features.limits.default.group_size
|
max: config.features.limits.global.group_size
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -288,9 +288,9 @@ impl Message {
|
|||||||
// Verify replies are valid.
|
// Verify replies are valid.
|
||||||
let mut replies = HashSet::new();
|
let mut replies = HashSet::new();
|
||||||
if let Some(entries) = data.replies {
|
if let Some(entries) = data.replies {
|
||||||
if entries.len() > config.features.limits.default.message_replies {
|
if entries.len() > config.features.limits.global.message_replies {
|
||||||
return Err(create_error!(TooManyReplies {
|
return Err(create_error!(TooManyReplies {
|
||||||
max: config.features.limits.default.message_replies,
|
max: config.features.limits.global.message_replies,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,7 +616,7 @@ impl Message {
|
|||||||
pub async fn add_reaction(&self, db: &Database, user: &User, emoji: &str) -> Result<()> {
|
pub async fn add_reaction(&self, db: &Database, user: &User, emoji: &str) -> Result<()> {
|
||||||
// Check how many reactions are already on the message
|
// Check how many reactions are already on the message
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
if self.reactions.len() >= config.features.limits.default.message_reactions
|
if self.reactions.len() >= config.features.limits.global.message_reactions
|
||||||
&& !self.reactions.contains_key(emoji)
|
&& !self.reactions.contains_key(emoji)
|
||||||
{
|
{
|
||||||
return Err(create_error!(InvalidOperation));
|
return Err(create_error!(InvalidOperation));
|
||||||
@@ -781,7 +781,7 @@ impl Interactions {
|
|||||||
if let Some(reactions) = &self.reactions {
|
if let Some(reactions) = &self.reactions {
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::React)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::React)?;
|
||||||
|
|
||||||
if reactions.len() > config.features.limits.default.message_reactions {
|
if reactions.len() > config.features.limits.global.message_reactions {
|
||||||
return Err(create_error!(InvalidOperation));
|
return Err(create_error!(InvalidOperation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ pub async fn create_emoji(
|
|||||||
|
|
||||||
// Check that we haven't hit the emoji limit
|
// Check that we haven't hit the emoji limit
|
||||||
let emojis = db.fetch_emoji_by_parent_id(&server.id).await?;
|
let emojis = db.fetch_emoji_by_parent_id(&server.id).await?;
|
||||||
if emojis.len() >= config.features.limits.default.server_emoji {
|
if emojis.len() >= config.features.limits.global.server_emoji {
|
||||||
return Err(create_error!(TooManyEmoji {
|
return Err(create_error!(TooManyEmoji {
|
||||||
max: config.features.limits.default.server_emoji,
|
max: config.features.limits.global.server_emoji,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ pub async fn create(
|
|||||||
.throw_if_lacking_channel_permission(ChannelPermission::ManageRole)?;
|
.throw_if_lacking_channel_permission(ChannelPermission::ManageRole)?;
|
||||||
|
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
if server.roles.len() >= config.features.limits.default.server_roles {
|
if server.roles.len() >= config.features.limits.global.server_roles {
|
||||||
return Err(create_error!(TooManyRoles {
|
return Err(create_error!(TooManyRoles {
|
||||||
max: config.features.limits.default.server_roles,
|
max: config.features.limits.global.server_roles,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user