Skip to content

Commit

Permalink
Merge pull request #143 from xiaoyv404/develop
Browse files Browse the repository at this point in the history
try to fix time
  • Loading branch information
xiaoyv404 authored Jul 25, 2024
2 parents e71cb81 + 2ce55ee commit 60633f0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xiaoyv404.mirai.app.fsh.NfOptions
import com.xiaoyv404.mirai.core.App
import com.xiaoyv404.mirai.core.MessageProcessor.reply
import com.xiaoyv404.mirai.core.NfApp
import com.xiaoyv404.mirai.dao.getAllOnlinePlayers
import com.xiaoyv404.mirai.dao.send
import com.xiaoyv404.mirai.dao.toList
import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServer
Expand Down Expand Up @@ -39,7 +40,7 @@ class MinecraftServerList : NfApp(), IFshApp {

if (!cmdLine.hasOption("player"))
return true
MinecraftServerPlayer().getAllOnlinePlayers().send(msg)
MinecraftServerPlayer{}.getAllOnlinePlayers().send(msg)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.xiaoyv404.mirai.app.webAPI.controller.NfResult
import com.xiaoyv404.mirai.app.webAPI.model.MinecraftPlayerApiModel
import com.xiaoyv404.mirai.dao.findById
import com.xiaoyv404.mirai.dao.findByName
import com.xiaoyv404.mirai.dao.getAllOnlinePlayers
import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerPlayer
import io.ktor.server.application.*
import io.ktor.server.response.*
Expand Down Expand Up @@ -44,7 +45,7 @@ fun Route.player() {
call.respond(NfResult.success(data))
}
get("/players/online") {
val data = MinecraftServerPlayer().getAllOnlinePlayers().map {
val data = MinecraftServerPlayer{}.getAllOnlinePlayers().map {
MinecraftPlayerApiModel(
it.name,
it.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,11 @@ fun MinecraftServer.getOnlinePlayers(): List<MinecraftServerPlayer> {
return players
}

fun MinecraftServerPlayer.getAllOnlinePlayers(): List<MinecraftServerPlayer> {
val players =
Database.db.minecraftServerPlayer.filter {
MinecraftServerPlayers.lastLoginTime between (LocalDateTime.now()
.plusMinutes(-4))..(LocalDateTime.now())
}.toList()
return players
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.xiaoyv404.mirai.model.mincraftServer

import com.xiaoyv404.mirai.core.NfClock
import com.xiaoyv404.mirai.database.Database
import org.ktorm.dsl.between
import org.ktorm.entity.Entity
import org.ktorm.entity.filter
import org.ktorm.entity.sequenceOf
import org.ktorm.entity.toList
import org.ktorm.schema.Table
import org.ktorm.schema.datetime
import org.ktorm.schema.enum
Expand All @@ -22,17 +16,6 @@ interface MinecraftServerPlayer : Entity<MinecraftServerPlayer> {
var lastLoginTime: LocalDateTime
var lastLoginServer: String
var permissions: Permissions
fun getAllOnlinePlayers(): List<MinecraftServerPlayer> {
val now = NfClock.now()
val players =
Database.db.minecraftServerPlayer.filter {
MinecraftServerPlayers.lastLoginTime between (now
.plusMinutes(-4))..(now)
}.toList()
return players
}

private val org.ktorm.database.Database.minecraftServerPlayer get() = this.sequenceOf(MinecraftServerPlayers)
}

object MinecraftServerPlayers : Table<MinecraftServerPlayer>("MinecraftServerPlayers") {
Expand Down

0 comments on commit 60633f0

Please sign in to comment.