mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-08-07 21:01:14 +00:00
[feature] some logic fixed.
This commit is contained in:
@@ -52,6 +52,20 @@ data class NicknameColor(
|
||||
val colorCode: String = ""
|
||||
)
|
||||
|
||||
data class LiveStatus(
|
||||
val liveTitle: String,
|
||||
val status: String,
|
||||
val concurrentUserCount: Int,
|
||||
val accumulateCount: Int,
|
||||
val paidPromotion: Boolean,
|
||||
val adult: Boolean,
|
||||
val krOnlyViewing: Boolean,
|
||||
val openDate: String,
|
||||
val closeDate: String?,
|
||||
val clipActive: Boolean,
|
||||
val chatChannelId: String
|
||||
)
|
||||
|
||||
// OkHttpClient에 Interceptor 추가
|
||||
val client = OkHttpClient.Builder()
|
||||
.addNetworkInterceptor { chain ->
|
||||
@@ -84,3 +98,24 @@ fun getFollowDate(chatID: String, userId: String) : IData<IFollowContent?> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getChzzkChannelId(channelId: String): String? {
|
||||
val url = "https://api.chzzk.naver.com/polling/v3/channels/$channelId/live-status?includePlayerRecommendContent=false"
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.get()
|
||||
.build()
|
||||
|
||||
client.newCall(request).execute().use { response ->
|
||||
try {
|
||||
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
|
||||
val body = response.body?.string()
|
||||
val data = gson.fromJson(body, object: TypeToken<IData<LiveStatus?>>() {})
|
||||
|
||||
return data.content?.chatChannelId
|
||||
} catch(e: Exception) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user