Skip to content

Commit

Permalink
chore: Major cleanup of the API and internals
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Nov 15, 2024
1 parent 1037ced commit 73ffe13
Show file tree
Hide file tree
Showing 30 changed files with 711 additions and 616 deletions.
38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Are you sick of players turning your awesome server into a NSFW gallery ?
Do you wish to bring back your logic displays without the fear of seing anime girls in questionable situations ?
Well, worry no more, xpdustry cooked another banger plugin for just this situation.

Introducing **nohorny 2**, the successor of [BMI](https://github.com/L0615T1C5-216AC-9437/BannedMindustryImage).
Introducing **nohorny**, the successor of [BMI](https://github.com/L0615T1C5-216AC-9437/BannedMindustryImage).
This mindustry plugin automatically tracks logic displays and canvases and process them when needed
with the anti-nsfw API of your choice.

Expand All @@ -25,7 +25,7 @@ This plugin requires at least :

- Mindustry v146

- [KotlinRuntime](https://github.com/xpdustry/kotlin-runtime) v3.2.0-k.1.9.23
- [KotlinRuntime](https://github.com/xpdustry/kotlin-runtime) latest

## Usage

Expand All @@ -35,13 +35,6 @@ Then, go to the created directory `config/mods/nohorny` and create a file named

Now you can set up the analyzer of your choice:

- **[ModerateContent](https://moderatecontent.com/)**: Incredibly generous free tier with 10000 free requests per month.

```yaml
analyzer:
moderate-content-token: xxx
```
- **[SightEngine](https://sightengine.com/)**: Very nice service with 2000 free operations per month. Also supports gore detection.

```yaml
Expand All @@ -64,9 +57,6 @@ Now you can set up the analyzer of your choice:
analyzer: Debug
```

> There is also the in-game command `nohorny-tracker-debug` that allows you to check
if displays and canvases are properly tracked.

Once you chose your analyzer, load your changes using the command `nohorny-reload` in the console, and enjoy,
the plugin will automatically ban players that have built structures at `UNSAFE` Rating.

Expand Down Expand Up @@ -99,19 +89,23 @@ In `config.yaml`:
# Whether nohorny should automatically ban players when nsfw is detected,
# set to false if you want to handle that yourself
auto-ban: true
# The minimum number of draw instructions in a logic processor to be part of a cluster
minimum-instruction-count: 100
# The delay between the last logic or canvas block built and the analysis step,
# lower it on servers with fast build time such as sandbox
processing-delay: 5s
# The minimum number of canvases in a cluster to be eligible for processing,
# relatively high since you a lot of canvases are needed for a clear picture
minimum-canvas-cluster-size: 9
# The minimum number of logic processors in a cluster to be eligible for processing
minimum-processor-count: 5
# The search radius of linked logic processors around a cluster of logic displays,
# tweak depending on the average size of your server maps
processor-search-radius: 10
# Display tracker configuration
displays:
# The minimum number of draw instructions in a logic processor to be part of a cluster
minimum-instruction-count: 100
# The minimum number of logic processors in a cluster to be eligible for processing
minimum-processor-count: 5
# The search radius of linked logic processors around a cluster of logic displays,
# tweak depending on the average size of your server maps
processor-search-radius: 10
# Canvas tracker configuration
canvases:
# The minimum number of canvases in a cluster to be eligible for processing,
# relatively high since you a lot of canvases are needed for a clear picture
minimum-canvas-cluster-size: 9
```

## Building
Expand Down
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ toxopid {
repositories {
mavenCentral()
anukeXpdustry()
maven("https://maven.xpdustry.com/releases") {
name = "xpdustry-releases"
mavenContent { releasesOnly() }
}
}

dependencies {
Expand Down
4 changes: 0 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ pluginManagement {
name = "xpdustry-releases"
mavenContent { releasesOnly() }
}
maven("https://maven.xpdustry.com/snapshots") {
name = "xpdustry-snapshots"
mavenContent { snapshotsOnly() }
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/com/xpdustry/nohorny/NoHornyAutoBan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
*/
package com.xpdustry.nohorny

import com.xpdustry.nohorny.analyzer.ImageAnalyzerEvent
import com.xpdustry.nohorny.analyzer.ImageInformation
import com.xpdustry.nohorny.extension.onEvent
import com.xpdustry.nohorny.geometry.ImmutablePoint
import com.xpdustry.nohorny.image.NoHornyImage
import com.xpdustry.nohorny.image.NoHornyInformation
import com.xpdustry.nohorny.image.analyzer.ImageAnalyzerEvent
import kotlinx.coroutines.Dispatchers
import mindustry.Vars
import mindustry.content.Blocks
import mindustry.gen.Call
Expand All @@ -37,10 +39,10 @@ import mindustry.world.blocks.logic.CanvasBlock
import mindustry.world.blocks.logic.LogicBlock
import mindustry.world.blocks.logic.LogicDisplay

internal class NoHornyAutoBan(private val plugin: NoHornyPlugin) : NoHornyListener {
internal class NoHornyAutoBan(private val plugin: NoHornyPlugin) : NoHornyListener("Auto Ban", Dispatchers.Default) {
override fun onInit() {
onEvent<ImageAnalyzerEvent> { (result, cluster, _, author) ->
if (result.rating == ImageInformation.Rating.UNSAFE &&
if (result.rating == NoHornyInformation.Rating.UNSAFE &&
plugin.config.autoBan &&
author != null
) {
Expand Down
29 changes: 3 additions & 26 deletions src/main/kotlin/com/xpdustry/nohorny/NoHornyConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,20 @@
*/
package com.xpdustry.nohorny

import com.sksamuel.hoplite.Secret
import com.xpdustry.nohorny.analyzer.ImageInformation
import com.xpdustry.nohorny.image.analyzer.AnalyzerConfig
import com.xpdustry.nohorny.tracker.CanvasesConfig
import com.xpdustry.nohorny.tracker.DisplaysConfig
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

internal data class NoHornyConfig(
val analyzer: Analyzer = Analyzer.None,
val analyzer: AnalyzerConfig = AnalyzerConfig.None,
val autoBan: Boolean = true,
val processingDelay: Duration = 5.seconds,
val displays: DisplaysConfig = DisplaysConfig(),
val canvases: CanvasesConfig = CanvasesConfig(),
) {
init {
require(processingDelay > Duration.ZERO) { "processingDelay must be above 0" }
}

sealed interface Analyzer {
data object None : Analyzer

data object Debug : Analyzer

data class SightEngine(
val sightEngineUser: String,
val sightEngineSecret: Secret,
val unsafeThreshold: Float = 0.55F,
val warningThreshold: Float = 0.4F,
val kinds: List<ImageInformation.Kind> = listOf(ImageInformation.Kind.NUDITY),
) : Analyzer {
init {
require(unsafeThreshold >= 0) { "unsafeThreshold cannot be lower than 0" }
require(warningThreshold >= 0) { "warningThreshold cannot be lower than 0" }
require(kinds.isNotEmpty()) { "models cannot be empty" }
}
}

data class Fallback(val primary: Analyzer, val secondary: Analyzer) : Analyzer
require(processingDelay >= 1.seconds) { "processingDelay must be above 1 second" }
}
}
124 changes: 0 additions & 124 deletions src/main/kotlin/com/xpdustry/nohorny/NoHornyImageRenderer.kt

This file was deleted.

21 changes: 16 additions & 5 deletions src/main/kotlin/com/xpdustry/nohorny/NoHornyListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@
*/
package com.xpdustry.nohorny

import arc.util.CommandHandler
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import org.slf4j.LoggerFactory
import kotlin.coroutines.CoroutineContext

internal interface NoHornyListener {
fun onInit() = Unit
private val NoHornyCoroutineExceptionHandler =
CoroutineExceptionHandler { _, throwable ->
LoggerFactory.getLogger(NoHornyPlugin::class.java).error("An uncaught error occurred", throwable)
}

fun onServerCommandsRegistration(handler: CommandHandler) = Unit
internal abstract class NoHornyListener(name: String, context: CoroutineContext) {
protected val scope =
CoroutineScope(
context + SupervisorJob() + CoroutineName("NoHorny $name Scope") + NoHornyCoroutineExceptionHandler,
)

fun onClientCommandsRegistration(handler: CommandHandler) = Unit
open fun onInit() = Unit
}
Loading

0 comments on commit 73ffe13

Please sign in to comment.