Skip to content

Commit

Permalink
feat: release version 2.2.0 (#79)
Browse files Browse the repository at this point in the history
feat(gh-73): `/get-server-details` now lists up to 5 recent errors (#74)
feat: add optional support for DarkAtra/v-rising-discord-bot-companion ([ae17f2d](ae17f2d))
fix: ignore casing when sorting the player list ([fdf0d70](fdf0d70))
chore(deps): update dependency org.mockito.kotlin:mockito-kotlin to v5
chore(deps): update dependency org.springframework.boot:spring-boot-starter-parent to v3.1.0
  • Loading branch information
DarkAtra authored Jun 7, 2023
1 parent 9ca4ae1 commit 6a23f85
Show file tree
Hide file tree
Showing 40 changed files with 940 additions and 332 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- next
paths:
- 'src/**'
- 'pom.xml'
Expand Down
71 changes: 43 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,75 @@ Lists all server status monitors.

Adds a server to the status monitor.

| Parameter | Description | Required |
|------------------------------|--------------------------------------------------------------------------------------------------------------------------|----------|
| `server-hostname` | The hostname of the server to add a status monitor for. | `true` |
| `server-query-port` | The query port of the server to add a status monitor for. | `true` |
| `display-server-description` | Whether or not to display the v rising server description on discord. Defaults to not displaying the server description. | `false` |
| Parameter | Description | Required | Default value |
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------------|
| `server-hostname` | The hostname of the server to add a status monitor for. | `true` | `null` |
| `server-query-port` | The query port of the server to add a status monitor for. | `true` | `null` |
| `server-api-hostname` | The hostname to use when querying the server's api. Use `~` to set the value to `null`. This is required to integrate with [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) | `false` | `null` |
| `server-api-port` | The api port of the server. Use `-1` to set the value to `null`. This is required to integrate with [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) | `false` | `null` |
| `display-server-description` | Whether or not to display the v rising server description on discord. | `false` | `true` |
| `display-player-gear-level` | Whether or not to display each player's gear level. Only honored if the `server-api-port` is set. | `false` | `true` |

### `/update-server`

Updates the given server status monitor. Only the parameters that were specified when the command was executed are updated. All other parameters remain
untouched.

| Parameter | Description | Required |
|------------------------------|-----------------------------------------------------------------------|----------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` |
| `server-hostname` | The hostname of the server to add a status monitor for. | `false` |
| `server-query-port` | The query port of the server to add a status monitor for. | `false` |
| `status` | The status of the server status monitor. Either ACTIVE or INACTIVE. | `false` |
| `display-server-description` | Whether or not to display the v rising server description on discord. | `false` |
| Parameter | Description | Required | Default value |
|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` | `null` |
| `server-hostname` | The hostname of the server to add a status monitor for. | `false` | `null` |
| `server-query-port` | The query port of the server to add a status monitor for. | `false` | `null` |
| `server-api-hostname` | The hostname to use when querying the server's api. Use `~` to set the value to `null`. This is required to integrate with [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) | `false` | `null` |
| `server-api-port` | The api port of the server. Use `-1` to set the value to `null`. This is required to integrate with [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) | `false` | `null` |
| `status` | The status of the server status monitor. Either `ACTIVE` or `INACTIVE`. | `false` | `null` |
| `display-server-description` | Whether or not to display the v rising server description on discord. | `false` | `null` |
| `display-player-gear-level` | Whether or not to display each player's gear level. Only honored if the `server-api-port` is set. | `false` | `null` |

### `/remove-server`

Removes a server from the status monitor.

| Parameter | Description | Required |
|----------------------------|--------------------------------------|----------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` |
| Parameter | Description | Required | Default value |
|----------------------------|--------------------------------------|----------|---------------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` | `null` |

### `/get-server-details`

Gets all the configuration details for the specified server.

| Parameter | Description | Required |
|----------------------------|--------------------------------------|----------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` |
| Parameter | Description | Required | Default value |
|----------------------------|--------------------------------------|----------|---------------|
| `server-status-monitor-id` | The id of the server status monitor. | `true` | `null` |

## Configuration Properties

| Property | Type | Description | Default value |
|---------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `bot.discord-bot-token` | String | The token for the discord bot. You can find this in the [discord developer portal](https://discord.com/developers/applications). | `null` |
| `bot.database-path` | Path | The path to the database file. Should be overwritten when running inside a docker container. | `./bot.db` |
| `bot.database-username` | String | The username for the database. | `v-rising-discord-bot` |
| `bot.database-password` | String | The password for the database. | `null` |
| `bot.update-delay` | Duration | The delay between status monitor updates. At least 30 seconds. | `1m` |
| `bot.max-failed-attempts` | Int | The maximum amount of attempts to be made until a server is disabled. Use `0` if you don't want to use this feature. | `0` |
| Property | Type | Description | Default value |
|--------------------------------|----------|----------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `bot.discord-bot-token` | String | The token for the discord bot. You can find this in the [discord developer portal](https://discord.com/developers/applications). | `null` |
| `bot.database-path` | Path | The path to the database file. Should be overwritten when running inside a docker container. | `./bot.db` |
| `bot.database-username` | String | The username for the database. | `v-rising-discord-bot` |
| `bot.database-password` | String | The password for the database. | `null` |
| `bot.update-delay` | Duration | The delay between status monitor updates. At least 30 seconds. | `1m` |
| `bot.max-failed-attempts` | Int | The maximum number of attempts to be made until a server is disabled. Use `0` if you don't want to use this feature. | `0` |
| `bot.max-recent-errors` | Int | The maximum number of errors to keep for debugging via `/get-server-details`. Use `0` if you don't want to use this feature. | `5` |
| `bot.max-characters-per-error` | Int | The maximum number of errors to keep for debugging via `/get-server-details`. Use `0` if you don't want to use this feature. | `200` |

## [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) Integration

The v-rising-discord-bot is able to fetch additional data about players, such as the gear level, if
the [v-rising-discord-bot-companion](https://github.com/DarkAtra/v-rising-discord-bot-companion) is installed on the v rising server and the api port of that
server is accessible from where the bot runs. I highly recommend **not** exposing the api port to the internet.

## How to run it yourself using docker-compose

Find the latest docker image [here](https://github.com/DarkAtra/v-rising-discord-bot/pkgs/container/v-rising-discord-bot). If you prefer to use the JVM based version of this bot, remove the `-native` suffix from the `image` name in the example below.
Find the latest docker image [here](https://github.com/DarkAtra/v-rising-discord-bot/pkgs/container/v-rising-discord-bot). If you prefer to use the JVM based
version of this bot, remove the `-native` suffix from the `image` name in the example below.

```yaml
services:
v-rising-discord-bot:
image: ghcr.io/darkatra/v-rising-discord-bot:2.1.5-native
image: ghcr.io/darkatra/v-rising-discord-bot:2.2.0-native
command: -Dagql.nativeTransport=false
mem_reservation: 128M
mem_limit: 256M
Expand Down
23 changes: 20 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.1.0</version>
<relativePath/>
</parent>

<groupId>de.darkatra</groupId>
<artifactId>v-rising-discord-bot</artifactId>
<version>2.1.5</version>
<version>2.2.0-next.11</version>
<packaging>jar</packaging>

<licenses>
Expand Down Expand Up @@ -41,7 +41,8 @@
<potassium-nitrite.version>3.4.4</potassium-nitrite.version>
<commons-validator.version>1.7</commons-validator.version>

<mockito-kotlin.version>4.1.0</mockito-kotlin.version>
<mockito-kotlin.version>5.0.0</mockito-kotlin.version>
<wiremock.version>3.0.0-beta-8</wiremock.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -71,6 +72,16 @@
<optional>true</optional>
</dependency>

<!-- Jackson -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>

<!-- Discord -->
<dependency>
<groupId>dev.kord</groupId>
Expand Down Expand Up @@ -127,6 +138,12 @@
<artifactId>kotlinx-coroutines-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/de/darkatra/vrising/discord/Bot.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package de.darkatra.vrising.discord

import de.darkatra.vrising.discord.clients.botcompanion.model.CharacterResponse
import de.darkatra.vrising.discord.command.Command
import de.darkatra.vrising.discord.command.ValidationException
import de.darkatra.vrising.discord.migration.DatabaseMigrationService
import de.darkatra.vrising.discord.migration.Schema
import de.darkatra.vrising.discord.serverstatus.ServerStatusMonitorService
import de.darkatra.vrising.discord.serverstatus.model.Error
import de.darkatra.vrising.discord.serverstatus.model.ServerStatusMonitor
import dev.kord.core.Kord
import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.event.gateway.ReadyEvent
Expand Down Expand Up @@ -32,7 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean
@SpringBootApplication
@ImportRuntimeHints(BotRuntimeHints::class)
@EnableConfigurationProperties(BotProperties::class)
@RegisterReflectionForBinding(BotProperties::class, Schema::class, ServerStatusMonitor::class)
@RegisterReflectionForBinding(BotProperties::class, Schema::class, ServerStatusMonitor::class, Error::class, CharacterResponse::class)
class Bot(
private val database: Nitrite,
private val botProperties: BotProperties,
Expand Down Expand Up @@ -95,7 +99,7 @@ class Bot(
taskRegistrar.addFixedDelayTask(IntervalTask({
if (isReady.get() && kord.isActive) {
runBlocking {
serverStatusMonitorService.updateServerStatusMonitor(kord)
serverStatusMonitorService.updateServerStatusMonitors(kord)
}
}
}, botProperties.updateDelay, Duration.ofSeconds(5)))
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/de/darkatra/vrising/discord/BotProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ class BotProperties {
@field:Min(0)
@field:NotNull
var maxFailedAttempts: Int = 0

@field:Min(0)
@field:NotNull
var maxRecentErrors: Int = 5

@field:Min(1)
@field:NotNull
var maxCharactersPerError: Int = 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BotRuntimeHints : RuntimeHintsRegistrar {
// required by nitrite to create a database with password
hints.serialization().registerType(TypeReference.of("org.dizitart.no2.Security\$UserCredential"))
// required by nitrite for serialization
hints.serialization().registerType(TypeReference.of("java.util.ArrayList"))
hints.serialization().registerType(Attributes::class.java)
hints.serialization().registerType(AtomicBoolean::class.java)
hints.serialization().registerType(TypeReference.of("java.lang.Boolean"))
Expand Down
71 changes: 0 additions & 71 deletions src/main/kotlin/de/darkatra/vrising/discord/ServerStatusMonitor.kt

This file was deleted.

Loading

0 comments on commit 6a23f85

Please sign in to comment.