add discord webhool
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -13,19 +13,14 @@
|
||||
|
||||
<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="/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;">
|
||||
</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">
|
||||
|
||||
@@ -33,8 +28,8 @@
|
||||
|
||||
<footer>
|
||||
<div class="textbox">
|
||||
<input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk...">
|
||||
<button id="send-button" class="send_button" onclick="send_data()">send</button>
|
||||
<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()"></button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
@@ -44,8 +39,22 @@
|
||||
|
||||
<script>
|
||||
let id;
|
||||
var genz = false;
|
||||
|
||||
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) {
|
||||
if (event.key === "Enter") {
|
||||
|
||||
@@ -56,12 +65,16 @@
|
||||
});
|
||||
|
||||
function genZ() {
|
||||
var x = document.getElementById("funniez");
|
||||
if (x.style.display === "none") {
|
||||
x.style.display = "block";
|
||||
} else {
|
||||
x.style.display = "none";
|
||||
}
|
||||
let genzHtml = " <iframe width=\"420\" height=\"315\"\n" +
|
||||
" src=\"https://www.youtube.com/embed/mn-Tlb_wfjc\"\n" +
|
||||
" style=\"display: none;\" id='genz'>\n" +
|
||||
" </iframe>";
|
||||
|
||||
if (genz === false) {
|
||||
document.getElementById("funniez").insertAdjacentHTML("afterend", genzHtml);
|
||||
} else {
|
||||
document.getElementById("genz").remove();
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
@@ -106,12 +106,13 @@ body {
|
||||
}
|
||||
|
||||
.send_button {
|
||||
aspect-ratio: 1 / 1;
|
||||
justify-content: flex-end;
|
||||
padding: 4px 8px;
|
||||
margin: 10px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
background: white;
|
||||
background-image: url("/resources/send.png");
|
||||
color: #212121;
|
||||
border: none;
|
||||
}
|
||||
@@ -186,7 +187,6 @@ footer {
|
||||
.message {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.funny {
|
||||
display: none;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user