# Ban System

## Config

```lua
Config.BanSystem = {
    enable = true, -- Set to true if you want to use this Feature

    discordLog = true, -- Set true to enable DiscordLogs // Add Webhook Link in server/functions/bansystem.lua
    botColor = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
    botName = "MSK Scripts",
    botAvatar = "https://i.imgur.com/PizJGsh.png",

    commands = {
        enable = true,
        groups = {'superadmin', 'admin', 'god'},
        ban = 'banPlayer',
        unban = 'unbanPlayer'
    }
}
```

## MSK.BanPlayer

This will ban a player

<mark style="color:red;">**Parameters**</mark>\
**playerId** - `number` - The ServerId of the player who banned someone - ***Optional***\
**targetId** - `number` - The ServerId of the player who gets banned\
**time** - `string` - The Time until the player gets unbanned\
**reason** - `string` - The Reason why the player gets banned

<mark style="color:blue;">**Description**</mark>\
For the Parameter ***time*** you can set different types.

* 1M = 1 Minute
* 1H = 1 Hour
* 1D = 1 Day
* 1W = 1 Week
* P = Permanent

```lua
MSK.BanPlayer(playerId, targetId, time, reason)

-- Player gets banned for 2 days for reason cheating
MSK.BanPlayer(playerId, targetId, '2D', 'cheating')

-- Player gets permanetly banned for reason cheating
.BanPlayer(playerId, targetId, 'P', 'cheating')

-- If you execute this from the server
MSK.BanPlayer(0, targetId, '2D', 'cheating')

-- As an Export:
exports.msk_core:BanPlayer(playerId, targetId, time, reason)
```

## MSK.UnbanPlayer

This will unban a player

<mark style="color:red;">**Parameters**</mark>\
**banId** - `number` - The BanId

<mark style="color:blue;">**Description**</mark>\
The Parameter ***banId*** is the id in msk\_bansystem database

```lua
MSK.UnbanPlayer(banId)

-- As an Export:
exports.msk_core:UnbanPlayer(banId)
```

## MSK.IsPlayerBanned

This will check if the given player is banned

<mark style="color:red;">**Parameters**</mark>\
**playerId** - `number` - The ServerId of the player

<mark style="color:green;">**Returns**</mark>\
**isBanned** - `boolean or table` - If the player is banned or not\
**isExpired** - `boolean or nil` - If the Ban is expired or not

<mark style="color:blue;">**Description**</mark>\
**O**n a future update we implement that you can search for specific identifiers like license, discord, etc.

```lua
local isBanned, isExpired = MSK.IsPlayerBanned(playerId)

if isBanned and not isExpired then
    -- Player is banned
    print(isBanned.banId, isBanned.ids, isBanned.reason, isBanned.time, isBanned.from)
elseif isBanned and isExpired then
    -- Player was banned but the Ban is expired
    print(isBanned.banId, isBanned.ids, isBanned.reason, isBanned.time, isBanned.from)
else
    -- Player is not banned
end

-- As an Export:
local isBanned, isExpired = exports.msk_core:IsPlayerBanned(playerId)
```

## Commands

### /banPlayer

<mark style="color:red;">**Parameters**</mark>\
**targetId** - `number` - The ServerId of the player who gets banned\
**time** - `string` - The Time until the player gets unbanned\
**reason** - `string` - The Reason why the player gets banned - **Optional**, default: `'Unknown reason'`

<mark style="color:blue;">**Description**</mark>\
For the Parameter ***time*** you can set different types:

* 1M = 1 Minute
* 1H = 1 Hour
* 1D = 1 Day
* 1W = 1 Week
* P = Permanent

```lua
/banPlayer playerId time reason

-- Example 1: Player with ID 1 gets banned for 2 days for cheating
/banPlayer 1 2D "Cheating"

-- Example 2: Player with ID 1 gets permanently banned for cheating
/banPlayer 1 P "Cheating"
```

### /unbanPlayer

<mark style="color:red;">**Parameters**</mark>\
**banId** - `number` - The BanId

```lua
/unbanPlayer banId

-- Example: BanId 5 gets unbanned
/unbanPlayer 5
```
