fix: fixed time conversion errors, fixed list iteration errors

This commit is contained in:
moonleay 2023-12-06 00:24:17 +01:00
parent d57a05cc84
commit 13d07b1866
Signed by: moonleay
GPG key ID: 82667543CCD715FB
5 changed files with 19 additions and 9 deletions

View file

@ -32,7 +32,7 @@ val ownerID = 372703841151614976L
group = "net.moonleay.bedge" group = "net.moonleay.bedge"
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" } version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
?: "0.0.4" ?: "0.0.5"
val kordver = "1.5.9-SNAPSHOT" val kordver = "1.5.9-SNAPSHOT"
val coroutinesver = "1.7.3" val coroutinesver = "1.7.3"

View file

@ -23,6 +23,7 @@ import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.entity.MessageFlags import dev.kord.common.entity.MessageFlags
import net.moonleay.bedge.data.database.repository.UserRepository import net.moonleay.bedge.data.database.repository.UserRepository
import net.moonleay.bedge.jobs.component.JobManager
import net.moonleay.bedge.util.EmbedColor import net.moonleay.bedge.util.EmbedColor
import net.moonleay.bedge.util.Logger import net.moonleay.bedge.util.Logger
import net.moonleay.bedge.util.MessageUtil import net.moonleay.bedge.util.MessageUtil
@ -82,6 +83,9 @@ class AwakeExtension : Extension() {
// update user // update user
UserRepository.update(ud) UserRepository.update(ud)
// kill job
JobManager.killNamedJob("WakeupJob${u.id.value.toLong()}")
// respond to user // respond to user
this.respond { this.respond {
this.embeds.add( this.embeds.add(

View file

@ -29,6 +29,7 @@ import net.moonleay.bedge.data.database.entry.UserData
import net.moonleay.bedge.data.database.repository.UserRepository import net.moonleay.bedge.data.database.repository.UserRepository
import net.moonleay.bedge.util.EmbedColor import net.moonleay.bedge.util.EmbedColor
import net.moonleay.bedge.util.MessageUtil import net.moonleay.bedge.util.MessageUtil
import net.moonleay.bedge.util.TimeUtil
class ProfileExtension : Extension() { class ProfileExtension : Extension() {
@ -45,7 +46,7 @@ class ProfileExtension : Extension() {
val user = this.user.asUser() val user = this.user.asUser()
if (this.arguments.target == null || this.arguments.target!!.id == this.user.id) { if (this.arguments.target == null || this.arguments.target!!.id == this.user.id) {
// User wants to see own profile // User wants to see own profile
val target = this.arguments.target!! val target = this.user.asUser()
if(!UserRepository.doesUserExist(target.id.value)){ if(!UserRepository.doesUserExist(target.id.value)){
this.respond { this.respond {
this.embeds.add( this.embeds.add(
@ -95,8 +96,8 @@ class ProfileExtension : Extension() {
private fun getProfileMsg(target: UserData, targetUser: User, requester: User): EmbedBuilder = MessageUtil.getEmbedWithImage( private fun getProfileMsg(target: UserData, targetUser: User, requester: User): EmbedBuilder = MessageUtil.getEmbedWithImage(
EmbedColor.INFO, EmbedColor.INFO,
"Profile of ${target.userid}", "Profile of ${targetUser.username}",
"Account created: ${target.accountCreationDate}\n" + "Account created: ${TimeUtil.convertFromUnixStamp(target.accountCreationDate)}\n" +
"Current streak: ${target.currentStreak} days\n" + "Current streak: ${target.currentStreak} days\n" +
"Longest streak: ${target.longestStreak} days\n" + "Longest streak: ${target.longestStreak} days\n" +
"Number of fails: ${target.numberOfFails}x\n" + "Number of fails: ${target.numberOfFails}x\n" +

View file

@ -68,7 +68,7 @@ class TopExtension : Extension() {
} }
} }
var msg = "" var msg = ""
for (i in 0..9) { for (i in 0..if (allInGuild.size > 10) 9 else allInGuild.size-1) {
val user = allInGuild[i] val user = allInGuild[i]
val row = getRow(user, g, targetList) val row = getRow(user, g, targetList)
msg += "${i+1}. ${row[0]}: ${row[1]}\n" msg += "${i+1}. ${row[0]}: ${row[1]}\n"
@ -77,7 +77,7 @@ class TopExtension : Extension() {
this.embeds.add( this.embeds.add(
MessageUtil.getEmbed( MessageUtil.getEmbed(
EmbedColor.INFO, EmbedColor.INFO,
"Top ${targetList.name}", targetList.readableName,
msg, msg,
u.username, u.username,
) )

View file

@ -149,6 +149,10 @@ object TimeUtil {
return ZonedDateTime.of(localDateTime, zoneId) return ZonedDateTime.of(localDateTime, zoneId)
} }
fun convertFromUnixStamp(stamp: Long): ZonedDateTime {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(stamp), ZoneId.of("UTC"))
}
fun getCronjobStringFromDate(zdt: ZonedDateTime): String { fun getCronjobStringFromDate(zdt: ZonedDateTime): String {
// I'll have to add the possibility to set your timezone in the future // I'll have to add the possibility to set your timezone in the future
// Only subtracting 1 hour, because I want to run the job 1 hour later // Only subtracting 1 hour, because I want to run the job 1 hour later
@ -164,12 +168,13 @@ object TimeUtil {
return ZonedDateTime.of(localDateTime, zoneId).toEpochSecond() * 1000 return ZonedDateTime.of(localDateTime, zoneId).toEpochSecond() * 1000
} }
fun getZdtFromTime(inp: String, zone: String): ZonedDateTime { fun getZdtFromTime(inp: String, zone: String): ZonedDateTime {
val formatter = DateTimeFormatter.ofPattern("HH:mm") val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
val localDateTime = LocalDateTime.parse(inp, formatter)
val zoneId = ZoneId.of(zone) val zoneId = ZoneId.of(zone)
val now = ZonedDateTime.now(zoneId) val now = ZonedDateTime.now(zoneId)
val zdtPre = ZonedDateTime.of(localDateTime, zoneId).withDayOfMonth(now.dayOfMonth).withMonth(now.monthValue).withYear(now.year) val localDateTime = LocalDateTime.parse("${now.year}-${now.monthValue}-${if (now.dayOfMonth < 10) "0${now.dayOfMonth}" else now.dayOfMonth} $inp", formatter)
val zdtPre = ZonedDateTime.of(localDateTime, zoneId)
if(zdtPre.isBefore(now)) if(zdtPre.isBefore(now))
return zdtPre.plusDays(1) return zdtPre.plusDays(1)
return zdtPre return zdtPre