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,
@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(

View File

@ -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) {

View File

@ -147,28 +147,37 @@ class Lama {
refinedQuery?.keywords?.let { querys.add(it.joinToString { " " })}
val readedUrls = ArrayList<String>()
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")
}
}

View File

@ -119,7 +119,7 @@
<div class="box highlight">
<i class="icon solid major fa-pencil-alt"></i>
<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>
</section>
<section class="col-4 col-12-narrower">