Compare commits
4 commits
b1fc971825
...
ccdfa9abcf
Author | SHA1 | Date | |
---|---|---|---|
ccdfa9abcf | |||
61cdad8b21 | |||
48671c3b0a | |||
3e8a2d2d83 |
11 changed files with 167 additions and 12 deletions
|
@ -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"
|
||||
|
|
|
@ -79,6 +79,7 @@ object Bot {
|
|||
add(::AwakeExtension)
|
||||
add(::ProfileExtension)
|
||||
add(::TopExtension)
|
||||
// add(::ShopExtension)
|
||||
}
|
||||
|
||||
this.presence {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue