mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-24 00:31:30 +00:00
feat: dc inline query
This commit is contained in:
parent
7f0e16c7f2
commit
7f411871d1
@ -327,7 +327,9 @@ async def go_download(v: Video, p_num: int, m: Message, task: bool = True):
|
|||||||
# FLV 流下载
|
# FLV 流下载
|
||||||
await download_url(streams[0].url, flv_temp_path, m, "视频 FLV ")
|
await download_url(streams[0].url, flv_temp_path, m, "视频 FLV ")
|
||||||
# 转换文件格式
|
# 转换文件格式
|
||||||
_, result = await execute(f'{FFMPEG_PATH} -i "{flv_temp_path}" "{video_path}"')
|
_, result = await execute(
|
||||||
|
f'{FFMPEG_PATH} -i "{flv_temp_path}" "{video_path}"'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if len(streams) < 2:
|
if len(streams) < 2:
|
||||||
raise BilibiliDownloaderError("获取下载链接异常")
|
raise BilibiliDownloaderError("获取下载链接异常")
|
||||||
|
@ -2,9 +2,7 @@ from init import request
|
|||||||
|
|
||||||
|
|
||||||
class Exchange:
|
class Exchange:
|
||||||
API = (
|
API = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/"
|
||||||
"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/"
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.inited = False
|
self.inited = False
|
||||||
|
@ -20,7 +20,9 @@ async def get_splash() -> List[SplashApi]:
|
|||||||
headers = {
|
headers = {
|
||||||
"cookie": mys_cookie,
|
"cookie": mys_cookie,
|
||||||
}
|
}
|
||||||
data = await request.get("https://bbs-api.miyoushe.com/apihub/api/getAppSplash", headers=headers)
|
data = await request.get(
|
||||||
|
"https://bbs-api.miyoushe.com/apihub/api/getAppSplash", headers=headers
|
||||||
|
)
|
||||||
splash_list = []
|
splash_list = []
|
||||||
if data.is_success:
|
if data.is_success:
|
||||||
data = data.json()
|
data = data.json()
|
||||||
|
@ -78,7 +78,12 @@ async def converter(src_file: Union[Path, str]) -> Path:
|
|||||||
if process.returncode == 0:
|
if process.returncode == 0:
|
||||||
src_file.unlink(missing_ok=True)
|
src_file.unlink(missing_ok=True)
|
||||||
else:
|
else:
|
||||||
logs.error("转换 %s -> %s 时出错: %s", src_file.name, target_file.name, stderr.decode("utf-8"))
|
logs.error(
|
||||||
|
"转换 %s -> %s 时出错: %s",
|
||||||
|
src_file.name,
|
||||||
|
target_file.name,
|
||||||
|
stderr.decode("utf-8"),
|
||||||
|
)
|
||||||
raise ValueError("转换 %s -> %s 时出错" % (src_file.name, target_file.name))
|
raise ValueError("转换 %s -> %s 时出错" % (src_file.name, target_file.name))
|
||||||
return target_file
|
return target_file
|
||||||
|
|
||||||
@ -113,7 +118,7 @@ def get_ext_from_mime(mime: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def zip_dir(dir_path: str, zip_filepath: Path):
|
def zip_dir(dir_path: str, zip_filepath: Path):
|
||||||
zipf = zipfile.ZipFile(zip_filepath, 'w', zipfile.ZIP_DEFLATED)
|
zipf = zipfile.ZipFile(zip_filepath, "w", zipfile.ZIP_DEFLATED)
|
||||||
for root, dirs, files in os.walk(dir_path):
|
for root, dirs, files in os.walk(dir_path):
|
||||||
for file in files:
|
for file in files:
|
||||||
file_path = Path(root).joinpath(file)
|
file_path = Path(root).joinpath(file)
|
||||||
@ -126,7 +131,10 @@ async def run_zip_dir(dir_path: str, zip_filepath: Path):
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
await loop.run_in_executor(
|
await loop.run_in_executor(
|
||||||
executor, zip_dir, dir_path, zip_filepath,
|
executor,
|
||||||
|
zip_dir,
|
||||||
|
dir_path,
|
||||||
|
zip_filepath,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +143,9 @@ async def edit_message(reply: "Message", text: str) -> "Message":
|
|||||||
return await reply.edit(text)
|
return await reply.edit(text)
|
||||||
|
|
||||||
|
|
||||||
async def get_from_sticker_set(short_name: str, uid: int, client: "Client", reply: "Message") -> Path:
|
async def get_from_sticker_set(
|
||||||
|
short_name: str, uid: int, client: "Client", reply: "Message"
|
||||||
|
) -> Path:
|
||||||
s = InputStickerSetShortName(short_name=short_name)
|
s = InputStickerSetShortName(short_name=short_name)
|
||||||
packs: "StickerSet" = await client.invoke(GetStickerSet(stickerset=s, hash=0))
|
packs: "StickerSet" = await client.invoke(GetStickerSet(stickerset=s, hash=0))
|
||||||
tempdir = tempfile.mkdtemp()
|
tempdir = tempfile.mkdtemp()
|
||||||
|
2
init.py
2
init.py
@ -22,7 +22,7 @@ root_logger = getLogger()
|
|||||||
root_logger.setLevel(ERROR)
|
root_logger.setLevel(ERROR)
|
||||||
root_logger.addHandler(logging_handler)
|
root_logger.addHandler(logging_handler)
|
||||||
# pyro_logger = getLogger()
|
# pyro_logger = getLogger()
|
||||||
# pyro_logger.setLevel(INFO)
|
# pyro_logger.setLevel(logging.DEBUG)
|
||||||
# pyro_logger.addHandler(logging_handler)
|
# pyro_logger.addHandler(logging_handler)
|
||||||
basicConfig(level=INFO)
|
basicConfig(level=INFO)
|
||||||
logs.setLevel(INFO)
|
logs.setLevel(INFO)
|
||||||
|
@ -10,10 +10,18 @@ async def temp_fix(
|
|||||||
is_scheduled: bool = False,
|
is_scheduled: bool = False,
|
||||||
replies: int = 1,
|
replies: int = 1,
|
||||||
business_connection_id: str = None,
|
business_connection_id: str = None,
|
||||||
reply_to_message: "raw.base.Message" = None
|
reply_to_message: "raw.base.Message" = None,
|
||||||
):
|
):
|
||||||
parsed = await pyrogram.types.Message.old_parse(
|
parsed = await pyrogram.types.Message.old_parse(
|
||||||
client, message, users, chats, topics, is_scheduled, replies, business_connection_id, reply_to_message
|
client,
|
||||||
|
message,
|
||||||
|
users,
|
||||||
|
chats,
|
||||||
|
topics,
|
||||||
|
is_scheduled,
|
||||||
|
replies,
|
||||||
|
business_connection_id,
|
||||||
|
reply_to_message,
|
||||||
) # noqa
|
) # noqa
|
||||||
if (
|
if (
|
||||||
isinstance(message, pyrogram.raw.types.Message)
|
isinstance(message, pyrogram.raw.types.Message)
|
||||||
|
@ -1,8 +1,27 @@
|
|||||||
from pyrogram import Client, filters
|
from pyrogram import Client, filters
|
||||||
from pyrogram.types import Message, Chat
|
from pyrogram.types import (
|
||||||
|
Message,
|
||||||
|
Chat,
|
||||||
|
InlineQuery,
|
||||||
|
InlineQueryResultArticle,
|
||||||
|
InputTextMessageContent,
|
||||||
|
InlineKeyboardMarkup,
|
||||||
|
InlineKeyboardButton,
|
||||||
|
ChosenInlineResult,
|
||||||
|
CallbackQuery,
|
||||||
|
)
|
||||||
|
from pyrogram.utils import unpack_inline_message_id
|
||||||
|
|
||||||
from init import bot
|
from init import bot
|
||||||
|
|
||||||
|
geo_dic = {
|
||||||
|
"1": "美国-佛罗里达州-迈阿密",
|
||||||
|
"2": "荷兰-阿姆斯特丹",
|
||||||
|
"3": "美国-佛罗里达州-迈阿密",
|
||||||
|
"4": "荷兰-阿姆斯特丹",
|
||||||
|
"5": "新加坡",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def mention_chat(chat: Chat) -> str:
|
def mention_chat(chat: Chat) -> str:
|
||||||
return (
|
return (
|
||||||
@ -33,16 +52,59 @@ def get_dc(message: Message):
|
|||||||
|
|
||||||
@bot.on_message(filters.incoming & filters.command(["dc", f"dc@{bot.me.username}"]))
|
@bot.on_message(filters.incoming & filters.command(["dc", f"dc@{bot.me.username}"]))
|
||||||
async def dc_command(_: Client, message: Message):
|
async def dc_command(_: Client, message: Message):
|
||||||
geo_dic = {
|
|
||||||
"1": "美国-佛罗里达州-迈阿密",
|
|
||||||
"2": "荷兰-阿姆斯特丹",
|
|
||||||
"3": "美国-佛罗里达州-迈阿密",
|
|
||||||
"4": "荷兰-阿姆斯特丹",
|
|
||||||
"5": "新加坡",
|
|
||||||
}
|
|
||||||
dc, mention = get_dc(message)
|
dc, mention = get_dc(message)
|
||||||
if dc:
|
if dc:
|
||||||
text = f"{mention}所在数据中心为: <b>DC{dc}</b>\n该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
|
text = f"{mention}所在数据中心为: <b>DC{dc}</b>\n该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
|
||||||
else:
|
else:
|
||||||
text = f"{mention}需要先<b>设置头像并且对我可见。</b>"
|
text = f"{mention}需要先<b>设置头像并且对我可见。</b>"
|
||||||
await message.reply(text)
|
await message.reply(text)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on_inline_query(filters.regex(r"^dc$"))
|
||||||
|
async def dc_query(_: Client, inline_query: InlineQuery):
|
||||||
|
results = [
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
title="查询 dc",
|
||||||
|
input_message_content=InputTextMessageContent(message_text="加载中,请等待。。。"),
|
||||||
|
reply_markup=InlineKeyboardMarkup(
|
||||||
|
[[InlineKeyboardButton(text="重试", callback_data="dc")]]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
await inline_query.answer(
|
||||||
|
results=results,
|
||||||
|
switch_pm_text="发送后查询",
|
||||||
|
switch_pm_parameter="start",
|
||||||
|
cache_time=0,
|
||||||
|
)
|
||||||
|
inline_query.stop_propagation()
|
||||||
|
|
||||||
|
|
||||||
|
def get_dc_text(dc: int):
|
||||||
|
return f"此会话所在数据中心为: <b>DC{dc}</b>\n" f"该数据中心位于 <b>{geo_dic[str(dc)]}</b>"
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on_chosen_inline_result()
|
||||||
|
async def dc_choose_callback(_: Client, chosen_inline_result: ChosenInlineResult):
|
||||||
|
if chosen_inline_result.query != "dc":
|
||||||
|
chosen_inline_result.continue_propagation()
|
||||||
|
mid = chosen_inline_result.inline_message_id
|
||||||
|
if not mid:
|
||||||
|
return
|
||||||
|
unpacked = unpack_inline_message_id(mid)
|
||||||
|
dc = unpacked.dc_id
|
||||||
|
await bot.edit_inline_text(mid, get_dc_text(dc))
|
||||||
|
|
||||||
|
|
||||||
|
@bot.on_callback_query(filters.regex(r"^dc$"))
|
||||||
|
async def dc_callback(_: Client, callback_query: CallbackQuery):
|
||||||
|
mid = callback_query.inline_message_id
|
||||||
|
if not mid:
|
||||||
|
await callback_query.answer("数据错误", show_alert=True)
|
||||||
|
callback_query.continue_propagation()
|
||||||
|
unpacked = unpack_inline_message_id(mid)
|
||||||
|
dc = unpacked.dc_id
|
||||||
|
try:
|
||||||
|
await callback_query.edit_message_text(get_dc_text(dc))
|
||||||
|
except Exception:
|
||||||
|
await callback_query.answer("数据错误", show_alert=True)
|
||||||
|
@ -22,7 +22,7 @@ async def send_donate(_, message: Message):
|
|||||||
description="Support me",
|
description="Support me",
|
||||||
currency="XTR",
|
currency="XTR",
|
||||||
prices=[LabeledPrice(label="Star", amount=amount)],
|
prices=[LabeledPrice(label="Star", amount=amount)],
|
||||||
payload="stars"
|
payload="stars",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ async def empty_inline(_, inline_query: InlineQuery):
|
|||||||
input_message_content=InputTextMessageContent("使用 m 来查询米游社启动图"),
|
input_message_content=InputTextMessageContent("使用 m 来查询米游社启动图"),
|
||||||
description="使用 m 来查询米游社启动图",
|
description="使用 m 来查询米游社启动图",
|
||||||
),
|
),
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
title="dc",
|
||||||
|
input_message_content=InputTextMessageContent("使用 dc 来查询会话数据中心"),
|
||||||
|
description="使用 dc 来查询会话数据中心",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
return await inline_query.answer(
|
return await inline_query.answer(
|
||||||
results=results,
|
results=results,
|
||||||
|
@ -7,8 +7,14 @@ from pyrogram import filters, ContinuePropagation
|
|||||||
from pyrogram.enums import ChatAction, MessageEntityType
|
from pyrogram.enums import ChatAction, MessageEntityType
|
||||||
from pyrogram.errors import StickersetInvalid
|
from pyrogram.errors import StickersetInvalid
|
||||||
|
|
||||||
from defs.sticker_download import get_from_sticker_set, get_from_sticker, custom_emoji_filter, \
|
from defs.sticker_download import (
|
||||||
get_from_custom_emoji, export_end, export_add
|
get_from_sticker_set,
|
||||||
|
get_from_sticker,
|
||||||
|
custom_emoji_filter,
|
||||||
|
get_from_custom_emoji,
|
||||||
|
export_end,
|
||||||
|
export_add,
|
||||||
|
)
|
||||||
from init import bot
|
from init import bot
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -17,7 +23,10 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
@bot.on_message(
|
@bot.on_message(
|
||||||
filters.private & filters.text & filters.incoming & filters.regex(r"^https://t.me/addstickers/.*")
|
filters.private
|
||||||
|
& filters.text
|
||||||
|
& filters.incoming
|
||||||
|
& filters.regex(r"^https://t.me/addstickers/.*")
|
||||||
)
|
)
|
||||||
async def process_sticker_set(client: "Client", message: "Message"):
|
async def process_sticker_set(client: "Client", message: "Message"):
|
||||||
cid = message.from_user.id
|
cid = message.from_user.id
|
||||||
@ -69,7 +78,11 @@ async def process_single_sticker(client: "Client", message: "Message"):
|
|||||||
async def process_custom_emoji(client: "Client", message: "Message"):
|
async def process_custom_emoji(client: "Client", message: "Message"):
|
||||||
try:
|
try:
|
||||||
stickers = await client.get_custom_emoji_stickers(
|
stickers = await client.get_custom_emoji_stickers(
|
||||||
[i.custom_emoji_id for i in message.entities if i and i.type == MessageEntityType.CUSTOM_EMOJI]
|
[
|
||||||
|
i.custom_emoji_id
|
||||||
|
for i in message.entities
|
||||||
|
if i and i.type == MessageEntityType.CUSTOM_EMOJI
|
||||||
|
]
|
||||||
)
|
)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
await message.reply("无法获取贴纸", quote=True)
|
await message.reply("无法获取贴纸", quote=True)
|
||||||
@ -96,15 +109,17 @@ async def process_custom_emoji(client: "Client", message: "Message"):
|
|||||||
|
|
||||||
|
|
||||||
@bot.on_message(
|
@bot.on_message(
|
||||||
filters.private & filters.incoming & filters.command(
|
filters.private
|
||||||
["sticker_export_start", "sticker_export_end"]
|
& filters.incoming
|
||||||
)
|
& filters.command(["sticker_export_start", "sticker_export_end"])
|
||||||
)
|
)
|
||||||
async def batch_start(_: "Client", message: "Message"):
|
async def batch_start(_: "Client", message: "Message"):
|
||||||
uid = message.from_user.id
|
uid = message.from_user.id
|
||||||
if "start" in message.command[0].lower():
|
if "start" in message.command[0].lower():
|
||||||
if await cache.get(f"sticker:export:{uid}"):
|
if await cache.get(f"sticker:export:{uid}"):
|
||||||
await message.reply("已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True)
|
await message.reply(
|
||||||
|
"已经开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True
|
||||||
|
)
|
||||||
return
|
return
|
||||||
await cache.set(f"sticker:export:{uid}", tempfile.mkdtemp())
|
await cache.set(f"sticker:export:{uid}", tempfile.mkdtemp())
|
||||||
await message.reply("开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True)
|
await message.reply("开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user