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,113 +225,60 @@ 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" -> {
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 { // "/setGaipKeys" -> {
// logService.log("on Cmd JF with SO") // var pref = Preferences.userNodeForPackage(Telegram::class.java)
// logService.log("${cmd} Start ${cmds[1]}") // pref.put("GAPI_KEY".plus("_").plus(msg.from!!.id.toString()), cmds[1])
// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)} // pref.sync()
// logService.log("${cmd} END ${cmds[1]}") // 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" ->{}
"/lama" -> { // "/jf" ->{
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}") //// CoroutineScope(Dispatchers.IO).launch {
WebClient.create().get() //// logService.log("on Cmd JF with SO")
.uri(fullUrl) //// logService.log("${cmd} Start ${cmds[1]}")
.retrieve() //// String.format(String(Base64.getMimeDecoder().decode("aHR0cHM6Ly9rcjcwLnNvZ2lybC5zby8/cz0lcw==".toByteArray())),cmds[1]).getJ().let { doc -> FeedParseManager.parse(doc,rssDataService)}
.bodyToMono(String::class.java).block() //// logService.log("${cmd} END ${cmds[1]}")
} //// }
CoroutineScope(Dispatchers.IO).launch { // }
logService.log("${cmd} Start ${cmds[1]}") // "/lama" -> {
// msg.chat?.id // val req = BumlamaReq(msg.text!!.replace(cmd,""))
try { // CoroutineScope(Dispatchers.IO).launch {
val client = WebClient.create() //
client.post() // val fullUrl =
.uri(lamaGenerated) // "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=lama 에게 전송 ${req.reqMsg}"
.body(BodyInserters.fromValue(Gson().toJson(req))) // logService.log("fullUrl >>> ${fullUrl}")
.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) {
msg.from?.id?.let { sendMsg(it.toString()) }
} else {
println(msg.text)
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}"
logService.log("fullUrl >>> ${fullUrl}")
WebClient.create().get()
.uri(fullUrl)
.retrieve()
.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() // WebClient.create().get()
// .uri(gSearch) // .uri(fullUrl)
// .retrieve() // .retrieve()
// .bodyToMono(GoogleSearchResult::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { result -> // .bodyToMono(String::class.java).block()
// println("gsearch result ==> ${Gson().toJson(result)}") // }
// req.reqMsg = req.reqMsg + "\n\n" + result.items?.map { it.snippet +"\nurl:"+it.link }?.joinToString { "\n" } // CoroutineScope(Dispatchers.IO).launch {
// logService.log("${cmd} Start ${cmds[1]}")
//// msg.chat?.id
// try {
// val client = WebClient.create() // val client = WebClient.create()
// client.post() // client.post()
// .uri("https://lama.lunaticbum.kr/api/generate") // .uri(lamaGenerated)
// .body(BodyInserters.fromValue(Gson().toJson(req))) // .body(BodyInserters.fromValue(Gson().toJson(req)))
// .retrieve() // .retrieve()
// .bodyToMono(String::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { result -> // .bodyToMono(String::class.java).timeout(Duration.ofSeconds(6000L)).block()?.let { result ->
// println("generate Result ==> ${result}")
// Gson().fromJson(result, BumlamaResp::class.java)?.let { sss -> // Gson().fromJson(result, BumlamaResp::class.java)?.let { sss ->
// println(Gson().toJson(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}" // val fullUrl = "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${sss.response}"
// logService.log("fullUrl >>> ${fullUrl}") // logService.log("fullUrl >>> ${fullUrl}")
// WebClient.create().get() // WebClient.create().get()
// .uri(fullUrl) // .uri(fullUrl)
@ -336,36 +286,38 @@ class Telegram {
// .bodyToMono(String::class.java).block() ?: "FAIL" // .bodyToMono(String::class.java).block() ?: "FAIL"
// } // }
// } // }
// } catch (e: Exception) {
// e.printStackTrace()
// } // }
//
} else if (req.reqMsg?.contains("검색") == true) { // logService.log("${cmd[0]} END ${cmd[1]}")
var originalQuery = req.reqMsg // }
lama.generateResponse(originalQuery,msg.from?.id.toString()) // }
// else -> {}
// }
// }
// }
} else if (msg.text?.contains("어디") == true) {
msg.from?.id?.let { sendMsg(it.toString()) }
} else { } else {
val client = WebClient.create() println(msg.text)
client.post() val req = BumlamaReq(msg.text)
.uri(lamaGenerated) CoroutineScope(Dispatchers.IO).launch {
.body(BodyInserters.fromValue(Gson().toJson(req))) val fullUrl =
.retrieve() "https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=blama 일시키겠=> '${req.reqMsg}'"
.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}") logService.log("fullUrl >>> ${fullUrl}")
WebClient.create().get() WebClient.create().get()
.uri(fullUrl) .uri(fullUrl)
.retrieve() .retrieve()
.bodyToMono(String::class.java).block() ?: "FAIL" .bodyToMono(String::class.java).block()
} }
CoroutineScope(Dispatchers.IO).launch {
var originalQuery = msg.text
lama.generateResponse(originalQuery?.replace("오늘","오늘(${SimpleDateFormat("yyyy-MM-dd").format(Date())})"),msg.from?.id.toString())
} }
} }
} catch (e: Exception) {
e.printStackTrace()
}
} }
}
}
logService.log("test $httpServletRequest.requestURI") logService.log("test $httpServletRequest.requestURI")
} catch (e : Exception) { } catch (e : Exception) {
} }

View File

@ -147,13 +147,19 @@ 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 {
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}") println("gSearch >>> ${gSearch}")
WebClient.create().get() WebClient.create().get()
.uri(gSearch) .uri(gSearch)
.retrieve() .retrieve()
.bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult -> .bodyToMono(SearXng::class.java).timeout(Duration.ofMinutes(20L)).block()?.let { gsResult ->
gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4}?.forEach { gsResult.results?.filter { it.url?.startsWith("https://") == true && it.score > 0.4 }?.forEach {
println("in filter ${it.url}") println("in filter ${it.url}")
if (readedUrls.contains(it.url) == false) { if (readedUrls.contains(it.url) == false) {
readedUrls.add(it.url!!) readedUrls.add(it.url!!)
@ -163,9 +169,12 @@ class Lama {
try { try {
jsopFilter(it.url!!).let { text -> jsopFilter(it.url!!).let { text ->
it.originHtml = text it.originHtml = text
webPageSummarize(it,text) webPageSummarize(it, text)
}
} catch (e: Exception) {
e.printStackTrace()
}
} }
}catch(e:Exception){e.printStackTrace()}
} }
} }
} }

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">