Compare commits

...

4 commits

Author SHA1 Message Date
303e4061c6 we have history babeeee! 2024-09-21 04:30:50 -06:00
fe32062d98 whoops 2024-09-21 04:25:29 -06:00
7a9ae5076b those should be private 2024-09-21 04:17:50 -06:00
aee2126d21 we dont need that 2024-09-21 04:17:34 -06:00
6 changed files with 40 additions and 12 deletions

3
backend/.gitignore vendored
View file

@ -45,4 +45,5 @@ bin/
.DS_Store
### Other ###
bot.cfg
bot.cfg
ntfyHistory.txt

View file

@ -14,6 +14,7 @@ import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.plugins.ratelimit.*
import kotlinx.coroutines.runBlocking
import observer.nelle.nelleObserverBackend.helpers.checkCreate
import observer.nelle.nelleObserverBackend.plugins.configureRouting
import kotlin.time.Duration.Companion.minutes
@ -36,6 +37,8 @@ fun Application.module() {
allowHeader(HttpHeaders.ContentType)
anyHost()
}
// check for ntfyhistory file, and if it doesnt exist, create it
checkCreate()
runBlocking {
val client =
HttpClient(CIO) {

View file

@ -13,8 +13,8 @@ import java.util.*
val prop = Properties()
class Config {
val confPath = Paths.get("").toAbsolutePath().toString()
val confFile = File("$confPath/bot.cfg")
private val confPath = Paths.get("").toAbsolutePath().toString()
private val confFile = File("$confPath/bot.cfg")
init {
if (confFile.exists()) {
@ -35,11 +35,4 @@ class Config {
val botToken: String = (prop.getProperty("botToken"))
val instanceDomain: String = (prop.getProperty("instance"))
val superSecret: String = (prop.getProperty("superSecret"))
fun stringToWords(s: String) =
s
.trim()
.splitToSequence(", ")
.filter { it.isNotEmpty() } // or: .filter { it.isNotBlank() }
.toList()
}

View file

@ -0,0 +1,29 @@
package observer.nelle.nelleObserverBackend.helpers
import observer.nelle.nelleObserverBackend.prop
import java.io.File
import java.io.FileInputStream
import java.nio.file.Files
import java.nio.file.Paths
val historyPath = Paths.get("").toAbsolutePath().toString()
val historyFile = File("$historyPath/ntfyHistory.txt")
fun checkCreate() {
if (historyFile.exists()) {
FileInputStream(historyFile).use { prop.load(it) }
} else {
Files.createFile(Paths.get("$historyPath/ntfyHistory.txt"))
}
}
fun storeMessage(
title: String,
message: String,
attach: String,
click: String,
) {
val text = "Title: $title, Message: $message, Attach: $attach, Click: $click\n"
historyFile.appendText(text, Charsets.UTF_8)
}

View file

@ -44,8 +44,8 @@ suspend fun ntfyMsg(
client.post("https://ntfy.ouroboros.group/pushy") {
headers {
append("Title", title)
append("Attach", title)
append("Click", title)
append("Attach", attach)
append("Click", click)
}
setBody(message)
}

View file

@ -12,6 +12,7 @@ import io.ktor.server.routing.*
import observer.nelle.nelleObserverBackend.*
import observer.nelle.nelleObserverBackend.helpers.getBeep
import observer.nelle.nelleObserverBackend.helpers.getMeow
import observer.nelle.nelleObserverBackend.helpers.storeMessage
import java.util.*
import kotlin.concurrent.timerTask
import kotlin.time.Duration.Companion.minutes
@ -140,6 +141,7 @@ fun Application.configureRouting(client: HttpClient) {
val click = formParameters["Click"].toString()
call.response.status(HttpStatusCode(201, "Received..."))
call.respondText("Received:: Title: $title, Message: $message, Attachment: $attach, Click: $click")
storeMessage(title, message, attach, click)
ntfyMsg(client, title, message, attach, click)
}
}