mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
add replyTo support for /get
This commit is contained in:
parent
c5fef1359d
commit
2374d39b41
@ -8,7 +8,7 @@ object MornyConfiguration {
|
||||
val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono"
|
||||
val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s"
|
||||
|
||||
val VERSION = "2.0.0-alpha8"
|
||||
val VERSION = "2.0.0-alpha9"
|
||||
val VERSION_DELTA: Option[String] = None
|
||||
val CODENAME = "guanggu"
|
||||
|
||||
|
@ -24,9 +24,17 @@ class GetSocial (using coeur: MornyCoeur) extends ITelegramCommand {
|
||||
TelegramStickers.ID_404
|
||||
).replyToMessageId(event.message.messageId())
|
||||
|
||||
if command.args.length < 1 then { do404(); return }
|
||||
val content =
|
||||
if command.args.length > 0 then
|
||||
Right(command.args(0))
|
||||
else if event.message.replyToMessage != null then
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.textWithUrls
|
||||
Left(event.message.replyToMessage.textWithUrls)
|
||||
else
|
||||
do404()
|
||||
return
|
||||
|
||||
if !OnGetSocial.tryFetchSocial(Right(command.args(0)))(using event.message.chat.id, event.message.messageId) then
|
||||
if !OnGetSocial.tryFetchSocial(content)(using event.message.chat.id, event.message.messageId) then
|
||||
do404()
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import cc.sukazyo.cono.morny.Log.{exceptionLog, logger}
|
||||
import cc.sukazyo.cono.morny.reporter.MornyReport
|
||||
import cc.sukazyo.cono.morny.social_share.api.{SocialTwitterParser, SocialWeiboParser}
|
||||
import cc.sukazyo.cono.morny.social_share.external.{twitter, weibo}
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.entitiesSafe
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.textWithUrls
|
||||
import com.pengrad.telegrambot.model.Chat
|
||||
import com.pengrad.telegrambot.model.request.ParseMode
|
||||
import com.pengrad.telegrambot.request.{SendMessage, SendSticker}
|
||||
@ -23,9 +23,7 @@ class OnGetSocial (using coeur: MornyCoeur) extends EventListener {
|
||||
if messageEvent.text == null then return;
|
||||
|
||||
if tryFetchSocial(
|
||||
Left((
|
||||
messageEvent.text :: messageEvent.entitiesSafe.map(f => f.url).filterNot(f => f == null)
|
||||
).mkString(" "))
|
||||
Left(messageEvent.textWithUrls)
|
||||
)(using messageEvent.chat.id, messageEvent.messageId) then
|
||||
event.setEventOk
|
||||
|
||||
@ -74,7 +72,7 @@ object OnGetSocial {
|
||||
|
||||
}
|
||||
|
||||
def tryFetchSocialOfTweet (url: twitter.TweetUrlInformation)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
def tryFetchSocialOfTweet (url: twitter.TweetUrlInformation)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur): Unit =
|
||||
import cc.sukazyo.cono.morny.social_share.external.twitter.FXApi
|
||||
import io.circe.{DecodingFailure, ParsingFailure}
|
||||
import sttp.client3.SttpClientException
|
||||
@ -90,7 +88,7 @@ object OnGetSocial {
|
||||
"Error on requesting FixTweet API\n" + exceptionLog(e)
|
||||
coeur.externalContext.consume[MornyReport](_.exception(e, "Error on requesting FixTweet API"))
|
||||
|
||||
def tryFetchSocialOfWeibo (url: weibo.StatusUrlInfo)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) =
|
||||
def tryFetchSocialOfWeibo (url: weibo.StatusUrlInfo)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur): Unit =
|
||||
import cc.sukazyo.cono.morny.social_share.external.weibo.MApi
|
||||
import io.circe.{DecodingFailure, ParsingFailure}
|
||||
import sttp.client3.{HttpError, SttpClientException}
|
||||
|
@ -72,6 +72,10 @@ object TelegramExtensions {
|
||||
if self.entities == null then Nil else
|
||||
self.entities.toList
|
||||
|
||||
def textWithUrls: String =
|
||||
(self.text :: self.entitiesSafe.map(_.url).filterNot(_ == null))
|
||||
.mkString(" ")
|
||||
|
||||
}}
|
||||
|
||||
class LimboUser (id: Long) extends User(id)
|
||||
|
Loading…
Reference in New Issue
Block a user