Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
15.3 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

import {
	BASE64_IMAGE_MAX_SIZE,
	MAX_BIO_LENGTH,
	MAX_SCREEN_SHARE_BITRATE_CEILING,
	MIN_SCREEN_SHARE_BITRATE_CEILING,
} from '@fluxer/constants/src/LimitConstants';

export const LIMIT_KEYS = [
	'avatar_max_size',
	'emoji_max_size',
	'feature_animated_avatar',
	'feature_animated_banner',
	'feature_custom_discriminator',
	'feature_custom_notification_sounds',
	'feature_early_access',
	'feature_global_expressions',
	'feature_guild_create',
	'feature_higher_video_quality',
	'feature_per_guild_profiles',
	'feature_voice_entrance_sounds',
	'guild_visit_history_days_unverified',
	'max_attachments_per_message',
	'max_bio_length',
	'max_bookmarks',
	'max_bot_attachment_file_size',
	'max_channels_per_category',
	'max_custom_backgrounds',
	'max_embeds_per_message',
	'max_favorite_meme_tags',
	'max_favorite_memes',
	'max_group_dm_recipients',
	'max_group_dms_per_user',
	'max_guild_channels',
	'max_guild_emojis',
	'max_guild_emojis_animated_more',
	'max_guild_emojis_animated',
	'max_guild_emojis_static_more',
	'max_guild_emojis_static',
	'max_guild_invites',
	'max_guild_members',
	'max_guild_roles',
	'max_guild_stickers_more',
	'max_guild_stickers',
	'max_guild_visits',
	'max_guilds',
	'max_attachment_file_size',
	'max_message_length',
	'max_private_channels_per_user',
	'max_reactions_per_message',
	'max_relationships',
	'max_screen_share_bitrate',
	'max_users_per_message_reaction',
	'max_voice_message_duration',
	'max_webhooks_per_channel',
	'max_webhooks_per_guild',
	'sticker_max_size',
] as const;

export type LimitKey = (typeof LIMIT_KEYS)[number];
export type LimitScope = 'user' | 'guild' | 'both';

export const LIMIT_KEY_SCOPES: Record<LimitKey, LimitScope> = {
	avatar_max_size: 'user',
	emoji_max_size: 'guild',
	feature_animated_avatar: 'user',
	feature_animated_banner: 'user',
	feature_custom_discriminator: 'user',
	feature_custom_notification_sounds: 'user',
	feature_early_access: 'user',
	feature_global_expressions: 'user',
	feature_guild_create: 'user',
	feature_higher_video_quality: 'user',
	feature_per_guild_profiles: 'user',
	feature_voice_entrance_sounds: 'user',
	guild_visit_history_days_unverified: 'user',
	max_attachments_per_message: 'both',
	max_bio_length: 'user',
	max_bookmarks: 'user',
	max_bot_attachment_file_size: 'both',
	max_channels_per_category: 'guild',
	max_custom_backgrounds: 'user',
	max_embeds_per_message: 'both',
	max_favorite_meme_tags: 'user',
	max_favorite_memes: 'user',
	max_group_dm_recipients: 'user',
	max_group_dms_per_user: 'user',
	max_guild_channels: 'guild',
	max_guild_emojis: 'guild',
	max_guild_emojis_animated_more: 'guild',
	max_guild_emojis_animated: 'guild',
	max_guild_emojis_static_more: 'guild',
	max_guild_emojis_static: 'guild',
	max_guild_invites: 'guild',
	max_guild_members: 'guild',
	max_guild_roles: 'guild',
	max_guild_stickers_more: 'guild',
	max_guild_stickers: 'guild',
	max_guild_visits: 'user',
	max_guilds: 'user',
	max_attachment_file_size: 'both',
	max_message_length: 'both',
	max_private_channels_per_user: 'user',
	max_reactions_per_message: 'guild',
	max_relationships: 'user',
	max_screen_share_bitrate: 'user',
	max_users_per_message_reaction: 'guild',
	max_voice_message_duration: 'both',
	max_webhooks_per_channel: 'guild',
	max_webhooks_per_guild: 'guild',
	sticker_max_size: 'guild',
};

type LimitCategory = 'messages' | 'guilds' | 'channels' | 'expressions' | 'files' | 'social' | 'media' | 'features';

interface LimitKeyMetadata {
	key: LimitKey;
	label: string;
	description: string;
	category: LimitCategory;
	scope: LimitScope;
	isToggle: boolean;
	unit?: 'bytes' | 'count' | 'bps';
	min?: number;
	max?: number;
}

