add discord webhool

This commit is contained in:
2026-02-12 16:47:38 +01:00
parent d698471fb8
commit 917b8c8add
5 changed files with 74 additions and 20 deletions
+2
View File
@@ -14,6 +14,7 @@ version = "1.0-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()
maven { url = uri("https://jitpack.io") }
} }
application { application {
@@ -26,6 +27,7 @@ dependencies {
implementation("io.ktor:ktor-server-netty:$ktor_version") implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("io.ktor:ktor-server-sessions:${ktor_version}") implementation("io.ktor:ktor-server-sessions:${ktor_version}")
implementation("io.ktor:ktor-server-auth:${ktor_version}") implementation("io.ktor:ktor-server-auth:${ktor_version}")
implementation("com.github.BinaryWriter:discord-webhooks:1.0")
} }
tasks.test { tasks.test {
+41 -2
View File
@@ -14,6 +14,9 @@ import kotlin.random.nextInt
import io.ktor.server.auth.* import io.ktor.server.auth.*
import io.ktor.server.application.* import io.ktor.server.application.*
import me.binarywriter.discordwebhooks.data.* //discord webhook
import java.awt.Color
//átlagos JAVA alapú fejlesztő //átlagos JAVA alapú fejlesztő
val httpPort: Int = System.getenv("HTTP_PORT")?.toInt() ?: 8080 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>) { fun main(args: Array<String>) {
Logger.log("HTTP server started on 127.0.0.1:$httpPort") Logger.log("HTTP server started on 127.0.0.1:$httpPort")
@@ -246,9 +279,14 @@ fun runEmbeddedServer()
put("/api/write/{id}") put("/api/write/{id}")
{ {
try { try {
val id = call.parameters["id"]?.toInt() ?: -1
val text = call.receiveText()
ConversationHandler.conversations.find { ConversationHandler.conversations.find {
it.ID == call.parameters["id"]?.toInt() it.ID == id
}?.write(Message(true, call.receiveText())) }?.write(Message(true, text))
discordWebhook(id, text, Color.blue)
call.respond(HttpStatusCode.OK) call.respond(HttpStatusCode.OK)
@@ -268,6 +306,7 @@ fun runEmbeddedServer()
get("/api/init") { get("/api/init") {
ConversationHandler.newConv() ConversationHandler.newConv()
Logger.log("Conversation ${ConversationHandler.conversations.last().ID} initialized") 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()) call.respondText(ConversationHandler.conversations.last().ID.toString())
} }
+26 -13
View File
@@ -13,19 +13,14 @@
<div class="main-flexbox"> <div class="main-flexbox">
<header class="navbar"> <header class="navbar" id="funniez">
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a> <a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
<a href="/about" style="float: left">About</a> <a href="/about" style="float: left">About</a>
<button onclick="genZ()" style="float: left;" class="funny">Gen Z compatible site</button> <!--<button onclick="genZ()" style="float: left;" class="funny">Gen Z compatible site</button>-->
<img src="resources/logo.png" alt=logo" class="logo" style="float: right;"> <img src="resources/logo.png" alt=logo" class="logo" style="float: right;">
</header> </header>
<iframe width="420" height="315"
src="https://www.youtube.com/embed/mn-Tlb_wfjc"
id="funniez"
style="display: none;">
</iframe>
<div id="messages" class="messages"> <div id="messages" class="messages">
@@ -33,8 +28,8 @@
<footer> <footer>
<div class="textbox"> <div class="textbox">
<input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk..."> <input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk..." onchange="sendButton()" >
<button id="send-button" class="send_button" onclick="send_data()">send</button> <button id="send-button" class="send_button" onclick="send_data()"></button>
</div> </div>
</footer> </footer>
@@ -44,8 +39,22 @@
<script> <script>
let id; let id;
var genz = false;
var input = document.getElementById("promptText"); var input = document.getElementById("promptText");
function sendButton() {
var x = document.getElementById("send-button");
var input = document.getElementById("promptText")
console.log(input.value)
if (input.value == "") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
input.addEventListener("keypress", function(event) { input.addEventListener("keypress", function(event) {
if (event.key === "Enter") { if (event.key === "Enter") {
@@ -56,11 +65,15 @@
}); });
function genZ() { function genZ() {
var x = document.getElementById("funniez"); let genzHtml = " <iframe width=\"420\" height=\"315\"\n" +
if (x.style.display === "none") { " src=\"https://www.youtube.com/embed/mn-Tlb_wfjc\"\n" +
x.style.display = "block"; " style=\"display: none;\" id='genz'>\n" +
" </iframe>";
if (genz === false) {
document.getElementById("funniez").insertAdjacentHTML("afterend", genzHtml);
} else { } else {
x.style.display = "none"; document.getElementById("genz").remove();
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+2 -2
View File
@@ -106,12 +106,13 @@ body {
} }
.send_button { .send_button {
aspect-ratio: 1 / 1;
justify-content: flex-end; justify-content: flex-end;
padding: 4px 8px; padding: 4px 8px;
margin: 10px; margin: 10px;
height: 30px; height: 30px;
border-radius: 50%; border-radius: 50%;
background: white; background-image: url("/resources/send.png");
color: #212121; color: #212121;
border: none; border: none;
} }
@@ -186,7 +187,6 @@ footer {
.message { .message {
width: 80%; width: 80%;
} }
.funny { .funny {
display: none; display: none;
} }