add discord webhool
This commit is contained in:
@@ -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<String>) {
|
||||
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())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user