diff --git a/kiszolgalo/build.gradle.kts b/kiszolgalo/build.gradle.kts index 26e9de0..f6d14b6 100644 --- a/kiszolgalo/build.gradle.kts +++ b/kiszolgalo/build.gradle.kts @@ -14,6 +14,7 @@ version = "1.0-SNAPSHOT" repositories { mavenCentral() + maven { url = uri("https://jitpack.io") } } application { @@ -26,6 +27,7 @@ dependencies { implementation("io.ktor:ktor-server-netty:$ktor_version") implementation("io.ktor:ktor-server-sessions:${ktor_version}") implementation("io.ktor:ktor-server-auth:${ktor_version}") + implementation("com.github.BinaryWriter:discord-webhooks:1.0") } tasks.test { diff --git a/kiszolgalo/src/main/kotlin/Main.kt b/kiszolgalo/src/main/kotlin/Main.kt index df23b91..b2e753a 100644 --- a/kiszolgalo/src/main/kotlin/Main.kt +++ b/kiszolgalo/src/main/kotlin/Main.kt @@ -14,6 +14,9 @@ import kotlin.random.nextInt import io.ktor.server.auth.* import io.ktor.server.application.* +import me.binarywriter.discordwebhooks.data.* //discord webhook +import java.awt.Color + //átlagos JAVA alapú fejlesztő val httpPort: Int = System.getenv("HTTP_PORT")?.toInt() ?: 8080 @@ -180,6 +183,36 @@ class Message(val user: Boolean, messagetext: String) } } +fun discordWebhook(id: Int, message: String, embed_color: Color) +{ + + val webhook = Webhook { + this.username = "Sc0ttGPT bot" + //this.content = "Content" + embed { + this.title = id.toString() + this.description = message + this.url = "https://vesztettem.sch.bme.hu/" + + /* + author { + this.name = "Author Name" + } +*/ + this.color = embed_color +/* + field { + this.name = "Field Name" + this.value = "Field Value" + }*/ + } + + // ... + } + + webhook.send("https://discord.com/api/webhooks/1471523550522249381/XVHtwUk7JsPvfwbd1J8sX9inb6Q05lsXRfww1mTpOGcgcAw15diohzBgVg7qlQtw1eyA") +} + fun main(args: Array) { Logger.log("HTTP server started on 127.0.0.1:$httpPort") @@ -238,7 +271,7 @@ fun runEmbeddedServer() } staticFiles("/admin", File("$resourcesPath/admin.html")) - staticFiles("/resources", File(resourcesPath)) + staticFiles("/resources", File(resourcesPath)) staticFiles("/", File("$resourcesPath/index.html")) staticFiles("/style", File("$resourcesPath/style.css")) staticFiles("/about", File("$resourcesPath/about.html")) @@ -246,9 +279,14 @@ fun runEmbeddedServer() put("/api/write/{id}") { try { + val id = call.parameters["id"]?.toInt() ?: -1 + val text = call.receiveText() + ConversationHandler.conversations.find { - it.ID == call.parameters["id"]?.toInt() - }?.write(Message(true, call.receiveText())) + it.ID == id + }?.write(Message(true, text)) + + discordWebhook(id, text, Color.blue) call.respond(HttpStatusCode.OK) @@ -268,6 +306,7 @@ fun runEmbeddedServer() get("/api/init") { ConversationHandler.newConv() Logger.log("Conversation ${ConversationHandler.conversations.last().ID} initialized") + discordWebhook(ConversationHandler.conversations.last().ID, "New conversation probably incoming", Color.green) call.respondText(ConversationHandler.conversations.last().ID.toString()) } diff --git a/kiszolgalo/src/main/resources/index.html b/kiszolgalo/src/main/resources/index.html index b4b985d..e90090f 100644 --- a/kiszolgalo/src/main/resources/index.html +++ b/kiszolgalo/src/main/resources/index.html @@ -13,19 +13,14 @@
-