@@ -6,6 +6,7 @@ import dev.slne.surf.chat.api.processor.PostChatProcessor
66import dev.slne.surf.chat.bukkit.ai.OpenAiService
77import dev.slne.surf.chat.bukkit.ai.openAiService
88import dev.slne.surf.chat.bukkit.config.aiModerationConfig
9+ import dev.slne.surf.chat.bukkit.plugin
910import dev.slne.surf.chat.bukkit.redis.event.TeamMessageRedisEvent
1011import dev.slne.surf.chat.bukkit.redisApi
1112import dev.slne.surf.chat.bukkit.util.appendBotIcon
@@ -104,100 +105,105 @@ object AiModerationPostChatProcessor : PostChatProcessor {
104105 classification : OpenAiService .ClassificationResult
105106 ) {
106107 val senderUuid = messageContext.messageData.sender.uuid
107- sendWebhook(URI .create(aiModerationConfig.webhookUrl).toURL()) {
108- name(" Arty AI Moderation" )
109- avatar(aiModerationConfig.webhookAvatarUrl)
110- embed {
111- thumbnail {
112- url(" https://mc-heads.net/avatar/$senderUuid " )
113- }
114- title(" Chat Nachricht moderiert" )
115-
116- when (classification.action) {
117- OpenAiService .ClassificationAction .SILENT_FLAG -> {
118- content(" Nachricht wurde als unangemessen markiert — bitte überprüfen und ggf. handeln" )
119108
109+ runCatching {
110+ sendWebhook(URI .create(aiModerationConfig.webhookUrl).toURL()) {
111+ name(" Arty AI Moderation" )
112+ avatar(aiModerationConfig.webhookAvatarUrl)
113+ embed {
114+ thumbnail {
115+ url(" https://mc-heads.net/avatar/$senderUuid " )
120116 }
117+ title(" Chat Nachricht moderiert" )
121118
122- OpenAiService . ClassificationAction . DELETE -> {
123- content( " Die Chat Nachricht wurde gelöscht. " )
124- }
119+ when (classification.action) {
120+ OpenAiService . ClassificationAction . SILENT_FLAG -> {
121+ content( " Nachricht wurde als unangemessen markiert — bitte überprüfen und ggf. handeln " )
125122
126- OpenAiService .ClassificationAction .MUTE -> {
127- content(" Die Chat Nachricht wurde gelöscht und der Absender wurde für 7 Tage stumm geschaltet — bitte überprüfen" )
128- }
123+ }
129124
130- else -> Unit
131- }
125+ OpenAiService .ClassificationAction .DELETE -> {
126+ content(" Die Chat Nachricht wurde gelöscht." )
127+ }
132128
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
129+ OpenAiService .ClassificationAction .MUTE -> {
130+ content(" Die Chat Nachricht wurde gelöscht und der Absender wurde für 7 Tage stumm geschaltet — bitte überprüfen" )
131+ }
132+
133+ else -> Unit
139134 }
140- )
141135
142- field {
143- name(" Nachricht" )
144- value(messageContext.messageData.plainMessage)
145- inline = false
146- }
136+ color(
137+ when (classification.action) {
138+ OpenAiService .ClassificationAction .SILENT_FLAG -> Color .YELLOW
139+ OpenAiService .ClassificationAction .DELETE -> Color .RED
140+ OpenAiService .ClassificationAction .MUTE -> Color .MAGENTA
141+ else -> Color .WHITE
142+ }
143+ )
147144
148- field {
149- name(" Kategorien" )
150- value(buildString {
151- classification.flaggedScores.object2DoubleEntrySet()
152- .sortedByDescending { it.doubleValue }
153- .forEachIndexed { index, entry ->
154- val category = entry.key
155- val scorePercent = entry.doubleValue * 100
156- append(" - ${category.name} (${" %.2f" .format(scorePercent)} %)" )
157- if (index != classification.flaggedScores.size - 1 ) {
158- append(" \n " )
159- }
160- }
161- })
162- inline = false
163- }
145+ field {
146+ name(" Nachricht" )
147+ value(messageContext.messageData.plainMessage)
148+ inline = false
149+ }
164150
165- field {
166- name(" Sender" )
167- value(" [${nameOrUuid(senderUuid)} ](${aiModerationConfig.userPanelPrefix}$senderUuid )" )
168- inline = true
169- }
151+ field {
152+ name(" Kategorien" )
153+ value(buildString {
154+ classification.flaggedScores.object2DoubleEntrySet()
155+ .sortedByDescending { it.doubleValue }
156+ .forEachIndexed { index, entry ->
157+ val category = entry.key
158+ val scorePercent = entry.doubleValue * 100
159+ append(" - ${category.name} (${" %.2f" .format(scorePercent)} %)" )
160+ if (index != classification.flaggedScores.size - 1 ) {
161+ append(" \n " )
162+ }
163+ }
164+ })
165+ inline = false
166+ }
170167
171- val receiverUuid = messageContext.messageData.receiver?.uuid
172- if (receiverUuid != null ) {
173168 field {
174- name(" Receiver " )
175- value(" [${nameOrUuid(receiverUuid )} ](${aiModerationConfig.userPanelPrefix}$receiverUuid )" )
169+ name(" Sender " )
170+ value(" [${nameOrUuid(senderUuid )} ](${aiModerationConfig.userPanelPrefix}$senderUuid )" )
176171 inline = true
177172 }
178- }
179173
180- field {
181- name(" Server" )
182- value(messageContext.messageData.server.internalName)
183- inline = true
184- }
174+ val receiverUuid = messageContext.messageData.receiver?.uuid
175+ if (receiverUuid != null ) {
176+ field {
177+ name(" Receiver" )
178+ value(" [${nameOrUuid(receiverUuid)} ](${aiModerationConfig.userPanelPrefix}$receiverUuid )" )
179+ inline = true
180+ }
181+ }
185182
186- val channel = messageContext.messageData.channel
187- if (channel != null ) {
188183 field {
189- name(" Channel " )
190- value(channel )
184+ name(" Server " )
185+ value(messageContext.messageData.server.internalName )
191186 inline = true
192187 }
193- }
194188
195- field {
196- name(" Type" )
197- value(messageContext.messageData.type.name)
198- inline = true
189+ val channel = messageContext.messageData.channel
190+ if (channel != null ) {
191+ field {
192+ name(" Channel" )
193+ value(channel)
194+ inline = true
195+ }
196+ }
197+
198+ field {
199+ name(" Type" )
200+ value(messageContext.messageData.type.name)
201+ inline = true
202+ }
199203 }
200204 }
205+ }.onFailure {
206+ plugin.logger.warning(" Failed to send webhook for AI moderation!" )
201207 }
202208 }
203209
0 commit comments