[+] API for bot to ban user from ranking board

pull/50/head
Clansty 2024-08-06 15:13:54 +08:00
parent 17a0209c8c
commit 7ee4c14fae
No known key found for this signature in database
GPG Key ID: 3A6BE8BAF2EDE134
2 changed files with 48 additions and 0 deletions

View File

@ -133,5 +133,9 @@ server.error.whitelabel.enabled=false
aqua-net.frontier.enabled=false
aqua-net.frontier.ftk=0x00
## APIs for bot management
aqua-net.bot.enabled=true
aqua-net.bot.secret=hunter2
## OpenAI Settings (For content moderation)
aqua-net.openai.api-key=sk-1234567890abcdef1234567890abcdef

View File

@ -0,0 +1,44 @@
package icu.samnyan.aqua.net
import ext.*
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.general.service.CardService
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController
@Configuration
@ConfigurationProperties(prefix = "aqua-net.bot")
class BotProps {
var enabled: Boolean = false
var secret: String = ""
}
@RestController
@ConditionalOnProperty("aqua-net.frontier.enabled", havingValue = "true")
@API("/api/v2/bot")
class BotController(
val cardService: CardService,
val us: AquaUserServices,
val props: BotProps
) {
fun Str.checkSecret() {
if (this != props.secret) 403 - "Invalid Secret"
}
@PostMapping("/ranking-ban")
@Doc("Register a new card by access code", "Card information")
suspend fun rankingBan(@RP secret: Str, @RP username: Str) {
secret.checkSecret()
us.cardByName(username) { card ->
card.rankingBanned = true
cardService.cardRepo.save(card)
SUCCESS
}
}
}