Packages@robojs/xp
config
Variable: config
const config: {
get: (guildId, options?) => Promise<GuildConfig>;
getDefault: () => GuildConfig;
getGlobal: () => Promise<GlobalConfig>;
set: (guildId, partial, options?) => Promise<GuildConfig>;
setGlobal: (config) => Promise<void>;
validate: (config) => {
errors: string[];
valid: boolean;
};
};Configuration management for XP system
Provides comprehensive configuration management with validation, defaults, and guild-specific overrides. All configuration changes are persisted to Flashcore immediately.
Features:
- Guild-specific and global configuration
- Automatic validation with detailed error messages
- Standard defaults for easy setup
- Role rewards, multipliers, and No-XP zones
- Cache invalidation when using setGlobal
Config Precedence (highest to lowest):
- Guild-specific config (via
config.set()) - Global config defaults (via
config.setGlobal()) - System defaults
Type declaration
| Name | Type | Default value | Description |
|---|---|---|---|
get | (guildId, options?) => Promise<GuildConfig> | getConfig | Get guild configuration with all defaults applied |
getDefault | () => GuildConfig | getDefaultConfig | Get default configuration |
getGlobal | () => Promise<GlobalConfig> | getGlobalConfig | Get global configuration defaults |
set | (guildId, partial, options?) => Promise<GuildConfig> | setConfig | Update guild configuration with validation |
setGlobal | (config) => Promise<void> | setGlobalConfig | Set global configuration defaults |
validate | (config) => { errors: string[]; valid: boolean; } | validateConfig | Validate configuration object |
Examples
Basic Configuration
import { config } from '@robojs/xp'
// Get guild config (creates with defaults if not found)
const guildConfig = await config.get('123456789012345678')
console.log(`Cooldown: ${guildConfig.cooldownSeconds}s`)
// Update guild config
await config.set('123456789012345678', {
cooldownSeconds: 120, // 2 minutes between XP awards
xpRate: 1.5 // +50% XP boost for entire guild
})Role Rewards Configuration
import { config } from '@robojs/xp'
// Configure role rewards with stack mode (users keep all qualifying roles)
await config.set('123456789012345678', {
roleRewards: [
{ level: 5, roleId: '234567890123456789' },
{ level: 10, roleId: '345678901234567890' },
{ level: 25, roleId: '456789012345678901' }
],
rewardsMode: 'stack', // Users accumulate all roles
removeRewardsOnLoss: false // Keep roles even if user loses XP
})
// Configure with replace mode (only highest level role)
await config.set('123456789012345678', {
rewardsMode: 'replace' // Users get only their highest qualifying role
})XP Multipliers (Premium Features)
import { config } from '@robojs/xp'
// Set up multipliers for premium users
await config.set('123456789012345678', {
multipliers: {
user: {
'premiumUserId1': 1.5, // +50% XP boost
'vipUserId2': 2.0 // +100% XP boost (double XP)
},
role: {
'boosterRoleId': 1.2, // +20% for server boosters
'donorRoleId': 1.3 // +30% for donors
}
}
})
// Multipliers stack: user with both roles gets 1.2 * 1.3 = 1.56x totalNo-XP Zones Configuration
import { config } from '@robojs/xp'
// Configure roles and channels to exclude from XP gains
await config.set('123456789012345678', {
noXpRoles: [
'mutedRoleId', // Muted users don't gain XP
'botRoleId' // Bots don't gain XP
],
noXpChannels: [
'spamChannelId', // Spam channels don't award XP
'botCommandsChannelId' // Command channels excluded
]
})Validation Before Updates
import { config } from '@robojs/xp'
// Validate config before applying
const userConfig = {
cooldownSeconds: -10, // Invalid: negative value
xpRate: 'invalid' // Invalid: not a number
}
const validation = config.validate(userConfig)
if (!validation.valid) {
console.error('Config validation failed:', validation.errors)
// Errors: ['cooldownSeconds must be non-negative', 'xpRate must be a number']
} else {
await config.set(guildId, userConfig)
}Global Defaults for Bot Networks
import { config } from '@robojs/xp'
// Set global defaults for all guilds
await config.setGlobal({
cooldownSeconds: 90, // Default 90s cooldown for all guilds
xpRate: 1.0,
rewardsMode: 'stack'
})
// Individual guilds can still override
await config.set('specificGuildId', {
cooldownSeconds: 60 // This guild uses 60s instead of global 90s
})Default Configuration Setup
import { config } from '@robojs/xp'
// Default config uses standard settings - no setup needed!
const defaultConfig = config.getDefault()
console.log(defaultConfig)
// {
// cooldownSeconds: 60,
// xpRate: 1.0,
// rewardsMode: 'stack',
// removeRewardsOnLoss: false,
// ...
// }
// Get guild config with defaults applied
const guildConfig = await config.get('123456789012345678')
// Returns default configuration if not customizedRemarks
- Config changes are validated before persistence
- Global config updates invalidate caches for consistency
- Default settings: 60s cooldown, 15-25 XP/msg, stack mode
- Multipliers stack multiplicatively (user * role * guild)
