main #8
2 changed files with 12 additions and 6 deletions
|
@ -18,22 +18,26 @@ import kotlin.time.Duration.Companion.minutes
|
|||
|
||||
var meowTimedOut = false
|
||||
var beepTimedOut = false
|
||||
var timeoutTime = 33.minutes
|
||||
|
||||
// function to facilitate the timeout for meows
|
||||
fun meowTimer() {
|
||||
meowTimedOut = true
|
||||
// get the randomized timeout time, anywhere between
|
||||
val timeoutTime = (10..180).random().minutes
|
||||
println(timeoutTime)
|
||||
Timer("SettingUp", true).schedule(
|
||||
timerTask {
|
||||
meowTimedOut = false
|
||||
logger.debug { "timeout reset" }
|
||||
},
|
||||
// 33 minutes in milliseconds
|
||||
timeoutTime.inWholeMilliseconds,
|
||||
)
|
||||
}
|
||||
|
||||
// same as meowTimer, but for beeps
|
||||
fun beepTimer() {
|
||||
beepTimedOut = true
|
||||
val timeoutTime = (1..1440).random().minutes
|
||||
Timer("SettingUp", true).schedule(
|
||||
timerTask {
|
||||
beepTimedOut = false
|
||||
|
@ -44,9 +48,11 @@ fun beepTimer() {
|
|||
)
|
||||
}
|
||||
|
||||
// this is where the fun REST comes in!
|
||||
fun Application.configureRouting(client: HttpClient) {
|
||||
routing {
|
||||
rateLimit {
|
||||
// route all paths of */api
|
||||
route("/api") {
|
||||
// meow
|
||||
route("/meow") {
|
||||
|
@ -55,7 +61,7 @@ fun Application.configureRouting(client: HttpClient) {
|
|||
if (meowTimedOut) {
|
||||
call.response.status(HttpStatusCode(423, "Timed Out"))
|
||||
call.respondText("Timed Out")
|
||||
logger.debug { "timed out" }
|
||||
logger.debug { "timed out for some time" }
|
||||
} else {
|
||||
call.response.status(HttpStatusCode(100, "Not Timed Out"))
|
||||
call.respondText("Not Timed Out")
|
||||
|
@ -72,13 +78,13 @@ fun Application.configureRouting(client: HttpClient) {
|
|||
} else {
|
||||
if (meowTimedOut) {
|
||||
call.response.status(HttpStatusCode(423, "Timed Out"))
|
||||
call.respondText("still sleeping...")
|
||||
call.respondText("still sleeping... timed out for some time")
|
||||
logger.info { "failed meow" }
|
||||
} else {
|
||||
call.response.status(HttpStatusCode(201, "Meow Posted"))
|
||||
makePost(client, getMeow(), Config().instanceDomain)
|
||||
meowTimer()
|
||||
call.respondText("meow' sent!")
|
||||
call.respondText("meow' sent! timed out for some time")
|
||||
logger.info { "meowed" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<hr>
|
||||
<h3>meow/beep </h3>
|
||||
<p>press the buttons bellow to make me meow/beep on the fediverse,
|
||||
there is a global timeout of 33 minutes, and a separate timer for each button. if it says its sleeping, come back and try again later!</p>
|
||||
there is a global timeout of anywhere between 10 and 180 minutes, and a separate timer for each button. if it says its sleeping, come back and try again later!</p>
|
||||
|
||||
<button
|
||||
class="custom-btn btn-1 beep-buttons"
|
||||
|
|
Loading…
Reference in a new issue