fix some bugs 5(alert final fix)

This commit is contained in:
dalbodeule 2024-06-17 18:19:40 +09:00
parent a774418259
commit 035a6dc6cd
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
2 changed files with 15 additions and 17 deletions

View File

@ -2,7 +2,6 @@ package space.mori.chzzk_bot.chzzk
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.IOException
@ -91,20 +90,17 @@ data class AdParameter(
val tag: String = ""
)
// User-Agent 헤더를 설정하는 Interceptor
val userAgentInterceptor = Interceptor { chain ->
val originalRequest = chain.request()
val requestWithUserAgent = originalRequest.newBuilder()
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36\n")
.build()
chain.proceed(requestWithUserAgent)
}
// OkHttpClient에 Interceptor 추가
val client = OkHttpClient.Builder()
.addInterceptor(userAgentInterceptor)
.addNetworkInterceptor { chain ->
chain.proceed(
chain.request()
.newBuilder()
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
.build()
)
}
.build()
val gson = Gson()
fun getFollowDate(chatID: String, userId: String) : IData<IFollowContent> {

View File

@ -55,7 +55,7 @@ object ChzzkHandler {
internal fun runStreamInfo() {
running = true
Thread {
val thread = Thread({
while(running) {
handlers.forEach {
if (!running) return@forEach
@ -64,16 +64,18 @@ object ChzzkHandler {
if (streamInfo.content.status == "OPEN" && !it.isActive) it.isActive(true, streamInfo)
if (streamInfo.content.status == "CLOSED" && it.isActive) it.isActive(false, streamInfo)
} catch(e: SocketTimeoutException) {
logger.info("timeout: ${it.channel.channelName}")
logger.info("Timeout: ${it.channel.channelName} / ${e.stackTraceToString()}")
} catch (e: Exception) {
logger.info("Exception: ${it.channel.channelName}")
logger.info("Exception: ${it.channel.channelName} / ${e.stackTraceToString()}")
} finally {
Thread.sleep(5000)
}
}
Thread.sleep(60000)
}
}.start()
}, "Chzzk-StreamInfo")
thread.start()
}
internal fun stopStreamInfo() {
@ -138,7 +140,7 @@ class UserHandler(
if(value) {
logger.info("${user.username} is live.")
if(user.liveAlertMessage != "" && user.liveAlertGuild != null && user.liveAlertChannel != null) {
val channel = discord.getChannel(user.liveAlertGuild!!, user.liveAlertGuild!!) ?: throw RuntimeException("${user.liveAlertChannel} is not valid.")
val channel = discord.getChannel(user.liveAlertGuild!!, user.liveAlertChannel!!) ?: throw RuntimeException("${user.liveAlertChannel} is not valid.")
val embed = EmbedBuilder()
embed.setTitle(status.content.liveTitle, "https://chzzk.naver.com/live/${user.token}")