mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
code optimize
and change debug logs on Nbnhhsh command to trace logs
This commit is contained in:
parent
c19134811d
commit
e6b68ae307
@ -45,26 +45,26 @@ class Nbnhhsh (using coeur: MornyCoeur) extends ITelegramCommand {
|
||||
val message = StringBuilder(NBNHHSH_RESULT_HEAD_HTML)
|
||||
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
logger debug s"**xx len=${queryResp.words.length}"
|
||||
logger trace s"**nbnhhsh got len=${queryResp.words.length}"
|
||||
for (_word <- queryResp.words) {
|
||||
logger debug "**exec"
|
||||
logger trace s"**start for ${_word.name}"
|
||||
val _use_trans = (_word.trans ne null) && (_word.trans nonEmpty)
|
||||
val _use_inputting = (_word.inputting ne null) && (_word.inputting nonEmpty)
|
||||
if (_use_trans || _use_inputting)
|
||||
message ++= s"\n\n<b>[[ ${h(_word.name)} ]]</b>"
|
||||
logger debug s"**used [${_word.name}]"
|
||||
logger trace s"**used [${_word.name}]"
|
||||
if (_use_trans) for (_trans <- _word.trans)
|
||||
message ++= s"\n* <i>${h(_trans)}</i>"
|
||||
logger debug s"**used [${_word.name}] used `${_trans}``"
|
||||
logger trace s"**used [${_word.name}] used `${_trans}``"
|
||||
if (_use_inputting)
|
||||
logger debug s"**used [${_word.name}] inputting"
|
||||
logger trace s"**used [${_word.name}] inputting"
|
||||
if (_use_trans)
|
||||
message += '\n'
|
||||
message ++= " maybe:"
|
||||
for (_inputting <- _word.inputting)
|
||||
logger debug s"**used [${_word.name}] used-i ${_inputting}"
|
||||
logger trace s"**used [${_word.name}] used-i ${_inputting}"
|
||||
message ++= s"\n` <i>${h(_inputting)}</i>"
|
||||
logger debug s"**exec as ${_word.name}"
|
||||
logger trace s"**done"
|
||||
}
|
||||
|
||||
coeur.account exec SendMessage(
|
||||
|
@ -7,11 +7,13 @@ import sttp.model.MediaType
|
||||
|
||||
object NbnhhshQuery {
|
||||
|
||||
case class Word (name: String, trans: Array[String], inputting: Array[String])
|
||||
case class Word (
|
||||
name: String,
|
||||
trans: Array[String] = Array.empty,
|
||||
inputting: Array[String] = Array.empty
|
||||
)
|
||||
case class GuessResult (words: Array[Word])
|
||||
|
||||
private case class GuessRequest (text: String)
|
||||
|
||||
private val API_URL = uri"https://lab.magiconch.com/api/nbnhhsh/"
|
||||
private val API_GUESS_METHOD = uri"$API_URL/guess/"
|
||||
|
||||
@ -19,12 +21,13 @@ object NbnhhshQuery {
|
||||
|
||||
@throws[HttpError[_]|SttpClientException]
|
||||
def sendGuess (text: String): GuessResult = {
|
||||
case class GuessRequest (text: String)
|
||||
val http = basicRequest
|
||||
.body(Gson().toJson(GuessRequest(text))).contentType(MediaType.ApplicationJson)
|
||||
.post(API_GUESS_METHOD)
|
||||
.response(asString.getRight)
|
||||
.send(httpClient)
|
||||
Gson().fromJson(s"{ 'words': ${http.body} }", classOf[GuessResult])
|
||||
GuessResult(Gson().fromJson(http.body, classOf[Array[Word]]))
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user