Compare commits

..

4 commits

11 changed files with 167 additions and 12 deletions

View file

@ -27,12 +27,12 @@ plugins {
`maven-publish` `maven-publish`
} }
//lilJudd version 2 //Bedge version 1
val ownerID = 372703841151614976L 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.7" ?: "0.0.8"
val kordver = "1.5.9-SNAPSHOT" val kordver = "1.5.9-SNAPSHOT"
val coroutinesver = "1.7.3" val coroutinesver = "1.7.3"

View file

@ -79,6 +79,7 @@ object Bot {
add(::AwakeExtension) add(::AwakeExtension)
add(::ProfileExtension) add(::ProfileExtension)
add(::TopExtension) add(::TopExtension)
// add(::ShopExtension)
} }
this.presence { this.presence {

View file

@ -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 { fun getUserByID(id: Long): UserData? {
lateinit var user: UserData var user: UserData? = null
transaction { transaction {
UserTable.select(UserTable.userid eq id).forEach { UserTable.select(UserTable.userid eq id).forEach {
user = UserData( user = UserData(

View file

@ -39,7 +39,7 @@ class AwakeExtension : Extension() {
val u = this.user.asUser() val u = this.user.asUser()
Logger.out("User ${u.username} wants to be awake") Logger.out("User ${u.username} wants to be awake")
if (UserRepository.doesUserExist(u.id.value)){ if (UserRepository.doesUserExist(u.id.value)){
val ud = UserRepository.getUserByID(u.id.value) val ud = UserRepository.getUserByID(u.id.value)!!
if (ud.isAwake) { if (ud.isAwake) {
// User is already awake // User is already awake
if (ud.currentStreak == 0 && ud.lastWakeup + (1000*60*60*12) > System.currentTimeMillis()) { if (ud.currentStreak == 0 && ud.lastWakeup + (1000*60*60*12) > System.currentTimeMillis()) {

View file

@ -60,7 +60,7 @@ class ProfileExtension : Extension() {
} }
return@action return@action
} }
val td = UserRepository.getUserByID(target.id.value) val td = UserRepository.getUserByID(target.id.value)!!
this.respond { this.respond {
this.embeds.add( this.embeds.add(
getProfileMsg(td, target, target) getProfileMsg(td, target, target)
@ -84,7 +84,7 @@ class ProfileExtension : Extension() {
} }
return@action return@action
} }
val td = UserRepository.getUserByID(target.id.value) val td = UserRepository.getUserByID(target.id.value)!!
this.respond { this.respond {
this.embeds.add( this.embeds.add(
getProfileMsg(td, target, user) getProfileMsg(td, target, user)

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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<ShopAction> {
this.name = "action"
this.description = "What you want to do"
}
}
}

View file

@ -51,9 +51,12 @@ class TimeExtension : Extension() {
val targetChannelId = this.channel.asChannel().id.value.toLong() val targetChannelId = this.channel.asChannel().id.value.toLong()
lateinit var ud: UserData lateinit var ud: UserData
// This should be correct;
val timeToSleep = timeToWake.toEpochSecond() * 1000 - System.currentTimeMillis()
if (UserRepository.doesUserExist(u.id.value)) { if (UserRepository.doesUserExist(u.id.value)) {
// Update existing user // Update existing user
ud = UserRepository.getUserByID(u.id.value) ud = UserRepository.getUserByID(u.id.value)!!
ud.nextWakeup = timeToWake.toEpochSecond() * 1000 // ms ud.nextWakeup = timeToWake.toEpochSecond() * 1000 // ms
ud.nextWakeupCron = cronJobString ud.nextWakeupCron = cronJobString
ud.isAwake = false ud.isAwake = false
@ -92,7 +95,7 @@ class TimeExtension : Extension() {
this.embeds.add(MessageUtil.getEmbed( this.embeds.add(MessageUtil.getEmbed(
EmbedColor.SUCCESS, EmbedColor.SUCCESS,
"Wakeup time set", "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" + "Have a restfull sleep!\n" +
"***You can change your wakeup time by running /time again!***", "***You can change your wakeup time by running /time again!***",
u.username u.username

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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")
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
}

View file

@ -44,7 +44,7 @@ class WakeupJob(override val jobName: String, override val jobIncoming: String,
override suspend fun jobFunction() { override suspend fun jobFunction() {
Logger.out("WakeupJob, running \"$jobName\"") Logger.out("WakeupJob, running \"$jobName\"")
val user = UserRepository.getUserByID(userId) val user = UserRepository.getUserByID(userId)!!
if (!user.isAwake){ if (!user.isAwake){
// Failed // Failed
val userasuser = Bot.bot.kordRef.getUser(Snowflake(userId))!!.asUser() val userasuser = Bot.bot.kordRef.getUser(Snowflake(userId))!!.asUser()

View file

@ -173,7 +173,7 @@ object TimeUtil {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm") val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
val zoneId = ZoneId.of(zone) val zoneId = ZoneId.of(zone)
val now = ZonedDateTime.now(zoneId) 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) val zdtPre = ZonedDateTime.of(localDateTime, zoneId)
if(zdtPre.isBefore(now)) if(zdtPre.isBefore(now))
return zdtPre.plusDays(1) return zdtPre.plusDays(1)