mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 03:04:54 +08:00
inline get social content now can search all available links in query texts
This commit is contained in:
parent
02819a9069
commit
1230b9e6b5
@ -4,6 +4,8 @@ import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener}
|
||||
import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, MornyQueries}
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
import com.google.gson.Gson
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
import com.pengrad.telegrambot.model.request.InlineQueryResult
|
||||
import com.pengrad.telegrambot.request.AnswerInlineQuery
|
||||
@ -30,6 +32,8 @@ class MornyOnInlineQuery (using queryManager: MornyQueries) (using coeur: MornyC
|
||||
|
||||
if (results isEmpty) return;
|
||||
|
||||
logger debug resultAnswers.map(Gson().toJson(_)).mkString("\n")
|
||||
|
||||
coeur.account exec AnswerInlineQuery(
|
||||
update.inlineQuery.id, resultAnswers toArray:_*
|
||||
).cacheTime(cacheTime).isPersonal(isPersonal)
|
||||
|
@ -73,7 +73,7 @@ object OnGetSocial {
|
||||
|
||||
}
|
||||
|
||||
def tryFetchSocialOfTweet (url: twitter.TweetUrlInformation)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
private def tryFetchSocialOfTweet (url: twitter.TweetUrlInformation)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
import io.circe.{DecodingFailure, ParsingFailure}
|
||||
import sttp.client3.SttpClientException
|
||||
import twitter.FXApi
|
||||
@ -89,7 +89,7 @@ object OnGetSocial {
|
||||
"Error on requesting FixTweet API\n" + exceptionLog(e)
|
||||
coeur.daemons.reporter.exception(e, "Error on requesting FixTweet API")
|
||||
|
||||
def tryFetchSocialOfWeibo (url: weibo.StatusUrlInfo)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
private def tryFetchSocialOfWeibo (url: weibo.StatusUrlInfo)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
import io.circe.{DecodingFailure, ParsingFailure}
|
||||
import sttp.client3.{HttpError, SttpClientException}
|
||||
import weibo.MApi
|
||||
|
@ -6,7 +6,7 @@ import com.pengrad.telegrambot.model.request.InlineQueryResult
|
||||
object InlineQueryUnit {
|
||||
|
||||
object defaults:
|
||||
val CACHE_TIME = 300
|
||||
val CACHE_TIME = 1
|
||||
val IS_PERSONAL = false
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cc.sukazyo.cono.morny.bot.query
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.query
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
|
||||
|
@ -1,43 +1,40 @@
|
||||
package cc.sukazyo.cono.morny.bot.query
|
||||
|
||||
import cc.sukazyo.cono.morny.data.social.{SocialTwitterParser, SocialWeiboParser}
|
||||
import cc.sukazyo.cono.morny.extra.{twitter, weibo}
|
||||
import cc.sukazyo.cono.morny.extra.twitter.{FXApi, TweetUrlInformation}
|
||||
import cc.sukazyo.cono.morny.extra.weibo.{MApi, StatusUrlInfo}
|
||||
import cc.sukazyo.cono.morny.extra.twitter.FXApi
|
||||
import cc.sukazyo.cono.morny.extra.weibo.MApi
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
|
||||
class ShareToolSocialContent extends ITelegramQuery {
|
||||
|
||||
override def query (event: Update): List[InlineQueryUnit[_]] | Null = {
|
||||
|
||||
val _queryRaw = event.inlineQuery.query
|
||||
val query =
|
||||
_queryRaw.trim match
|
||||
case _startsWithTag if _startsWithTag startsWith "get " =>
|
||||
(_startsWithTag drop 4)trim
|
||||
case _endsWithTag if _endsWithTag endsWith " get" =>
|
||||
(_endsWithTag dropRight 4)trim
|
||||
case _ => return null
|
||||
val query = event.inlineQuery.query
|
||||
if query == null then return null
|
||||
|
||||
(
|
||||
twitter.parseTweetUrl(query) match
|
||||
case Some(TweetUrlInformation(_, statusPath, _, statusId, _, _)) =>
|
||||
SocialTwitterParser.parseFXTweet(FXApi.Fetch.status(Some(statusPath), statusId))
|
||||
twitterTweets(query) ::: weiboStatus(query)
|
||||
|
||||
}
|
||||
|
||||
private def twitterTweets (query: String): List[InlineQueryUnit[_]] = {
|
||||
twitter.guessTweetUrl(query).flatMap { tweet =>
|
||||
SocialTwitterParser.parseFXTweet(FXApi.Fetch.status(Some(tweet.statusPath), tweet.statusId))
|
||||
.genInlineQueryResults(using
|
||||
"morny/share/tweet/content", statusId,
|
||||
"morny/share/tweet/content", tweet.statusId,
|
||||
"Twitter Tweet Content"
|
||||
)
|
||||
case None => Nil
|
||||
) ::: (
|
||||
weibo.parseWeiboStatusUrl(query) match
|
||||
case Some(StatusUrlInfo(_, id)) =>
|
||||
SocialWeiboParser.parseMStatus(MApi.Fetch.statuses_show(id))
|
||||
}
|
||||
}
|
||||
|
||||
private def weiboStatus (query: String): List[InlineQueryUnit[_]] = {
|
||||
weibo.guessWeiboStatusUrl(query).flatMap { status =>
|
||||
SocialWeiboParser.parseMStatus(MApi.Fetch.statuses_show(status.id))
|
||||
.genInlineQueryResults(using
|
||||
"morny/share/weibo/status/content", id,
|
||||
"morny/share/weibo/status/content", status.id,
|
||||
"Weibo Content"
|
||||
)
|
||||
case None => Nil
|
||||
) ::: Nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,19 +2,17 @@ package cc.sukazyo.cono.morny.bot.query
|
||||
|
||||
import cc.sukazyo.cono.morny.extra.twitter
|
||||
import cc.sukazyo.cono.morny.extra.twitter.TweetUrlInformation
|
||||
import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils.inlineQueryId
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
import com.pengrad.telegrambot.model.request.InlineQueryResultArticle
|
||||
|
||||
import scala.language.postfixOps
|
||||
import scala.util.matching.Regex
|
||||
|
||||
class ShareToolTwitter extends ITelegramQuery {
|
||||
|
||||
private val TITLE_VX = "[tweet] Share as VxTwitter"
|
||||
private val ID_PREFIX_VX = "[morny/share/twitter/vxtwi]"
|
||||
private val ID_PREFIX_VX = "[morny/share/twitter/vx_url]"
|
||||
private val TITLE_FX = "[tweet] Share as Fix-Tweet"
|
||||
private val ID_PREFIX_FX = "[morny/share/twitter/fxtwi]"
|
||||
private val ID_PREFIX_FX = "[morny/share/twitter/fx_url]"
|
||||
|
||||
override def query (event: Update): List[InlineQueryUnit[_]] | Null = {
|
||||
|
||||
|
@ -62,7 +62,7 @@ case class SocialContent (
|
||||
(
|
||||
if (medias_mosaic nonEmpty) && (medias_mosaic.get.t == Photo) && medias_mosaic.get.isInstanceOf[SocialMediaWithUrl] then
|
||||
InlineQueryUnit(InlineQueryResultPhoto(
|
||||
inlineQueryId(s"[$id_head/photo/mosaic]$id_param"),
|
||||
s"[$id_head/photo/mosaic]$id_param",
|
||||
medias_mosaic.get.asInstanceOf[SocialMediaWithUrl].url,
|
||||
thumbnailOrElse(medias_mosaic.get.asInstanceOf[SocialMediaWithUrl].url)
|
||||
).title(s"$name").caption(text_html).parseMode(ParseMode.HTML)) :: Nil
|
||||
@ -71,18 +71,20 @@ case class SocialContent (
|
||||
media match
|
||||
case media_url: SocialMediaWithUrl =>
|
||||
InlineQueryUnit(InlineQueryResultPhoto(
|
||||
inlineQueryId(s"[$id_head/photo/0]$id_param"),
|
||||
s"[$id_head/photo/0]$id_param",
|
||||
media_url.url,
|
||||
thumbnailOrElse(media_url.url)
|
||||
).title(s"$name").caption(text_html).parseMode(ParseMode.HTML)) :: Nil
|
||||
case _ =>
|
||||
InlineQueryUnit(InlineQueryResultArticle(
|
||||
inlineQueryId(s"[$id_head/text_only]$id_param"), s"$name (text only)",
|
||||
s"[$id_head/text_only]$id_param",
|
||||
s"$name (text only)",
|
||||
InputTextMessageContent(text_withPicPlaceholder).parseMode(ParseMode.HTML)
|
||||
)) :: Nil
|
||||
else
|
||||
InlineQueryUnit(InlineQueryResultArticle(
|
||||
inlineQueryId(s"[$id_head/text]$id_param"), s"$name",
|
||||
s"[$id_head/text]$id_param",
|
||||
s"$name",
|
||||
InputTextMessageContent(text_html).parseMode(ParseMode.HTML)
|
||||
)) :: Nil
|
||||
) ::: Nil
|
||||
|
Loading…
Reference in New Issue
Block a user