add remove command

This commit is contained in:
dalbodeule
2024-06-12 22:59:27 +09:00
parent 2bef5be6fa
commit 02d12e74b5
2 changed files with 55 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package space.mori.chzzk_bot.services
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import space.mori.chzzk_bot.models.Command
import space.mori.chzzk_bot.models.Commands
@@ -17,6 +18,17 @@ object CommandService {
}
}
fun removeCommand(user: User, command: String): Command? {
return transaction {
val commandRow = Command.find(Commands.user eq user.id and(Commands.command eq command)).firstOrNull()
commandRow ?: throw RuntimeException("Command not found! $command")
commandRow.delete()
return@transaction commandRow
}
}
fun getCommand(id: Int): Command? {
return transaction {
return@transaction Command.findById(id)