add discord hook logics

- add ApiDiscordRoutes.kt
- modify HookCommand from RegisterCommand.kt
This commit is contained in:
dalbodeule
2024-08-10 16:54:32 +09:00
parent 6d7a6beb10
commit 2d0e83efc2
7 changed files with 136 additions and 66 deletions

View File

@@ -0,0 +1,8 @@
package space.mori.chzzk_bot.common.events
class DiscordRegisterEvent(
val user: String,
val token: String,
): Event {
val TAG = javaClass.simpleName
}

View File

@@ -2,7 +2,6 @@ package space.mori.chzzk_bot.common.services
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import space.mori.chzzk_bot.common.models.User
import space.mori.chzzk_bot.common.models.Users
@@ -76,18 +75,13 @@ object UserService {
}
}
fun updateLiveAlert(id: Int, guildId: Long, channelId: Long, alertMessage: String?): User {
fun updateLiveAlert(user: User, guildId: Long, channelId: Long, alertMessage: String?): User {
return transaction {
val updated = Users.update({ Users.id eq id }) {
it[liveAlertGuild] = guildId
it[liveAlertChannel] = channelId
it[liveAlertMessage] = alertMessage ?: ""
}
user.liveAlertGuild = guildId
user.liveAlertChannel = channelId
user.liveAlertMessage = alertMessage ?: ""
if(updated == 0) throw RuntimeException("User not found! $id")
val users = User.find { Users.id eq id }
return@transaction users.first()
user
}
}
}