Post support add extra video

This commit is contained in:
xtaodada 2024-03-21 16:04:56 +08:00
parent 2f43729837
commit 528a1a49a4
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -28,7 +28,7 @@ from gram_core.basemodel import Settings
from modules.apihelper.client.components.hoyolab import Hoyolab
from modules.apihelper.client.components.hyperion import Hyperion, HyperionBase
from modules.apihelper.error import APIHelperException
from modules.apihelper.models.genshin.hyperion import PostTypeEnum
from modules.apihelper.models.genshin.hyperion import ArtworkImage, PostTypeEnum
from utils.helpers import sha1
from utils.log import logger
@ -36,7 +36,6 @@ if TYPE_CHECKING:
from bs4 import Tag
from telegram import Update, Message
from telegram.ext import ContextTypes
from modules.apihelper.models.genshin.hyperion import ArtworkImage
class PostHandlerData:
@ -58,14 +57,16 @@ class PostConfig(Settings):
CHECK_POST, SEND_POST, CHECK_COMMAND, GTE_DELETE_PHOTO = range(10900, 10904)
GET_POST_CHANNEL, GET_TAGS, GET_TEXT = range(10904, 10907)
GET_POST_CHANNEL, GET_TAGS, GET_TEXT, GET_VIDEO = range(10904, 10908)
post_config = PostConfig()
class Post(Plugin.Conversation):
"""文章推送"""
MENU_KEYBOARD = ReplyKeyboardMarkup([["推送频道", "添加TAG"], ["编辑文字", "删除图片"], ["退出"]], True, True)
MENU_KEYBOARD = ReplyKeyboardMarkup(
[["推送频道", "添加TAG"], ["编辑文字", "删除图片"], ["添加视频", "退出"]], True, True
)
def __init__(self):
self.gids = 8
@ -202,6 +203,10 @@ class Post(Plugin.Conversation):
def input_media(
media: "ArtworkImage", *args, **kwargs
) -> Union[None, InputMediaDocument, InputMediaPhoto, InputMediaVideo]:
if media.art_id == 114514:
doc = InputMediaVideo(media.file_name, *args, **kwargs)
doc._frozen = False
return doc
file_extension = media.file_extension
filename = media.file_name
doc = None
@ -405,6 +410,8 @@ class Post(Plugin.Conversation):
return await self.edit_text(update, context)
if message.text == "删除图片":
return await self.delete_photo(update, context)
if message.text == "添加视频":
return await self.add_video(update, context)
return ConversationHandler.END
@staticmethod
@ -512,6 +519,23 @@ class Post(Plugin.Conversation):
await message.reply_text("请选择你的操作", reply_markup=self.MENU_KEYBOARD)
return CHECK_COMMAND
@staticmethod
async def add_video(update: "Update", _: "ContextTypes.DEFAULT_TYPE") -> int:
message = update.effective_message
await message.reply_text("请回复添加的视频")
return GET_VIDEO
@conversation.state(state=GET_VIDEO)
@handler.message(filters=filters.VIDEO & ~filters.COMMAND, block=False)
async def get_add_video(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> int:
post_handler_data: PostHandlerData = context.chat_data.get("post_handler_data")
message = update.effective_message
video = message.video
post_handler_data.post_images.insert(0, ArtworkImage(art_id=114514, file_name=video.file_id))
await message.reply_text("插入视频成功")
await message.reply_text("请选择你的操作", reply_markup=self.MENU_KEYBOARD)
return CHECK_COMMAND
@conversation.state(state=SEND_POST)
@handler.message(filters=filters.TEXT & ~filters.COMMAND, block=False)
async def send_post(self, update: "Update", context: "ContextTypes.DEFAULT_TYPE") -> int: