Skip to content

Commit

Permalink
more Patreon docs and update Docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
compujuckel committed May 8, 2023
1 parent bae02df commit 05392ac
Show file tree
Hide file tree
Showing 10 changed files with 7,933 additions and 7,049 deletions.
2,070 changes: 1,316 additions & 754 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "2.1.0",
"@docusaurus/preset-classic": "2.1.0",
"@docusaurus/core": "2.4.0",
"@docusaurus/preset-classic": "2.4.0",
"@mdx-js/react": "^1.6.22",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
Expand Down
Binary file modified patreon-docs/assettoserver-hub/assets/discord_setup_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
220 changes: 216 additions & 4 deletions patreon-docs/assettoserver-hub/discord.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description: Discord features built into AssettoServer Hub

AssettoServer Hub includes a Discord bot with the following features:
* Linking Steam accounts to Discord accounts
* Mapping Discord roles to AssettoServer user groups
* Mapping Discord roles to AssettoServer user groups (example use case: Whitelist based on Discord role)
* Mapping AssettoServer user groups to Discord roles (example use case: Assign role based on Timing Leaderboard)
* Posting server status in Discord

## Setup
Expand All @@ -21,7 +22,7 @@ This is what the bot page should look like:

* On the left side, click on `OAuth2` and select `URL Generator`.
* Under `Scopes`, make sure that `bot` is checked.
* Under `Bot Permissions`, make sure that `Send Messages` is checked.
* Under `Bot Permissions`, make sure that `Send Messages` and `Manage Roles` is checked.

The page should look like this:

Expand Down Expand Up @@ -58,7 +59,11 @@ Administrators can manage linked Steam accounts with the following commands:
* `/steam-link find-steam` - Find SteamID that belongs to a Discord user
* `/steam-link unlink` - Unlink a SteamID from a Discord user

## User Groups
## Audit Log

AssettoServer Hub can post some events (linking Steam account, create/delete User Group, ...) to a specific channel. Use the `/audit-log set` command to activate this feature.

## Discord User Groups

Discord roles can be linked to AssettoServer user groups. This can be used for whitelist, reserved slots, etc.

Expand All @@ -83,6 +88,213 @@ For more general info on user groups see [this page](./user-groups).

To remove a group simply use the `/user-group remove` command.

## User Group Mappings

Existing AssettoServer user groups can be mapped to a Discord role. This can be used for example with [PatreonTimingPlugin](../plugins/PatreonTimingPlugin) to assign roles based on the Timing leaderboard.

### Example: Assign Role based on Timing Leaderboard

First, add a new Timing User Group to your `configuration.yml`:

```yaml title="configuration.yml (AssettoServer Hub)"
TimingUserGroups:
- Name: timing_top3
PostFilter: CarRank <= 3
```
This will create a user group called `timing_top3` that contains all players with a Top 3 leaderboard time for any car.

Next, use the `/user-group map` command to map this user group to a Discord role. For example `/user-group map timing_top3 <your role>`:

![](./assets/user_group_mapping_1.png)

Now all users with a linked Steam account and a Top 3 leaderboard time will get this role.

<details>
<summary>Custom Timing Filters (Advanced)</summary>
<p>

The criteria for creating Timing roles are fully customizable using SQL WHERE clauses. The following query is executed to determine Timing user groups:

```sql
WITH ranks AS (SELECT tle.player_id,
c.model AS CarModel,
tle.created_at AS CreatedAt,
t.name AS Track,
ts.name AS Stage,
MIN(tle.lap_time) AS LapTime,
RANK() OVER (
PARTITION BY t.track_id, ts.timing_stage_id, tle.car_id
ORDER BY tle.lap_time
) AS CarRank,
RANK() OVER (
PARTITION BY t.track_id, ts.timing_stage_id
ORDER BY tle.lap_time
) AS Rank
FROM timing_leaderboard_entries tle
JOIN cars c on c.car_id = tle.car_id
JOIN timing_leaderboards tl on tl.timing_leaderboard_id = tle.timing_leaderboard_id
JOIN timing_stages ts on ts.timing_stage_id = tle.timing_stage_id
JOIN tracks t on ts.track_id = t.track_id
WHERE tle.valid = true
--#preFilter
GROUP BY t.name, ts.name, tle.car_id, tle.player_id
ORDER BY t.name, ts.name, MIN(tle.lap_time))
SELECT DISTINCT r.player_id
FROM ranks r
--#postFilter
```