export const LIMIT_CATEGORY_LABELS: Record<LimitCategory, string> = {
	messages: 'Messages',
	guilds: 'Guilds',
	channels: 'Channels',
	expressions: 'Expressions & Stickers',
	files: 'Files & Attachments',
	social: 'Social & Private',
	media: 'Voice & Video',
	features: 'Feature Toggles',
};
export const LIMIT_KEY_METADATA: Record<LimitKey, LimitKeyMetadata> = {
	max_message_length: {
		key: 'max_message_length',
		label: 'Max Message Length',
		description: 'Maximum number of characters per message',
		category: 'messages',
		scope: 'both',
		isToggle: false,
		unit: 'count',
	},
	max_attachments_per_message: {
		key: 'max_attachments_per_message',
		label: 'Max Attachments per Message',
		description: 'Maximum number of file attachments per message',
		category: 'messages',
		scope: 'both',
		isToggle: false,
		unit: 'count',
	},
	max_embeds_per_message: {
		key: 'max_embeds_per_message',
		label: 'Max Embeds per Message',
		description: 'Maximum number of embeds per message',
		category: 'messages',
		scope: 'both',
		isToggle: false,
		unit: 'count',
	},
	max_reactions_per_message: {
		key: 'max_reactions_per_message',
		label: 'Max Reactions per Message',
		description: 'Maximum distinct reactions per message',
		category: 'messages',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_users_per_message_reaction: {
		key: 'max_users_per_message_reaction',
		label: 'Max Users per Reaction',
		description: 'Maximum users who can use the same reaction on a message',
		category: 'messages',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_voice_message_duration: {
		key: 'max_voice_message_duration',
		label: 'Max Voice Message Duration',
		description: 'Maximum duration in seconds for voice message recordings',
		category: 'messages',
		scope: 'both',
		isToggle: false,
		unit: 'count',
	},
	max_guilds: {
		key: 'max_guilds',
		label: 'Max Guilds',
		description: 'Maximum number of guilds a user can join',
		category: 'guilds',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_guild_visits: {
		key: 'max_guild_visits',
		label: 'Max Community Visits',
		description:
			'Maximum communities a user can visit at once without joining. Accounts without a confirmed email get half',
		category: 'guilds',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	guild_visit_history_days_unverified: {
		key: 'guild_visit_history_days_unverified',
		label: 'Visit History Days Without Email',
		description: 'How many days of message history accounts without a confirmed email can read while visiting',
		category: 'guilds',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_guild_members: {
		key: 'max_guild_members',
		label: 'Max Guild Members',
		description: 'Maximum members per guild',
		category: 'guilds',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_roles: {
		key: 'max_guild_roles',
		label: 'Max Guild Roles',
		description: 'Maximum roles per guild',
		category: 'guilds',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_invites: {
		key: 'max_guild_invites',
		label: 'Max Guild Invites',
		description: 'Maximum active invites per guild',
		category: 'guilds',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_channels: {
		key: 'max_guild_channels',
		label: 'Max Guild Channels',
		description: 'Maximum channels per guild',
		category: 'channels',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_channels_per_category: {
		key: 'max_channels_per_category',
		label: 'Max Channels per Category',
		description: 'Maximum channels per category',
		category: 'channels',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_webhooks_per_channel: {
		key: 'max_webhooks_per_channel',
		label: 'Max Webhooks per Channel',
		description: 'Maximum webhooks per channel',
		category: 'channels',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_webhooks_per_guild: {
		key: 'max_webhooks_per_guild',
		label: 'Max Webhooks per Guild',
		description: 'Maximum webhooks per guild',
		category: 'channels',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_emojis: {
		key: 'max_guild_emojis',
		label: 'Max Emojis',
		description: 'Maximum total emojis per guild',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_emojis_static: {
		key: 'max_guild_emojis_static',
		label: 'Max Emojis (Legacy Static)',
		description: 'Compatibility alias for older clients; emoji limits are enforced as a shared total',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_emojis_animated: {
		key: 'max_guild_emojis_animated',
		label: 'Max Emojis (Legacy Animated)',
		description: 'Compatibility alias for older clients; emoji limits are enforced as a shared total',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_emojis_static_more: {
		key: 'max_guild_emojis_static_more',
		label: 'Max Emojis (Legacy Static More)',
		description: 'Compatibility alias for older clients; emoji limits are enforced as a shared total',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_emojis_animated_more: {
		key: 'max_guild_emojis_animated_more',
		label: 'Max Emojis (Legacy Animated More)',
		description: 'Compatibility alias for older clients; emoji limits are enforced as a shared total',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_stickers: {
		key: 'max_guild_stickers',
		label: 'Max Stickers',
		description: 'Maximum stickers per guild',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	max_guild_stickers_more: {
		key: 'max_guild_stickers_more',
		label: 'Max Stickers (Legacy More)',
		description: 'Compatibility alias for older clients; sticker limits are enforced as one shared total',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'count',
	},
	emoji_max_size: {
		key: 'emoji_max_size',
		label: 'Emoji Max Size',
		description: 'Maximum file size for emoji uploads',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'bytes',
		min: 1,
		max: BASE64_IMAGE_MAX_SIZE,
	},
	sticker_max_size: {
		key: 'sticker_max_size',
		label: 'Sticker Max Size',
		description: 'Maximum file size for sticker uploads',
		category: 'expressions',
		scope: 'guild',
		isToggle: false,
		unit: 'bytes',
		min: 1,
		max: BASE64_IMAGE_MAX_SIZE,
	},
	max_attachment_file_size: {
		key: 'max_attachment_file_size',
		label: 'Max Attachment File Size',
		description:
			'Maximum size of each attachment file. The upload relay limit FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES applies to each upload part, so it only matters for files above about 10 GB',
		category: 'files',
		scope: 'both',
		isToggle: false,
		unit: 'bytes',
	},
	max_bot_attachment_file_size: {
		key: 'max_bot_attachment_file_size',
		label: 'Max Bot Attachment File Size',
		description:
			'Maximum size of each attachment file a bot uploads. A bot gets the lower of this and Max Attachment File Size',
		category: 'files',
		scope: 'both',
		isToggle: false,
		unit: 'bytes',
		min: 0,
	},
	avatar_max_size: {
		key: 'avatar_max_size',
		label: 'Avatar Max Size',
		description: 'Maximum file size for avatar uploads',
		category: 'files',
		scope: 'user',
		isToggle: false,
		unit: 'bytes',
		min: 1,
		max: BASE64_IMAGE_MAX_SIZE,
	},
	max_custom_backgrounds: {
		key: 'max_custom_backgrounds',
		label: 'Max Custom Backgrounds',
		description: 'Maximum custom profile backgrounds',
		category: 'files',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_relationships: {
		key: 'max_relationships',
		label: 'Max Relationships',
		description: 'Maximum friends/blocked users',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_private_channels_per_user: {
		key: 'max_private_channels_per_user',
		label: 'Max Private Channels',
		description: 'Maximum DM channels per user',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_group_dms_per_user: {
		key: 'max_group_dms_per_user',
		label: 'Max Group DMs',
		description: 'Maximum group DMs a user can own',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_group_dm_recipients: {
		key: 'max_group_dm_recipients',
		label: 'Max Group DM Members',
		description: 'Maximum members per group DM',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_bio_length: {
		key: 'max_bio_length',
		label: 'Max Bio Length',
		description: 'Maximum characters in user bio',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
		min: 0,
		max: MAX_BIO_LENGTH,
	},
	max_bookmarks: {
		key: 'max_bookmarks',
		label: 'Max Bookmarks',
		description: 'Maximum bookmarked messages',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_favorite_memes: {
		key: 'max_favorite_memes',
		label: 'Max Favorite Memes',
		description: 'Maximum favorited memes',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_favorite_meme_tags: {
		key: 'max_favorite_meme_tags',
		label: 'Max Favorite Meme Tags',
		description: 'Maximum meme tags to track',
		category: 'social',
		scope: 'user',
		isToggle: false,
		unit: 'count',
	},
	max_screen_share_bitrate: {
		key: 'max_screen_share_bitrate',
		label: 'Max Screen Share Bitrate',
		description: 'Highest video bitrate a screen share can send, in bits per second',
		category: 'media',
		scope: 'user',
		isToggle: false,
		unit: 'bps',
		min: MIN_SCREEN_SHARE_BITRATE_CEILING,
		max: MAX_SCREEN_SHARE_BITRATE_CEILING,
	},
	feature_animated_avatar: {
		key: 'feature_animated_avatar',
		label: 'Animated Avatar',
		description: 'Allow animated avatar uploads',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_animated_banner: {
		key: 'feature_animated_banner',
		label: 'Animated Banner',
		description: 'Allow animated banner uploads',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_custom_discriminator: {
		key: 'feature_custom_discriminator',
		label: 'Custom Discriminator',
		description: 'Allow custom discriminator selection',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_custom_notification_sounds: {
		key: 'feature_custom_notification_sounds',
		label: 'Custom Notification Sounds',
		description: 'Allow custom notification sounds',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_early_access: {
		key: 'feature_early_access',
		label: 'Early Access',
		description: 'Access to beta features',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_global_expressions: {
		key: 'feature_global_expressions',
		label: 'Global Expressions',
		description: 'Use expressions across all guilds',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_guild_create: {
		key: 'feature_guild_create',
		label: 'Community Creation Access',
		description: 'Create communities while the instance restricts community creation',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_higher_video_quality: {
		key: 'feature_higher_video_quality',
		label: 'Higher Video Quality',
		description: 'Access to higher video streaming quality',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_per_guild_profiles: {
		key: 'feature_per_guild_profiles',
		label: 'Per-Guild Profiles',
		description: 'Different profile per guild',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
	feature_voice_entrance_sounds: {
		key: 'feature_voice_entrance_sounds',
		label: 'Voice Entrance Sounds',
		description: 'Play sound when joining voice',
		category: 'features',
		scope: 'user',
		isToggle: true,
	},
};