diff --git a/defs/bilibili_download.py b/defs/bilibili_download.py
index 0fd649e..594e48d 100644
--- a/defs/bilibili_download.py
+++ b/defs/bilibili_download.py
@@ -327,7 +327,9 @@ async def go_download(v: Video, p_num: int, m: Message, task: bool = True):
# 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:
if len(streams) < 2:
raise BilibiliDownloaderError("获取下载链接异常")
diff --git a/defs/exchange.py b/defs/exchange.py
index 94d80b1..5245c43 100644
--- a/defs/exchange.py
+++ b/defs/exchange.py
@@ -2,9 +2,7 @@ from init import request
class Exchange:
- API = (
- "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/"
- )
+ API = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/"
def __init__(self):
self.inited = False
diff --git a/defs/splash.py b/defs/splash.py
index 257ed93..2c0696e 100644
--- a/defs/splash.py
+++ b/defs/splash.py
@@ -20,7 +20,9 @@ async def get_splash() -> List[SplashApi]:
headers = {
"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 = []
if data.is_success:
data = data.json()
diff --git a/defs/sticker_download.py b/defs/sticker_download.py
index eb8cb35..4f5782a 100644
--- a/defs/sticker_download.py
+++ b/defs/sticker_download.py
@@ -78,7 +78,12 @@ async def converter(src_file: Union[Path, str]) -> Path:
if process.returncode == 0:
src_file.unlink(missing_ok=True)
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))
return target_file
@@ -113,7 +118,7 @@ def get_ext_from_mime(mime: str) -> str:
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 file in files:
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()
with ThreadPoolExecutor() as 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)
-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)
packs: "StickerSet" = await client.invoke(GetStickerSet(stickerset=s, hash=0))
tempdir = tempfile.mkdtemp()
diff --git a/init.py b/init.py
index 72a4db7..caa9a43 100644
--- a/init.py
+++ b/init.py
@@ -22,7 +22,7 @@ root_logger = getLogger()
root_logger.setLevel(ERROR)
root_logger.addHandler(logging_handler)
# pyro_logger = getLogger()
-# pyro_logger.setLevel(INFO)
+# pyro_logger.setLevel(logging.DEBUG)
# pyro_logger.addHandler(logging_handler)
basicConfig(level=INFO)
logs.setLevel(INFO)
diff --git a/models/temp_fix.py b/models/temp_fix.py
index a441cdc..99b3ad8 100644
--- a/models/temp_fix.py
+++ b/models/temp_fix.py
@@ -10,10 +10,18 @@ async def temp_fix(
is_scheduled: bool = False,
replies: int = 1,
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(
- 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
if (
isinstance(message, pyrogram.raw.types.Message)
diff --git a/modules/dc.py b/modules/dc.py
index a077bfe..f5c9986 100644
--- a/modules/dc.py
+++ b/modules/dc.py
@@ -1,8 +1,27 @@
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
+geo_dic = {
+ "1": "美国-佛罗里达州-迈阿密",
+ "2": "荷兰-阿姆斯特丹",
+ "3": "美国-佛罗里达州-迈阿密",
+ "4": "荷兰-阿姆斯特丹",
+ "5": "新加坡",
+}
+
def mention_chat(chat: Chat) -> str:
return (
@@ -33,16 +52,59 @@ def get_dc(message: Message):
@bot.on_message(filters.incoming & filters.command(["dc", f"dc@{bot.me.username}"]))
async def dc_command(_: Client, message: Message):
- geo_dic = {
- "1": "美国-佛罗里达州-迈阿密",
- "2": "荷兰-阿姆斯特丹",
- "3": "美国-佛罗里达州-迈阿密",
- "4": "荷兰-阿姆斯特丹",
- "5": "新加坡",
- }
dc, mention = get_dc(message)
if dc:
text = f"{mention}所在数据中心为: DC{dc}\n该数据中心位于 {geo_dic[str(dc)]}"
else:
text = f"{mention}需要先设置头像并且对我可见。"
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"此会话所在数据中心为: DC{dc}\n" f"该数据中心位于 {geo_dic[str(dc)]}"
+
+
+@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)
diff --git a/modules/donate.py b/modules/donate.py
index 33d2e8e..7ca7dbf 100644
--- a/modules/donate.py
+++ b/modules/donate.py
@@ -22,7 +22,7 @@ async def send_donate(_, message: Message):
description="Support me",
currency="XTR",
prices=[LabeledPrice(label="Star", amount=amount)],
- payload="stars"
+ payload="stars",
)
diff --git a/modules/start.py b/modules/start.py
index 4126ea4..3676ba9 100644
--- a/modules/start.py
+++ b/modules/start.py
@@ -59,6 +59,11 @@ async def empty_inline(_, inline_query: InlineQuery):
input_message_content=InputTextMessageContent("使用 m 来查询米游社启动图"),
description="使用 m 来查询米游社启动图",
),
+ InlineQueryResultArticle(
+ title="dc",
+ input_message_content=InputTextMessageContent("使用 dc 来查询会话数据中心"),
+ description="使用 dc 来查询会话数据中心",
+ ),
]
return await inline_query.answer(
results=results,
diff --git a/modules/sticker_download.py b/modules/sticker_download.py
index d82fd25..b4505ab 100644
--- a/modules/sticker_download.py
+++ b/modules/sticker_download.py
@@ -7,8 +7,14 @@ from pyrogram import filters, ContinuePropagation
from pyrogram.enums import ChatAction, MessageEntityType
from pyrogram.errors import StickersetInvalid
-from defs.sticker_download import get_from_sticker_set, get_from_sticker, custom_emoji_filter, \
- get_from_custom_emoji, export_end, export_add
+from defs.sticker_download import (
+ get_from_sticker_set,
+ get_from_sticker,
+ custom_emoji_filter,
+ get_from_custom_emoji,
+ export_end,
+ export_add,
+)
from init import bot
if TYPE_CHECKING:
@@ -17,7 +23,10 @@ if TYPE_CHECKING:
@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"):
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"):
try:
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:
await message.reply("无法获取贴纸", quote=True)
@@ -96,15 +109,17 @@ async def process_custom_emoji(client: "Client", message: "Message"):
@bot.on_message(
- filters.private & filters.incoming & filters.command(
- ["sticker_export_start", "sticker_export_end"]
- )
+ filters.private
+ & filters.incoming
+ & filters.command(["sticker_export_start", "sticker_export_end"])
)
async def batch_start(_: "Client", message: "Message"):
uid = message.from_user.id
if "start" in message.command[0].lower():
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
await cache.set(f"sticker:export:{uid}", tempfile.mkdtemp())
await message.reply("开始批量导出贴纸,请直接发送贴纸,完成选择请输入 /sticker_export_end", quote=True)