This commit is contained in:
lunaticbum 2025-03-12 22:35:13 +09:00
parent e909df301d
commit 1cfb379ecc
4 changed files with 104 additions and 143 deletions

View File

@ -44,7 +44,7 @@ class BumsInterceptor : HandlerInterceptor {
handler: Any, handler: Any,
@Nullable modelAndView: ModelAndView? @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 (!skippResourcesExtension) {
if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter { if (request.requestURI.contains("logout") == false && !request.cookies.isNullOrEmpty() && request.cookies.filter {
it.name.equals( it.name.equals(

View File

@ -144,6 +144,9 @@ class Telegram {
try { try {
var pref = Preferences.userNodeForPackage(Telegram::class.java) var pref = Preferences.userNodeForPackage(Telegram::class.java)
var prefKey = pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"") var prefKey = pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"")
if (prefKey?.length ?: 0 < 4) {
prefKey = globalEvv.gapiKey
}
println("prefKey >> ${prefKey}") println("prefKey >> ${prefKey}")
if (prefKey != null && prefKey.length > 0) { if (prefKey != null && prefKey.length > 0) {
println("test strat ${msg.location}") println("test strat ${msg.location}")
@ -222,78 +225,78 @@ class Telegram {
} }
} }
} else if(msg.text?.startsWith("/") == true) { } else if(msg.text?.startsWith("/") == true) {
msg.text?.split(" ")?.let { cmds -> // msg.text?.split(" ")?.let { cmds ->
cmds[0].let { cmd -> // cmds[0].let { cmd ->
when(cmd.trim()) { // when(cmd.trim()) {
"/reqGapiKeys" -> { // "/reqGapiKeys" -> {
sendSimpleMsg(globalEvv.telegramBotKey!!,globalEvv.telegramMyId!!,"${msg.from!!.id.toString()}님이 서비스 키를 요첨항./setGaipKeys {key}") // sendSimpleMsg(globalEvv.telegramBotKey!!,globalEvv.telegramMyId!!,"${msg.from!!.id.toString()}님이 서비스 키를 요첨항./setGaipKeys {key}")
} // }
"/setGaipKeys" -> { // "/setGaipKeys" -> {
var pref = Preferences.userNodeForPackage(Telegram::class.java) // var pref = Preferences.userNodeForPackage(Telegram::class.java)
pref.put("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()), cmds[1]) // pref.put("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()), cmds[1])
pref.sync() // pref.sync()
println("test prefKey ${"GAPI_KEY".plus("_").plus(msg.from!!.id.toString())}") // println("test prefKey ${"GAPI_KEY".plus("_").plus(msg.from!!.id.toString())}")
println("test prefKey ${cmds[1]}") // println("test prefKey ${cmds[1]}")
println("test prefKey ${pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"")}") // println("test prefKey ${pref.get("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()),"")}")
//
} // }
"/get" ->{} // "/get" ->{}
"/jf" ->{ // "/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 { // 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) } // val fullUrl =
// logService.log("${cmd} END ${cmds[1]}") // "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 { // CoroutineScope(Dispatchers.IO).launch {
// logService.log("on Cmd JF with SO")
// logService.log("${cmd} Start ${cmds[1]}") // logService.log("${cmd} Start ${cmds[1]}")
// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)} //// msg.chat?.id
// logService.log("${cmd} END ${cmds[1]}") // 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" -> { // else -> {}
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 if (msg.text?.contains("어디") == true) { } else if (msg.text?.contains("어디") == true) {
msg.from?.id?.let { sendMsg(it.toString()) } msg.from?.id?.let { sendMsg(it.toString()) }
} else { } else {
@ -301,7 +304,7 @@ class Telegram {
val req = BumlamaReq(msg.text) val req = BumlamaReq(msg.text)
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val fullUrl = 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}") logService.log("fullUrl >>> ${fullUrl}")
WebClient.create().get() WebClient.create().get()
.uri(fullUrl) .uri(fullUrl)
@ -309,62 +312,11 @@ class Telegram {
.bodyToMono(String::class.java).block() .bodyToMono(String::class.java).block()
} }
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
try { var originalQuery = msg.text
if (req.reqMsg?.contains("주변") == true) { lama.generateResponse(originalQuery?.replace("오늘","오늘(${SimpleDateFormat("yyyy-MM-dd").format(Date())})"),msg.from?.id.toString())
// 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()
}
} }
} }
} }
logService.log("test $httpServletRequest.requestURI") logService.log("test $httpServletRequest.requestURI")
} catch (e : Exception) { } catch (e : Exception) {

View File

@ -147,28 +147,37 @@ class Lama {
refinedQuery?.keywords?.let { querys.add(it.joinToString { " " })} refinedQuery?.keywords?.let { querys.add(it.joinToString { " " })}
val readedUrls = ArrayList<String>() val readedUrls = ArrayList<String>()
querys.forEach { refinedQuery -> 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" CoroutineScope(Dispatchers.IO).launch {
println("gSearch >>> ${gSearch}") val gSearch = "https://psn.lunaticbum.kr/search?q=${
WebClient.create().get() refinedQuery?.replace(
.uri(gSearch) "오늘",
.retrieve() SimpleDateFormat("yyyMMdd").format(Date())
.bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult -> )
gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4}?.forEach { }&language=ko&time_range=month&safesearch=0&categories=general&format=json"
println("in filter ${it.url}") println("gSearch >>> ${gSearch}")
if (readedUrls.contains(it.url) == false) { WebClient.create().get()
readedUrls.add(it.url!!) .uri(gSearch)
it.originQuery = query .retrieve()
it.refinedQuery = refinedQuery .bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult ->
println(it.title) gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4 }?.forEach {
try { println("in filter ${it.url}")
jsopFilter(it.url!!).let { text -> if (readedUrls.contains(it.url) == false) {
it.originHtml = text readedUrls.add(it.url!!)
webPageSummarize(it,text) 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") println("end of search")
} }
} }

View File

@ -119,7 +119,7 @@
<div class="box highlight"> <div class="box highlight">
<i class="icon solid major fa-pencil-alt"></i> <i class="icon solid major fa-pencil-alt"></i>
<h3>글쓰기[Writing]</h3> <h3>글쓰기[Writing]</h3>
<br>오직 주인장 만의 권한 임요. 그냥 내가 쓰기 편하게 여기 놔둔 메뉴임. 님들은 못씀요.<br>[Only the owner has the authority. This is just a menu that I put here for my convenience. You can't use it.]</p> <p>오직 주인장 만의 권한 임요. 그냥 내가 쓰기 편하게 여기 놔둔 메뉴임. 님들은 못씀요.<br>[Only the owner has the authority. This is just a menu that I put here for my convenience. You can't use it.]</p>
</div> </div>
</section> </section>
<section class="col-4 col-12-narrower"> <section class="col-4 col-12-narrower">