From 1cfb379ecc1e02b3014cf9bc84cc17e2462a7b89 Mon Sep 17 00:00:00 2001 From: lunaticbum Date: Wed, 12 Mar 2025 22:35:13 +0900 Subject: [PATCH] ... --- .../back/lun/configs/BumsInterceptor.kt | 2 +- .../back/lun/controllers/Telegram.kt | 196 +++++++----------- .../kr/lunaticbum/back/lun/service/Lama.kt | 47 +++-- .../resources/templates/content/home.html | 2 +- 4 files changed, 104 insertions(+), 143 deletions(-) diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt b/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt index 67f9bfc..d0b33c9 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/configs/BumsInterceptor.kt @@ -44,7 +44,7 @@ class BumsInterceptor : HandlerInterceptor { handler: Any, @Nullable modelAndView: ModelAndView? ) { - var skippResourcesExtension = arrayListOf(".ajax",".js",".css","/tlg/").filter { request.requestURI.contains(it)}.size > 0 + var skippResourcesExtension = arrayListOf(".ajax",".js",".css","/tlg/",".api").filter { request.requestURI.contains(it)}.size > 0 if (!skippResourcesExtension) { if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter { it.name.equals( diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt index 9fc35e4..1dde4f9 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/controllers/Telegram.kt @@ -144,6 +144,9 @@ class Telegram { try { var pref = Preferences.userNodeForPackage(Telegram::class.java) var prefKey = pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"") + if (prefKey?.length ?: 0 < 4) { + prefKey = globalEvv.gapiKey + } println("prefKey >> ${prefKey}") if (prefKey != null && prefKey.length > 0) { println("test strat ${msg.location}") @@ -222,78 +225,78 @@ class Telegram { } } } else if(msg.text?.startsWith("/") == true) { - msg.text?.split(" ")?.let { cmds -> - cmds[0].let { cmd -> - when(cmd.trim()) { - "/reqGapiKeys" -> { - sendSimpleMsg(globalEvv.telegramBotKey!!,globalEvv.telegramMyId!!,"${msg.from!!.id.toString()}님이 서비스 키를 요첨항./setGaipKeys {key}") - } - "/setGaipKeys" -> { - var pref = Preferences.userNodeForPackage(Telegram::class.java) - pref.put("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()), cmds[1]) - pref.sync() - println("test prefKey ${"GAPI_KEY".plus("_").plus(msg.from!!.id.toString())}") - println("test prefKey ${cmds[1]}") - println("test prefKey ${pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"")}") - - } - "/get" ->{} - "/jf" ->{ +// msg.text?.split(" ")?.let { cmds -> +// cmds[0].let { cmd -> +// when(cmd.trim()) { +// "/reqGapiKeys" -> { +// sendSimpleMsg(globalEvv.telegramBotKey!!,globalEvv.telegramMyId!!,"${msg.from!!.id.toString()}님이 서비스 키를 요첨항./setGaipKeys {key}") +// } +// "/setGaipKeys" -> { +// var pref = Preferences.userNodeForPackage(Telegram::class.java) +// pref.put("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()), cmds[1]) +// pref.sync() +// println("test prefKey ${"GAPI_KEY".plus("_").plus(msg.from!!.id.toString())}") +// println("test prefKey ${cmds[1]}") +// println("test prefKey ${pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"")}") +// +// } +// "/get" ->{} +// "/jf" ->{ +//// CoroutineScope(Dispatchers.IO).launch { +//// logService.log("${cmd} Start ${cmds[1]}") +//// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService) } +//// logService.log("${cmd} END ${cmds[1]}") +//// } +//// CoroutineScope(Dispatchers.IO).launch { +//// logService.log("on Cmd JF with SO") +//// logService.log("${cmd} Start ${cmds[1]}") +//// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)} +//// logService.log("${cmd} END ${cmds[1]}") +//// } +// } +// "/lama" -> { +// val req = BumlamaReq(msg.text!!.replace(cmd,"")) // CoroutineScope(Dispatchers.IO).launch { -// logService.log("${cmd} Start ${cmds[1]}") -// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9qYXZtb3N0LnRvL3NlYXJjaC9tb3ZpZS8lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService) } -// logService.log("${cmd} END ${cmds[1]}") +// +// val fullUrl = +// "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 ${req.reqMsg}" +// logService.log("fullUrl >>> ${fullUrl}") +// WebClient.create().get() +// .uri(fullUrl) +// .retrieve() +// .bodyToMono(String::class.java).block() // } // CoroutineScope(Dispatchers.IO).launch { -// logService.log("on Cmd JF with SO") // logService.log("${cmd} Start ${cmds[1]}") -// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)} -// logService.log("${cmd} END ${cmds[1]}") +//// msg.chat?.id +// try { +// val client = WebClient.create() +// client.post() +// .uri(lamaGenerated) +// .body(BodyInserters.fromValue(Gson().toJson(req))) +// .retrieve() +// .bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result -> +// Gson().fromJson(result, BumlamaResp::class.java)?.let { sss -> +// println(Gson().toJson(sss)) +// val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${sss.response}" +// logService.log("fullUrl >>> ${fullUrl}") +// WebClient.create().get() +// .uri(fullUrl) +// .retrieve() +// .bodyToMono(String::class.java).block() ?: "FAIL" +// } +// } +// } catch (e: Exception) { +// e.printStackTrace() +// } +// +// logService.log("${cmd[0]} END ${cmd[1]}") // } - } - "/lama" -> { - val req = BumlamaReq(msg.text!!.replace(cmd,"")) - CoroutineScope(Dispatchers.IO).launch { - - val fullUrl = - "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 ${req.reqMsg}" - logService.log("fullUrl >>> ${fullUrl}") - WebClient.create().get() - .uri(fullUrl) - .retrieve() - .bodyToMono(String::class.java).block() - } - CoroutineScope(Dispatchers.IO).launch { - logService.log("${cmd} Start ${cmds[1]}") -// msg.chat?.id - try { - val client = WebClient.create() - client.post() - .uri(lamaGenerated) - .body(BodyInserters.fromValue(Gson().toJson(req))) - .retrieve() - .bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result -> - Gson().fromJson(result, BumlamaResp::class.java)?.let { sss -> - println(Gson().toJson(sss)) - val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${sss.response}" - logService.log("fullUrl >>> ${fullUrl}") - WebClient.create().get() - .uri(fullUrl) - .retrieve() - .bodyToMono(String::class.java).block() ?: "FAIL" - } - } - } catch (e: Exception) { - e.printStackTrace() - } - - logService.log("${cmd[0]} END ${cmd[1]}") - } - } - else -> {} - } - } - } +// } +// else -> {} +// } +// } +// } } else if (msg.text?.contains("어디") == true) { msg.from?.id?.let { sendMsg(it.toString()) } } else { @@ -301,7 +304,7 @@ class Telegram { val req = BumlamaReq(msg.text) CoroutineScope(Dispatchers.IO).launch { val fullUrl = - "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 => ${req.reqMsg}" + "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=blama 일시키겠=> '${req.reqMsg}'" logService.log("fullUrl >>> ${fullUrl}") WebClient.create().get() .uri(fullUrl) @@ -309,62 +312,11 @@ class Telegram { .bodyToMono(String::class.java).block() } CoroutineScope(Dispatchers.IO).launch { - try { - if (req.reqMsg?.contains("주변") == true) { -// val gSearch = "https://www.googleapis.com/customsearch/v1?key=AIzaSyARLXyvmr_554tOy3UCh3naFlZQS3-qQQM&cx=207f328d3ad7242f2&q=${req.reqMsg}&num=5&lr=kr" -// println("gSearch >>> ${gSearch}") -// WebClient.create().get() -// .uri(gSearch) -// .retrieve() -// .bodyToMono(GoogleSearchResult::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { result -> -// println("gsearch result ==> ${Gson().toJson(result)}") -// req.reqMsg = req.reqMsg + "\n\n" + result.items?.map { it.snippet +"\nurl:"+it.link }?.joinToString { "\n" } -// val client = WebClient.create() -// client.post() -// .uri("https://lama.lunaticbum.kr/api/generate") -// .body(BodyInserters.fromValue(Gson().toJson(req))) -// .retrieve() -// .bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { result -> -// println("generate Result ==> ${result}") -// Gson().fromJson(result, BumlamaResp::class.java)?.let { sss -> -// println(Gson().toJson(sss)) -// val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${req.reqMsg}의 대답이 도착했어요.\n\n${sss.response}" -// logService.log("fullUrl >>> ${fullUrl}") -// WebClient.create().get() -// .uri(fullUrl) -// .retrieve() -// .bodyToMono(String::class.java).block() ?: "FAIL" -// } -// } -// } - - } else if (req.reqMsg?.contains("검색") == true) { - var originalQuery = req.reqMsg - lama.generateResponse(originalQuery,msg.from?.id.toString()) - } else { - val client = WebClient.create() - client.post() - .uri(lamaGenerated) - .body(BodyInserters.fromValue(Gson().toJson(req))) - .retrieve() - .bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { result -> - Gson().fromJson(result, BumlamaResp::class.java)?.let { sss -> - println(Gson().toJson(sss)) - val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${req.reqMsg}의 대답이 도착했어요.\n\n${sss.response}" - logService.log("fullUrl >>> ${fullUrl}") - WebClient.create().get() - .uri(fullUrl) - .retrieve() - .bodyToMono(String::class.java).block() ?: "FAIL" - } - } - } - } catch (e: Exception) { - e.printStackTrace() - } - + var originalQuery = msg.text + lama.generateResponse(originalQuery?.replace("오늘","오늘(${SimpleDateFormat("yyyy-MM-dd").format(Date())})"),msg.from?.id.toString()) } } + } logService.log("test $httpServletRequest.requestURI") } catch (e : Exception) { diff --git a/src/main/kotlin/kr/lunaticbum/back/lun/service/Lama.kt b/src/main/kotlin/kr/lunaticbum/back/lun/service/Lama.kt index 7d7d4c8..b8051b7 100644 --- a/src/main/kotlin/kr/lunaticbum/back/lun/service/Lama.kt +++ b/src/main/kotlin/kr/lunaticbum/back/lun/service/Lama.kt @@ -147,28 +147,37 @@ class Lama { refinedQuery?.keywords?.let { querys.add(it.joinToString { " " })} val readedUrls = ArrayList() querys.forEach { refinedQuery -> - val gSearch = "https://psn.lunaticbum.kr/search?q=${refinedQuery?.replace("오늘", SimpleDateFormat("yyyMMdd").format(Date()))}&language=ko&time_range=month&safesearch=0&categories=general&format=json" - println("gSearch >>> ${gSearch}") - WebClient.create().get() - .uri(gSearch) - .retrieve() - .bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult -> - gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4}?.forEach { - println("in filter ${it.url}") - if (readedUrls.contains(it.url) == false) { - readedUrls.add(it.url!!) - it.originQuery = query - it.refinedQuery = refinedQuery - println(it.title) - try { - jsopFilter(it.url!!).let { text -> - it.originHtml = text - webPageSummarize(it,text) + CoroutineScope(Dispatchers.IO).launch { + val gSearch = "https://psn.lunaticbum.kr/search?q=${ + refinedQuery?.replace( + "오늘", + SimpleDateFormat("yyyMMdd").format(Date()) + ) + }&language=ko&time_range=month&safesearch=0&categories=general&format=json" + println("gSearch >>> ${gSearch}") + WebClient.create().get() + .uri(gSearch) + .retrieve() + .bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult -> + gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4 }?.forEach { + println("in filter ${it.url}") + if (readedUrls.contains(it.url) == false) { + readedUrls.add(it.url!!) + it.originQuery = query + it.refinedQuery = refinedQuery + println(it.title) + try { + jsopFilter(it.url!!).let { text -> + it.originHtml = text + webPageSummarize(it, text) + } + } catch (e: Exception) { + e.printStackTrace() } - }catch(e:Exception){e.printStackTrace()} + } } } - } + } println("end of search") } } diff --git a/src/main/resources/templates/content/home.html b/src/main/resources/templates/content/home.html index 577abf3..aefe735 100644 --- a/src/main/resources/templates/content/home.html +++ b/src/main/resources/templates/content/home.html @@ -119,7 +119,7 @@

글쓰기[Writing]

-
오직 주인장 만의 권한 임요. 그냥 내가 쓰기 편하게 여기 놔둔 메뉴임. 님들은 못씀요.
[Only the owner has the authority. This is just a menu that I put here for my convenience. You can't use it.]

+

오직 주인장 만의 권한 임요. 그냥 내가 쓰기 편하게 여기 놔둔 메뉴임. 님들은 못씀요.
[Only the owner has the authority. This is just a menu that I put here for my convenience. You can't use it.]