# exports

Use these exports to integrate sl-bot with other scripts.

***

## Helper Functions

### getLicense

Get player's license identifier.

```lua
local license = exports['sl-bot']:getLicense(source)
```

***

### getDiscord

Get player's Discord identifier.

```lua
local discord = exports['sl-bot']:getDiscord(source)
-- Returns: "discord:123456789012345678" or nil
```

***

### getSteam

Get player's Steam identifier.

```lua
local steam = exports['sl-bot']:getSteam(source)
-- Returns: "steam:110000123456789" or nil
```

***

### getIdentifier

Get player's primary identifier (license).

```lua
local identifier = exports['sl-bot']:getIdentifier(source)
```

***

### isPlayerOnline

Check if a player is online.

```lua
local isOnline = exports['sl-bot']:isPlayerOnline(playerId)
-- Returns: true/false
```

***

### getPlayerNameSafe

Get player name safely.

```lua
local name = exports['sl-bot']:getPlayerNameSafe(source)
-- Returns: player name or "Unknown"
```

***

## Ban System

### banPlayer

Ban a player programmatically.

```lua
local result = exports['sl-bot']:banPlayer(target, duration, reason, admin)
```

| Parameter | Type          | Description                              |
| --------- | ------------- | ---------------------------------------- |
| target    | string/number | Player ID or license                     |
| duration  | string        | Duration (e.g., '7d', '1M')              |
| reason    | string        | Ban reason                               |
| admin     | string        | Admin name (optional, default: 'System') |

Returns: `{ success = true/false, message = "..." }`

Example:

```lua
-- Ban online player
local result = exports['sl-bot']:banPlayer(1, '7d', 'Cheating', 'AntiCheat')
if result.success then
    print('Banned:', result.message)
end

-- Ban offline by license
exports['sl-bot']:banPlayer('abc123def456', '30d', 'Ban evading')
```

***

### unbanPlayer

Unban a player.

```lua
local result = exports['sl-bot']:unbanPlayer(target, admin)
```

| Parameter | Type   | Description           |
| --------- | ------ | --------------------- |
| target    | string | Ban ID or license     |
| admin     | string | Admin name (optional) |

Example:

```lua
exports['sl-bot']:unbanPlayer('ABC12345', 'Admin')
```

***

### checkBan

Check if a player has an active ban.

```lua
local result = exports['sl-bot']:checkBan(target, admin)
```

Example:

```lua
local result = exports['sl-bot']:checkBan('license:abc123')
if result.success then
    print(result.message)  -- Ban info or "No active ban"
end
```

***

### getBansList

Get list of all active bans.

```lua
local result = exports['sl-bot']:getBansList(admin)
```

***

## Warning System

### warnPlayer

Warn a player.

```lua
local result = exports['sl-bot']:warnPlayer(playerId, reason, admin)
```

| Parameter | Type   | Description           |
| --------- | ------ | --------------------- |
| playerId  | number | Online player ID      |
| reason    | string | Warning reason        |
| admin     | string | Admin name (optional) |

Example:

```lua
local result = exports['sl-bot']:warnPlayer(1, 'VDM', 'AutoMod')
```

***

### getPlayerWarnings

Get player's warnings.

```lua
local result = exports['sl-bot']:getPlayerWarnings(target, admin)
```

| Parameter | Type          | Description          |
| --------- | ------------- | -------------------- |
| target    | string/number | Player ID or license |

Example:

```lua
local result = exports['sl-bot']:getPlayerWarnings(1)
print(result.message)
```

***

### removeWarning

Remove a specific warning.

```lua
local result = exports['sl-bot']:removeWarning(warnId, admin)
```

Example:

```lua
exports['sl-bot']:removeWarning(15, 'Admin')
```

***

### clearPlayerWarnings

Clear all warnings for a player.

```lua
local result = exports['sl-bot']:clearPlayerWarnings(target, admin)
```

Example:

```lua
exports['sl-bot']:clearPlayerWarnings(1, 'Admin')
```

***

## Player Management

### kickPlayer

Kick a player from the server.

```lua
local result = exports['sl-bot']:kickPlayer(playerId, reason, admin)
```

Example:

```lua
exports['sl-bot']:kickPlayer(1, 'AFK too long', 'System')
```

***

### kickAllPlayers

Kick all players from the server.

```lua
local result = exports['sl-bot']:kickAllPlayers(reason, admin)
```

Example:

```lua
exports['sl-bot']:kickAllPlayers('Server maintenance')
```

***

### getOnlinePlayers

Get list of online players.

```lua
local result = exports['sl-bot']:getOnlinePlayers(admin)
```

***

## Execute Command

### execute

Execute any bot command programmatically.

```lua
local resultJson = exports['sl-bot']:execute(command, args, admin)
local result = json.decode(resultJson)
```

| Parameter | Type   | Description                   |
| --------- | ------ | ----------------------------- |
| command   | string | Command name (without prefix) |
| args      | table  | Command arguments             |
| admin     | string | Admin name                    |

Examples:

```lua
-- Ban command
local result = exports['sl-bot']:execute('ban', {'1', '7d', 'Cheating'}, 'System')

-- Kick command
local result = exports['sl-bot']:execute('kick', {'1', 'AFK'}, 'System')

-- Get players
local result = exports['sl-bot']:execute('players', {}, 'System')
```

***

## Usage Examples

### Anti-Cheat Integration

```lua
-- When cheat detected
RegisterNetEvent('anticheat:detected', function(reason)
    local src = source
    exports['sl-bot']:banPlayer(src, '999y', 'AntiCheat: ' .. reason, 'AntiCheat')
end)
```

### Warning System Integration

```lua
-- Auto-warn for rule breaking
RegisterCommand('report', function(source, args)
    local targetId = tonumber(args[1])
    local reason = table.concat(args, ' ', 2)
    
    local result = exports['sl-bot']:warnPlayer(targetId, reason, 'Report System')
    
    -- Check warning count and auto-ban if too many
    local warnings = exports['sl-bot']:getPlayerWarnings(targetId)
    -- Handle result...
end)
```

### Ban Check on Player Action

```lua
-- Check if player is banned before allowing action
local function isPlayerBanned(license)
    local result = exports['sl-bot']:checkBan(license)
    return result.message:find('Ban ID:') ~= nil
end
```