The database used is [SQLite](https://www.sqlite.org/lang_select.html).

`PreFilter` and `PostFilter` can be used to customize the resulting user group. For example, the following configuration will create a user group only for lap times set in the current month:

```yaml title="configuration.yml (AssettoServer Hub)"
TimingUserGroups:
- Name: timing_top5_month
PreFilter: tle.created_at > date('now', 'start of month')
PostFilter: CarRank <= 5
```

</p>
</details>

### Example: Assign Role based on Safety Rating

[PatreonSafetyRatingPlugin](../plugins/PatreonSafetyRatingPlugin) can create a user group for each rank, for example:

```yaml title="configuration.yml (AssettoServer Hub)"
SafetyRatingRanks:
- Color: '#00FF00'
MinimumRating: 4
Name: A
# highlight-next-line
UserGroupName: safety_a
- Color: null
MinimumRating: 1
Name: B
- Color: '#FF0000'
MinimumRating: 0
Name: C
```

This will create a user group called `safety_a` for each driver with an A rating. You can now use `/user-group map safety_a <your role>` to assign a role to all drivers with an A rating.

### Remove Mapping

A mapping can be removed with the `/user-group unmap` command.

## Server Status

tbd
AssettoServer Hub can create Server Status messages for your game servers that look like this:

![](./assets/server_status_1.png)

For this, add a new section to your `configuration.yml`, for example:

```yaml title="configuration.yml (AssettoServer Hub)"
DiscordServerStatus:
# Name that will be used for creating the embed
srp-eu:
# Embed title
Title: Europe - Germany
# Embed thumbnail
ThumbnailUrl: https://flagcdn.com/w160/eu.png
# Embed template - read below for more info
Template: default
# Embed color
Color: "#003399"
# List of game servers to query
Servers:
# Server name
- Name: EU 1 - No Traffic
# Server address in format ip:httpPort
Address: 65.108.176.35:8081
- Name: EU 2 - Traffic
Address: 65.108.176.35:8082
- Name: EU 3 - Traffic - Slow Cars
Address: 65.108.176.35:8083
- Name: EU 4 - Traffic
Address: 65.108.176.35:8085
- Name: EU PTB - Traffic
Address: 65.108.176.35:8084
```

The server status message can be posted by using the command `/server-status <name>` in a channel, for example `/server-status srp-eu`.

<details>
<summary>Custom Templates (Advanced)</summary>
<p>

Embeds are customizable using [Scriban templates](https://github.com/scriban/scriban).

AssettoServer Hub includes the following default template:

```
{{ for server in servers }}
**{{ server.alias }}**
{{ if server.online -}}
:green_circle: Online · Players: `{{ server.clients | string.pad_left 2 }}/{{ server.max_clients | string.pad_left 2 }}` · Time: `{{ server.time }}` · **[Join]({{ server.invite }})**
{{- else -}}
:red_circle: Offline
{{- end }}
{{ end }}
```

You can add custom templates by adding a `DiscordServerStatusTemplates` section to your `configuration.yml`. Example:

```yaml title="configuration.yml (AssettoServer Hub)"
DiscordServerStatusTemplates:
emoji: |
{{ for server in servers }}
**{{ server.alias }}**
{{
if server.online
fill = server.clients / server.max_clients
if fill < 0.5
":green_circle:"
else if fill < 0.75
":yellow_circle:"
else
":orange_circle:"
end
" Online"
else
":red_circle: Offline"
end
timeSplit = server.time | string.split ":"
hours = timeSplit[0] | string.to_int
minutes = timeSplit[1] | string.to_int
if minutes >= 45
hours += 1
end
hours = hours % 12
if hours == 0
hours = 12
end
if minutes > 15 && minutes < 45
minutes = 30
else
minutes = ""
end
clockEmoji = ":clock" + hours + minutes + ":"
}} · :busts_in_silhouette: `{{ server.clients | string.pad_left 2 }}/{{ server.max_clients | string.pad_left 2 }}` · {{ clockEmoji }} `{{ server.time }}` · **[Join]({{ server.invite }})**
{{ end }}
```
This template will change color of the green dot depending on the number of players on the server and show the correct time with a clock emoji.
You can then use this template by setting `Template: emoji` in your `DiscordServerStatus` configuration.

Output of the template:

![](./assets/server_status_2.png)

</p>
</details>
24 changes: 9 additions & 15 deletions patreon-docs/assettoserver-hub/user-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ By default, three user groups (`default_admins`, `default_blacklist`, `default_w

## Adding local User Groups
To create a new file-based user group, just add it to `extra_cfg.yml`:
```yaml
```yaml title="extra_cfg.yml (AssettoServer)"
UserGroups:
default_admins: admins.txt
default_blacklist: blacklist.txt
Expand All @@ -25,7 +25,7 @@ User groups can be synchronized to multiple game servers via AssettoServer Hub.

### Hub Setup
In `configuration.yml` of your Hub, add a new file-based user group:
```yaml
```yaml title="configuration.yml (AssettoServer Hub)"
FileBasedUserGroups:
- Name: my_group
Path: my_group.txt
Expand All @@ -37,41 +37,35 @@ When specifying a user group, prefix the user group name in `extra_cfg.yml` with
### Examples

#### Synchronizing Blacklist
AssettoServer Hub configuration (`configuration.yml`):
```yaml
```yaml title="configuration.yml (AssettoServer Hub)"
FileBasedUserGroups:
- Name: blacklist
Path: blacklist.txt
```

AssettoServer configuration (`extra_cfg.yml`):
```yaml
```yaml title="extra_cfg.yml (AssettoServer)"
BlacklistUserGroup: +blacklist
```

#### Synchronizing Whitelist
AssettoServer Hub configuration (`configuration.yml`):
```yaml
```yaml title="configuration.yml (AssettoServer Hub)"
FileBasedUserGroups:
- Name: whitelist
Path: whitelist.txt
```

AssettoServer configuration (`extra_cfg.yml`):
```yaml
BlacklistUserGroup: +whitelist
```yaml title="extra_cfg.yml (AssettoServer)"
WhitelistUserGroup: +whitelist
```

#### Synchronizing Reserved Slots
AssettoServer Hub configuration (`configuration.yml`):
```yaml
```yaml title="configuration.yml (AssettoServer Hub)"
FileBasedUserGroups:
- Name: reserved
Path: reserved.txt
```

AssettoServer configuration (`extra_cfg.yml`, under `!PatreonReservedSlotsConfiguration`):
```yaml
```yaml title="extra_cfg.yml (AssettoServer, under !PatreonReservedSlotsConfiguration)"
ReservedEntryListSlotsUserGroup: +reserved
# and/or
ReservedSlotsUserGroup: +reserved
Expand Down
31 changes: 31 additions & 0 deletions patreon-docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ title: Changelog
---
## Patreon Plugins

### v0.0.36

#### PatreonDynamicSkinsPlugin (new!)

#### PatreonChatRolesPlugin (new!)

#### PatreonRaceChallengePlugin

* Fix chat commands not working

#### PatreonSafetyRatingPlugin

* Fix chat name colors on CSP <0.1.79

#### PatreonSpeedTrapPlugin

* Fix speed trap flash not showing for other players

### v0.0.35

#### PatreonSafetyRatingPlugin (new!)
Expand Down Expand Up @@ -47,6 +65,19 @@ Please review the [documentation](./plugins/PatreonReservedSlotsPlugin.md).

## AssettoServer Hub

### v0.0.6

#### Timing Leaderboard
* Add filter for current month
* Add API
* Do not show tracks with no lap times set

#### Discord
* Add Discord Bot
* Add ability to link Steam account to Discord account
* Add Discord role mappings
* Add server status embeds

### v0.0.5

* Add race challenge leaderboard
Expand Down
Loading

0 comments on commit 05392ac

Please sign in to comment.