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_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 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 VERSION_DELTA: Option[String] = None
|
||||||
val CODENAME = "guanggu"
|
val CODENAME = "guanggu"
|
||||||
|
|
||||||
|
@ -24,9 +24,17 @@ class GetSocial (using coeur: MornyCoeur) extends ITelegramCommand {
|
|||||||
TelegramStickers.ID_404
|
TelegramStickers.ID_404
|
||||||
).replyToMessageId(event.message.messageId())
|
).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()
|
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.reporter.MornyReport
|
||||||
import cc.sukazyo.cono.morny.social_share.api.{SocialTwitterParser, SocialWeiboParser}
|
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.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.Chat
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode
|
import com.pengrad.telegrambot.model.request.ParseMode
|
||||||
import com.pengrad.telegrambot.request.{SendMessage, SendSticker}
|
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 messageEvent.text == null then return;
|
||||||
|
|
||||||
if tryFetchSocial(
|
if tryFetchSocial(
|
||||||
Left((
|
Left(messageEvent.textWithUrls)
|
||||||
messageEvent.text :: messageEvent.entitiesSafe.map(f => f.url).filterNot(f => f == null)
|
|
||||||
).mkString(" "))
|
|
||||||
)(using messageEvent.chat.id, messageEvent.messageId) then
|
)(using messageEvent.chat.id, messageEvent.messageId) then
|
||||||
event.setEventOk
|
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 cc.sukazyo.cono.morny.social_share.external.twitter.FXApi
|
||||||
import io.circe.{DecodingFailure, ParsingFailure}
|
import io.circe.{DecodingFailure, ParsingFailure}
|
||||||
import sttp.client3.SttpClientException
|
import sttp.client3.SttpClientException
|
||||||
@ -90,7 +88,7 @@ object OnGetSocial {
|
|||||||
"Error on requesting FixTweet API\n" + exceptionLog(e)
|
"Error on requesting FixTweet API\n" + exceptionLog(e)
|
||||||
coeur.externalContext.consume[MornyReport](_.exception(e, "Error on requesting FixTweet API"))
|
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 cc.sukazyo.cono.morny.social_share.external.weibo.MApi
|
||||||
import io.circe.{DecodingFailure, ParsingFailure}
|
import io.circe.{DecodingFailure, ParsingFailure}
|
||||||
import sttp.client3.{HttpError, SttpClientException}
|
import sttp.client3.{HttpError, SttpClientException}
|
||||||
|
@ -72,6 +72,10 @@ object TelegramExtensions {
|
|||||||
if self.entities == null then Nil else
|
if self.entities == null then Nil else
|
||||||
self.entities.toList
|
self.entities.toList
|
||||||
|
|
||||||
|
def textWithUrls: String =
|
||||||
|
(self.text :: self.entitiesSafe.map(_.url).filterNot(_ == null))
|
||||||
|
.mkString(" ")
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
class LimboUser (id: Long) extends User(id)
|
class LimboUser (id: Long) extends User(id)
|
||||||
|
Loading…
Reference in New Issue
Block a user