11package dev.slne.surf.chat.bukkit.processor.post
22
3+ import de.maxbossing.webhookbuilder.sendWebhook
34import dev.slne.surf.chat.api.message.MessageContext
45import dev.slne.surf.chat.api.processor.PostChatProcessor
56import dev.slne.surf.chat.bukkit.ai.OpenAiService
@@ -11,10 +12,9 @@ import dev.slne.surf.chat.bukkit.util.appendBotIcon
1112import dev.slne.surf.chat.core.service.historyService
1213import dev.slne.surf.surfapi.core.api.messages.Colors
1314import dev.slne.surf.surfapi.core.api.messages.adventure.buildText
14- import me.binarywriter.discordwebhooks.data.Image
15- import me.binarywriter.discordwebhooks.data.Webhook
1615import org.bukkit.Bukkit
1716import java.awt.Color
17+ import java.net.URI
1818import java.util.*
1919
2020object AiModerationPostChatProcessor : PostChatProcessor {
@@ -104,47 +104,50 @@ object AiModerationPostChatProcessor : PostChatProcessor {
104104 classification : OpenAiService .ClassificationResult
105105 ) {
106106 val senderUuid = messageContext.messageData.sender.uuid
107- val webhook = Webhook {
108- username = " Arty AI Moderation"
109- avatarUrl = aiModerationConfig.webhookAvatarUrl
107+ sendWebhook( URI .create(aiModerationConfig.webhookUrl).toURL()) {
108+ name( " Arty AI Moderation" )
109+ avatar( aiModerationConfig.webhookAvatarUrl)
110110 embed {
111- image = Image (" https://mc-heads.net/avatar/$senderUuid " )
111+ thumbnail {
112+ url(" https://mc-heads.net/avatar/$senderUuid " )
113+ }
114+ title(" Chat Nachricht moderiert" )
112115
113- title = " Chat Nachricht moderiert"
114116 when (classification.action) {
115117 OpenAiService .ClassificationAction .SILENT_FLAG -> {
116- description =
117- " Nachricht wurde als unangemessen markiert — bitte überprüfen und ggf. handeln "
118+ content( " Nachricht wurde als unangemessen markiert — bitte überprüfen und ggf. handeln " )
119+
118120 }
119121
120122 OpenAiService .ClassificationAction .DELETE -> {
121- description = " Die Chat Nachricht wurde gelöscht."
123+ content( " Die Chat Nachricht wurde gelöscht." )
122124 }
123125
124126 OpenAiService .ClassificationAction .MUTE -> {
125- description =
126- " Die Chat Nachricht wurde gelöscht und der Absender wurde für 7 Tage stumm geschaltet — bitte überprüfen"
127+ content(" Die Chat Nachricht wurde gelöscht und der Absender wurde für 7 Tage stumm geschaltet — bitte überprüfen" )
127128 }
128129
129130 else -> Unit
130131 }
131132
132- color = when (classification.action) {
133- OpenAiService .ClassificationAction .SILENT_FLAG -> Color .YELLOW
134- OpenAiService .ClassificationAction .DELETE -> Color .RED
135- OpenAiService .ClassificationAction .MUTE -> Color .MAGENTA
136- else -> Color .WHITE
137- }
133+ color(
134+ when (classification.action) {
135+ OpenAiService .ClassificationAction .SILENT_FLAG -> Color .YELLOW
136+ OpenAiService .ClassificationAction .DELETE -> Color .RED
137+ OpenAiService .ClassificationAction .MUTE -> Color .MAGENTA
138+ else -> Color .WHITE
139+ }
140+ )
138141
139142 field {
140- name = " Nachricht"
141- value = messageContext.messageData.plainMessage
143+ name( " Nachricht" )
144+ value( messageContext.messageData.plainMessage)
142145 inline = false
143146 }
144147
145148 field {
146- name = " Kategorien"
147- value = buildString {
149+ name( " Kategorien" )
150+ value( buildString {
148151 classification.flaggedScores.object2DoubleEntrySet()
149152 .sortedByDescending { it.doubleValue }
150153 .forEachIndexed { index, entry ->
@@ -155,50 +158,47 @@ object AiModerationPostChatProcessor : PostChatProcessor {
155158 append(" \n " )
156159 }
157160 }
158- }
161+ })
162+ inline = false
159163 }
160164
161165 field {
162- name = " Sender"
163- value =
164- " [${nameOrUuid(senderUuid)} ](${aiModerationConfig.userPanelPrefix}$senderUuid )"
166+ name(" Sender" )
167+ value(" [${nameOrUuid(senderUuid)} ](${aiModerationConfig.userPanelPrefix}$senderUuid )" )
165168 inline = true
166169 }
167170
168171 val receiverUuid = messageContext.messageData.receiver?.uuid
169172 if (receiverUuid != null ) {
170173 field {
171- name = " Receiver"
172- value =
173- " [${nameOrUuid(receiverUuid)} ](${aiModerationConfig.userPanelPrefix}$receiverUuid )"
174+ name(" Receiver" )
175+ value(" [${nameOrUuid(receiverUuid)} ](${aiModerationConfig.userPanelPrefix}$receiverUuid )" )
174176 inline = true
175177 }
176178 }
177179
178180 field {
179- name = " Server"
180- value = messageContext.messageData.server.internalName
181+ name( " Server" )
182+ value( messageContext.messageData.server.internalName)
181183 inline = true
182184 }
183185
184186 val channel = messageContext.messageData.channel
185187 if (channel != null ) {
186188 field {
187- name = " Channel"
188- value = channel
189+ name( " Channel" )
190+ value( channel)
189191 inline = true
190192 }
191193 }
192194
193195 field {
194- name = " Type"
195- value = messageContext.messageData.type.name
196+ name( " Type" )
197+ value( messageContext.messageData.type.name)
196198 inline = true
197199 }
198200 }
199201 }
200-
201- webhook.send(aiModerationConfig.webhookUrl)
202202 }
203203
204204 private fun nameOrUuid (uuid : UUID ): String {
0 commit comments