mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-08 05:11:12 +00:00
add chzzk chat handler, command handler
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package space.mori.chzzk_bot.services
|
||||
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import space.mori.chzzk_bot.models.Command
|
||||
import space.mori.chzzk_bot.models.Commands
|
||||
import space.mori.chzzk_bot.models.User
|
||||
|
||||
object CommandService {
|
||||
fun saveCommand(user: User, command: String, content: String): Command {
|
||||
return transaction {
|
||||
return@transaction Command.new {
|
||||
this.user = user
|
||||
this.command = command
|
||||
this.content = content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCommand(id: Int): Command? {
|
||||
return transaction {
|
||||
return@transaction Command.findById(id)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCommands(user: User): List<Command> {
|
||||
return transaction {
|
||||
return@transaction Command.find(Commands.user eq user.id)
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +1,46 @@
|
||||
package space.mori.chzzk_bot.services
|
||||
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import space.mori.chzzk_bot.models.User
|
||||
import space.mori.chzzk_bot.models.Users
|
||||
|
||||
class UserService {
|
||||
fun saveUser(user: User) {
|
||||
User.new {
|
||||
username = user.username
|
||||
token = user.token
|
||||
discord = user.discord
|
||||
object UserService {
|
||||
fun saveUser(username: String, token: String, discordID: Long): User {
|
||||
return transaction {
|
||||
return@transaction User.new {
|
||||
this.username = username
|
||||
this.token = token
|
||||
this.discord = discordID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getUser(id: Int): User? {
|
||||
return User.findById(id)
|
||||
return transaction {
|
||||
return@transaction User.findById(id)
|
||||
}
|
||||
}
|
||||
|
||||
fun getUser(discordID: Long): User? {
|
||||
val users = User.find(Users.discord eq discordID)
|
||||
return transaction {
|
||||
val users = User.find(Users.discord eq discordID)
|
||||
|
||||
return users.firstOrNull()
|
||||
return@transaction users.firstOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
fun getUser(chzzkID: String): User? {
|
||||
return transaction {
|
||||
val users = User.find(Users.token eq chzzkID)
|
||||
|
||||
return@transaction users.firstOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllUsers(): List<User> {
|
||||
return transaction {
|
||||
return@transaction User.all().toList()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user