feat!: made UserData nullable in UserRepository
This commit is contained in:
parent
3e8a2d2d83
commit
48671c3b0a
5 changed files with 12 additions and 9 deletions
|
@ -61,10 +61,10 @@ object UserRepository {
|
|||
}
|
||||
|
||||
|
||||
fun getUserByID(id: ULong): UserData = getUserByID(id.toLong())
|
||||
fun getUserByID(id: ULong): UserData? = getUserByID(id.toLong())
|
||||
|
||||
fun getUserByID(id: Long): UserData {
|
||||
lateinit var user: UserData
|
||||
fun getUserByID(id: Long): UserData? {
|
||||
var user: UserData? = null
|
||||
transaction {
|
||||
UserTable.select(UserTable.userid eq id).forEach {
|
||||
user = UserData(
|
||||
|
|
|
@ -39,7 +39,7 @@ class AwakeExtension : Extension() {
|
|||
val u = this.user.asUser()
|
||||
Logger.out("User ${u.username} wants to be awake")
|
||||
if (UserRepository.doesUserExist(u.id.value)){
|
||||
val ud = UserRepository.getUserByID(u.id.value)
|
||||
val ud = UserRepository.getUserByID(u.id.value)!!
|
||||
if (ud.isAwake) {
|
||||
// User is already awake
|
||||
if (ud.currentStreak == 0 && ud.lastWakeup + (1000*60*60*12) > System.currentTimeMillis()) {
|
||||
|
|
|
@ -60,7 +60,7 @@ class ProfileExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
val td = UserRepository.getUserByID(target.id.value)
|
||||
val td = UserRepository.getUserByID(target.id.value)!!
|
||||
this.respond {
|
||||
this.embeds.add(
|
||||
getProfileMsg(td, target, target)
|
||||
|
@ -84,7 +84,7 @@ class ProfileExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
val td = UserRepository.getUserByID(target.id.value)
|
||||
val td = UserRepository.getUserByID(target.id.value)!!
|
||||
this.respond {
|
||||
this.embeds.add(
|
||||
getProfileMsg(td, target, user)
|
||||
|
|
|
@ -51,9 +51,12 @@ class TimeExtension : Extension() {
|
|||
val targetChannelId = this.channel.asChannel().id.value.toLong()
|
||||
lateinit var ud: UserData
|
||||
|
||||
// This should be correct;
|
||||
val timeToSleep = timeToWake.toEpochSecond() * 1000 - System.currentTimeMillis()
|
||||
|
||||
if (UserRepository.doesUserExist(u.id.value)) {
|
||||
// Update existing user
|
||||
ud = UserRepository.getUserByID(u.id.value)
|
||||
ud = UserRepository.getUserByID(u.id.value)!!
|
||||
ud.nextWakeup = timeToWake.toEpochSecond() * 1000 // ms
|
||||
ud.nextWakeupCron = cronJobString
|
||||
ud.isAwake = false
|
||||
|
@ -92,7 +95,7 @@ class TimeExtension : Extension() {
|
|||
this.embeds.add(MessageUtil.getEmbed(
|
||||
EmbedColor.SUCCESS,
|
||||
"Wakeup time set",
|
||||
"${u.mention} is now set to be awake at $targetTime.\n" +
|
||||
"${u.mention} is now set to be awake in ${TimeUtil.getTimeFormatedShortend(timeToSleep, false)} at $targetTime.\n" +
|
||||
"Have a restfull sleep!\n" +
|
||||
"***You can change your wakeup time by running /time again!***",
|
||||
u.username
|
||||
|
|
|
@ -44,7 +44,7 @@ class WakeupJob(override val jobName: String, override val jobIncoming: String,
|
|||
|
||||
override suspend fun jobFunction() {
|
||||
Logger.out("WakeupJob, running \"$jobName\"")
|
||||
val user = UserRepository.getUserByID(userId)
|
||||
val user = UserRepository.getUserByID(userId)!!
|
||||
if (!user.isAwake){
|
||||
// Failed
|
||||
val userasuser = Bot.bot.kordRef.getUser(Snowflake(userId))!!.asUser()
|
||||
|
|
Loading…
Reference in a new issue