fix User.kt

- set "discord", "token" row to nullable.
This commit is contained in:
dalbodeule 2024-08-08 20:18:49 +09:00
parent 80fa2d5029
commit f2a871d664
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
10 changed files with 26 additions and 22 deletions

View File

@ -29,7 +29,7 @@ object ChzzkHandler {
private val logger = LoggerFactory.getLogger(this::class.java) private val logger = LoggerFactory.getLogger(this::class.java)
lateinit var botUid: String lateinit var botUid: String
@Volatile private var running: Boolean = false @Volatile private var running: Boolean = false
val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java) private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
fun addUser(chzzkChannel: ChzzkChannel, user: User) { fun addUser(chzzkChannel: ChzzkChannel, user: User) {
handlers.add(UserHandler(chzzkChannel, logger, user, streamStartTime = null)) handlers.add(UserHandler(chzzkChannel, logger, user, streamStartTime = null))

View File

@ -157,7 +157,7 @@ class MessageHandler(
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
dispatcher.post( dispatcher.post(
TimerEvent( TimerEvent(
user.token, user.token!!,
TimerType.UPTIME, TimerType.UPTIME,
getUptime(handler.streamStartTime!!) getUptime(handler.streamStartTime!!)
) )
@ -167,7 +167,7 @@ class MessageHandler(
"삭제" -> { "삭제" -> {
logger.debug("${user.token} / 삭제") logger.debug("${user.token} / 삭제")
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
dispatcher.post(TimerEvent(user.token, TimerType.REMOVE, "")) dispatcher.post(TimerEvent(user.token!!, TimerType.REMOVE, ""))
} }
} }
"설정" -> { "설정" -> {
@ -191,7 +191,7 @@ class MessageHandler(
val timestamp = currentTime.plus(time.toLong(), ChronoUnit.MINUTES) val timestamp = currentTime.plus(time.toLong(), ChronoUnit.MINUTES)
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
dispatcher.post(TimerEvent(user.token, TimerType.TIMER, timestamp.toString())) dispatcher.post(TimerEvent(user.token!!, TimerType.TIMER, timestamp.toString()))
} }
} catch (e: NumberFormatException) { } catch (e: NumberFormatException) {
listener.sendChat("!타이머/숫자 형식으로 적어주세요! 단위: 분") listener.sendChat("!타이머/숫자 형식으로 적어주세요! 단위: 분")
@ -254,7 +254,7 @@ class MessageHandler(
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
dispatcher.post( dispatcher.post(
SongEvent( SongEvent(
user.token, user.token!!,
SongType.ADD, SongType.ADD,
msg.userId, msg.userId,
msg.profile?.nickname ?: "", msg.profile?.nickname ?: "",
@ -286,10 +286,12 @@ class MessageHandler(
val session = "${UUID.randomUUID()}${UUID.randomUUID()}".replace("-", "") val session = "${UUID.randomUUID()}${UUID.randomUUID()}".replace("-", "")
bot.retrieveUserById(user.discord).queue { discordUser -> user.discord?.let {
discordUser?.openPrivateChannel()?.queue { channel -> bot.retrieveUserById(it).queue { discordUser ->
channel.sendMessage("여기로 접속해주세요! ||https://nabot.mori.space/songlist||.") discordUser?.openPrivateChannel()?.queue { channel ->
.queue() channel.sendMessage("여기로 접속해주세요! ||https://nabot.mori.space/songlist||.")
.queue()
}
} }
} }
} }

View File

@ -57,7 +57,7 @@ object AddCommand : CommandInterface {
return return
} }
val chzzkChannel = Connector.getChannel(user!!.token) val chzzkChannel = user!!.token?.let { Connector.getChannel(it) }
try { try {
CommandService.saveCommand(user!!, label, content, failContent ?: "") CommandService.saveCommand(user!!, label, content, failContent ?: "")

View File

@ -43,7 +43,7 @@ object AlertCommand : CommandInterface {
return return
} }
val chzzkChannel = Connector.getChannel(user!!.token) val chzzkChannel = user!!.token?.let { Connector.getChannel(it) }
try { try {
val newUser = UserService.updateLiveAlert(user!!.id.value, channel?.guild?.idLong ?: 0L, channel?.idLong ?: 0L, content ?: "") val newUser = UserService.updateLiveAlert(user!!.id.value, channel?.guild?.idLong ?: 0L, channel?.idLong ?: 0L, content ?: "")

View File

@ -47,7 +47,7 @@ object RemoveCommand : CommandInterface {
return return
} }
val chzzkChannel = Connector.getChannel(user!!.token) val chzzkChannel = user!!.token?.let { Connector.getChannel(it) }
try { try {
CommandService.removeCommand(user!!, label) CommandService.removeCommand(user!!, label)

View File

@ -51,7 +51,7 @@ object UpdateCommand : CommandInterface {
return return
} }
val chzzkChannel = Connector.getChannel(user!!.token) val chzzkChannel = user!!.token?.let { Connector.getChannel(it) }
try { try {
CommandService.updateCommand(user!!, label, content, failContent ?: "") CommandService.updateCommand(user!!, label, content, failContent ?: "")

View File

@ -8,8 +8,8 @@ import org.jetbrains.exposed.dao.id.IntIdTable
object Users: IntIdTable("users") { object Users: IntIdTable("users") {
val username = varchar("username", 255) val username = varchar("username", 255)
val token = varchar("token", 64) val token = varchar("token", 64).nullable()
val discord = long("discord") val discord = long("discord").nullable()
val naverId = varchar("naver_id", 128) val naverId = varchar("naver_id", 128)
val liveAlertGuild = long("live_alert_guild").nullable() val liveAlertGuild = long("live_alert_guild").nullable()
val liveAlertChannel = long("live_alert_channel").nullable() val liveAlertChannel = long("live_alert_channel").nullable()

View File

@ -103,6 +103,8 @@ val server = embeddedServer(Netty, port = 8080, ) {
} }
get("/logout") { get("/logout") {
call.sessions.clear<UserSession>() call.sessions.clear<UserSession>()
call.response.status(HttpStatusCode.OK)
return@get
} }
} }

View File

@ -93,7 +93,7 @@ fun Routing.apiRoutes() {
user = UserService.saveUser(session.nickname, session.id) user = UserService.saveUser(session.nickname, session.id)
} }
val songConfig = SongConfigService.getConfig(user) val songConfig = SongConfigService.getConfig(user)
val status = getStreamInfo(user.token) val status = getStreamInfo(user.token!!)
if(status.content == null) { if(status.content == null) {
call.respondText(user.naverId, status = HttpStatusCode.NotFound) call.respondText(user.naverId, status = HttpStatusCode.NotFound)

View File

@ -49,13 +49,13 @@ fun Routing.wsSongListRoutes() {
val uid = user.token val uid = user.token
addSession(uid, this) addSession(uid!!, this)
if(status[uid] == SongType.STREAM_OFF) { if(status[uid] == SongType.STREAM_OFF) {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
sendSerialized(SongResponse( sendSerialized(SongResponse(
SongType.STREAM_OFF.value, SongType.STREAM_OFF.value,
user.token, uid,
null, null,
null, null,
null, null,
@ -83,7 +83,7 @@ fun Routing.wsSongListRoutes() {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
SongListService.saveSong( SongListService.saveSong(
user, user,
user.token, user.token!!,
data.url, data.url,
youtubeVideo.name, youtubeVideo.name,
youtubeVideo.author, youtubeVideo.author,
@ -92,7 +92,7 @@ fun Routing.wsSongListRoutes() {
) )
dispatcher.post( dispatcher.post(
SongEvent( SongEvent(
user.token, user.token!!,
SongType.ADD, SongType.ADD,
user.token, user.token,
user.username, user.username,
@ -110,7 +110,7 @@ fun Routing.wsSongListRoutes() {
} }
else if(data.type == SongType.REMOVE.value && data.url != null) { else if(data.type == SongType.REMOVE.value && data.url != null) {
dispatcher.post(SongEvent( dispatcher.post(SongEvent(
user.token, user.token!!,
SongType.REMOVE, SongType.REMOVE,
null, null,
null, null,
@ -123,7 +123,7 @@ fun Routing.wsSongListRoutes() {
val song = SongListService.getSong(user)[0] val song = SongListService.getSong(user)[0]
SongListService.deleteSong(user, song.uid, song.name) SongListService.deleteSong(user, song.uid, song.name)
dispatcher.post(SongEvent( dispatcher.post(SongEvent(
user.token, user.token!!,
SongType.NEXT, SongType.NEXT,
null, null,
null, null,