diff --git a/build.gradle.kts b/build.gradle.kts
index 09525fd..43e9c5d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,12 +27,12 @@ plugins {
`maven-publish`
}
-//lilJudd version 2
+//Bedge version 1
val ownerID = 372703841151614976L
group = "net.moonleay.bedge"
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
- ?: "0.0.7"
+ ?: "0.0.8"
val kordver = "1.5.9-SNAPSHOT"
val coroutinesver = "1.7.3"
diff --git a/src/main/kotlin/net/moonleay/bedge/Bot.kt b/src/main/kotlin/net/moonleay/bedge/Bot.kt
index da857c9..444f31a 100644
--- a/src/main/kotlin/net/moonleay/bedge/Bot.kt
+++ b/src/main/kotlin/net/moonleay/bedge/Bot.kt
@@ -79,6 +79,7 @@ object Bot {
add(::AwakeExtension)
add(::ProfileExtension)
add(::TopExtension)
+// add(::ShopExtension)
}
this.presence {
diff --git a/src/main/kotlin/net/moonleay/bedge/data/database/repository/UserRepository.kt b/src/main/kotlin/net/moonleay/bedge/data/database/repository/UserRepository.kt
index 726f874..58d5ae4 100644
--- a/src/main/kotlin/net/moonleay/bedge/data/database/repository/UserRepository.kt
+++ b/src/main/kotlin/net/moonleay/bedge/data/database/repository/UserRepository.kt
@@ -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(
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/AwakeExtension.kt b/src/main/kotlin/net/moonleay/bedge/extensions/AwakeExtension.kt
index d283dfd..b005693 100644
--- a/src/main/kotlin/net/moonleay/bedge/extensions/AwakeExtension.kt
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/AwakeExtension.kt
@@ -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()) {
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/ProfileExtension.kt b/src/main/kotlin/net/moonleay/bedge/extensions/ProfileExtension.kt
index 499f938..c78a2e0 100644
--- a/src/main/kotlin/net/moonleay/bedge/extensions/ProfileExtension.kt
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/ProfileExtension.kt
@@ -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)
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt b/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt
new file mode 100644
index 0000000..7395c82
--- /dev/null
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt
@@ -0,0 +1,97 @@
+/*
+ * Bedge
+ * Copyright (C) 2023 moonleay
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.moonleay.bedge.extensions
+
+import com.kotlindiscord.kord.extensions.commands.Arguments
+import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.enumChoice
+import com.kotlindiscord.kord.extensions.extensions.Extension
+import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
+import com.kotlindiscord.kord.extensions.types.respond
+import net.moonleay.bedge.data.database.repository.UserRepository
+import net.moonleay.bedge.extensions.component.ShopAction
+import net.moonleay.bedge.extensions.component.ShopItem
+import net.moonleay.bedge.util.EmbedColor
+import net.moonleay.bedge.util.MessageUtil
+
+class ShopExtension : Extension() {
+
+ override val name = "shop"
+ override val allowApplicationCommandInDMs: Boolean
+ get() = false
+
+
+ override suspend fun setup() {
+ publicSlashCommand(::ShopArguments) {
+ name = "shop"
+ description = "Buy stuff with your items"
+
+ this.action {
+ val user = this.user.asUser()
+ val ud = UserRepository.getUserByID(user.id.value)
+
+ if (ud == null) {
+ this.respond {
+ this.embeds.add(
+ MessageUtil.getEmbed(EmbedColor.ERROR,
+ "You don't have an account here!",
+ "And therefore I cannot show you our shop.\n" +
+ "You can register by running `/time`.",
+ user.username)
+ )
+ }
+ return@action
+ }
+ when(this.arguments.action){
+ ShopAction.LIST_OFFERS -> {
+ var description = "Your Coins: ${ud.coins}\n" +
+ "Your lvl: ${ud.level}\n\n" +
+ "item :: price :: required level\n"
+
+ ShopItem.entries.forEach { itm ->
+ description += "\"${itm.readableName}\" :: ${itm.cost} coins :: ${itm.requiredLevel}\n"
+ }
+
+ this.respond {
+ this.embeds.add(
+ MessageUtil.getEmbed(
+ EmbedColor.INFO,
+ "The Shop",
+ description,
+ user.username
+ )
+ )
+ }
+ }
+ ShopAction.BUY -> {
+ var description = ""
+
+ }
+ }
+ }
+ }
+ }
+
+ inner class ShopArguments : Arguments() {
+
+ val action by enumChoice {
+ this.name = "action"
+ this.description = "What you want to do"
+ }
+ }
+}
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/TimeExtension.kt b/src/main/kotlin/net/moonleay/bedge/extensions/TimeExtension.kt
index 23c4559..beca09c 100644
--- a/src/main/kotlin/net/moonleay/bedge/extensions/TimeExtension.kt
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/TimeExtension.kt
@@ -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
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt
new file mode 100644
index 0000000..8c1fee0
--- /dev/null
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt
@@ -0,0 +1,26 @@
+/*
+ * Bedge
+ * Copyright (C) 2023 moonleay
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.moonleay.bedge.extensions.component
+
+import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum
+
+enum class ShopAction(override val readableName: String) : ChoiceEnum {
+ LIST_OFFERS("list offers"),
+ BUY("buy")
+}
diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt
new file mode 100644
index 0000000..f4f30c4
--- /dev/null
+++ b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt
@@ -0,0 +1,28 @@
+/*
+ * Bedge
+ * Copyright (C) 2023 moonleay
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package net.moonleay.bedge.extensions.component
+
+import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum
+
+enum class ShopItem(override val readableName: String, val itemDescription: String, val cost: Int, val requiredLevel: Int) : ChoiceEnum {
+ ADD_CUSTOM_SERVER_MOTD("Add a custom MOTD", "Add a MOTD to my minecraft server", 2, 0),
+ REMOVE_DEATH_FROM_COUNTER("Remove Death", "Remove a death from the death counter on my minecraft server", 21, 4),
+ UPDATE_WAKEUP_MESSAGE("Update wakeup msg", "Update the message the bot sends, when you wake up", 4, 2),
+ UPDATE_REMINDER_MESSAGE("Update reminder msg","Update the message the bot sends you to remind you to go to bed", 4, 2)
+}
diff --git a/src/main/kotlin/net/moonleay/bedge/jobs/WakeupJob.kt b/src/main/kotlin/net/moonleay/bedge/jobs/WakeupJob.kt
index eb2ce2a..229c0ab 100644
--- a/src/main/kotlin/net/moonleay/bedge/jobs/WakeupJob.kt
+++ b/src/main/kotlin/net/moonleay/bedge/jobs/WakeupJob.kt
@@ -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()
diff --git a/src/main/kotlin/net/moonleay/bedge/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/bedge/util/TimeUtil.kt
index 315c641..baf8168 100644
--- a/src/main/kotlin/net/moonleay/bedge/util/TimeUtil.kt
+++ b/src/main/kotlin/net/moonleay/bedge/util/TimeUtil.kt
@@ -173,7 +173,7 @@ object TimeUtil {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
val zoneId = ZoneId.of(zone)
val now = ZonedDateTime.now(zoneId)
- val localDateTime = LocalDateTime.parse("${now.year}-${now.monthValue}-${if (now.dayOfMonth < 10) "0${now.dayOfMonth}" else now.dayOfMonth} $inp", formatter)
+ val localDateTime = LocalDateTime.parse("${now.year}-${if (now.monthValue < 10) "0${now.monthValue}" else now.monthValue}-${if (now.dayOfMonth < 10) "0${now.dayOfMonth}" else now.dayOfMonth} $inp", formatter)
val zdtPre = ZonedDateTime.of(localDateTime, zoneId)
if(zdtPre.isBefore(now))
return zdtPre.plusDays(1)