all Update to v1.4.8

This commit is contained in:
xtaodada 2024-02-04 15:56:06 +08:00
parent 0d7b581d91
commit cdca0354ae
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
31 changed files with 258 additions and 226 deletions

View File

@ -43,9 +43,9 @@ async def get_hitokoto(request: AsyncClient):
try:
htk = (await request.get("https://v1.hitokoto.cn/?charset=utf-8")).json()
text = f"\"{htk['hitokoto']}\" —— "
if htk['from_who']:
if htk["from_who"]:
text += f"{htk['from_who']}"
if htk['from']:
if htk["from"]:
text += f"{htk['from']}"
except Exception:
text = '"用代码表达言语的魅力,用代码书写山河的壮丽。" —— 一言「一言开发者中心」'

View File

@ -24,7 +24,7 @@ async def at_admins(client: Client, message: Message):
await client.send_message(
message.chat.id,
"%s\n\n%s" % (say, send_list),
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()

View File

@ -23,7 +23,8 @@ async def audio_to_voice(bot: Client, message: Message):
audio,
reply_to_message_id=message.id
if message.audio
else (message.reply_to_message_id or message.reply_to_top_message_id),
else message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
except Exception as e:
await message.edit(f"转换为语音消息失败:{e}")

View File

@ -40,14 +40,14 @@ async def bingwall(message: Message):
filename,
caption=f"#bing wallpaper\n" f"{str(copy_right)}",
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
else:
await message.reply_photo(
filename,
caption=f"#bing wallpaper\n" f"{str(copy_right)}",
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
status = True
break # 成功了就赶紧结束啦!

View File

@ -79,7 +79,7 @@ async def chat_transfer(message: Message):
"chats.csv",
caption=f"对话导出文件,成功导出了 {num} 个群组/频道",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
safe_remove("chats.csv")
await message.safe_delete()

View File

@ -487,7 +487,7 @@ async def eat(client_: Client, context: Message):
await client_.send_document(
context.chat.id,
f"plugins{sep}eat{sep}eat.webp",
reply_to_message_id=context.reply_to_top_message_id,
message_thread_id=context.message_thread_id,
)
await final_msg.safe_delete()
except TypeError:

View File

@ -115,7 +115,7 @@ async def emoji_transfer(message: Message):
"emojis.csv",
caption=f"Emoji 包导出文件,成功导出了 {num} 个 Emoji 包",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
safe_remove("emojis.csv")
await message.safe_delete()

View File

@ -120,13 +120,13 @@ async def epic(message: Message):
"epic.jpg",
caption=msg,
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
except Exception:
await message.reply(
msg,
quote=False,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
safe_remove("epic.jpg")
else:

View File

@ -85,8 +85,8 @@ async def upload_sticker(bot: Client, message: Message, sticker_set: StickerSet)
message.chat.id,
f"{directory_name}.zip",
caption=sticker_set.set.short_name,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
safe_remove(f"{directory_name}.zip")
shutil.rmtree(directory_name)

View File

@ -20,10 +20,9 @@ async def httpcat(client: Client, message: Message, request: AsyncClient):
await client.send_photo(
message.chat.id,
io,
reply_to_message_id=(
message.reply_to_message_id or message.reply_to_top_message_id
)
reply_to_message_id=message.reply_to_message_id
if message.outgoing
else message.id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()

View File

@ -133,7 +133,7 @@ async def jikipedia(message: Message):
image,
quote=False,
caption=text,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
except Exception:

View File

@ -17,8 +17,8 @@ async def ju_pai(message: Message):
await message.reply_photo(
image_url,
quote=False,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
except Exception as e:

View File

@ -161,10 +161,13 @@ class KeywordTask:
async def process_keyword(self, message: Message):
msg = None
text = self.replace_reply(message)
reply_id = message.id if self.reply else message.reply_to_top_message_id
reply_id = message.id if self.reply else None
with contextlib.suppress(Exception):
msg = await message.reply(
text, parse_mode=ParseMode.HTML, reply_to_message_id=reply_id
text,
parse_mode=ParseMode.HTML,
reply_to_message_id=reply_id,
message_thread_id=message.message_thread_id,
)
if self.delete:
if self.source_delay_delete > 0:
@ -236,10 +239,17 @@ class KeywordTask:
if len(data) > 4:
self.delay_delete = int(data[4])
if len(data) > 5: # assuming the source_delay_delete is the 6th part of the task format
if (
len(data) > 5
): # assuming the source_delay_delete is the 6th part of the task format
self.source_delay_delete = int(data[5])
if self.ban < 0 or self.restrict < 0 or self.delay_delete < 0 or self.source_delay_delete < 0:
if (
self.ban < 0
or self.restrict < 0
or self.delay_delete < 0
or self.source_delay_delete < 0
):
raise ValueError("Invalid task format")

View File

@ -43,8 +43,8 @@ async def netease_search(keyword: str, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
@ -57,8 +57,8 @@ async def netease_url(url: str, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
@ -71,8 +71,8 @@ async def netease_id(music_id: str, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()

View File

@ -51,8 +51,6 @@ async def set_read_mentions(client: Client, message: Message):
await client.invoke(
ReadMentions(
peer=await client.resolve_peer(message.chat.id),
top_msg_id=message.reply_to_top_message_id
if message.chat.is_forum
else None,
top_msg_id=message.message_thread_id if message.topic else None,
)
)

View File

@ -285,14 +285,14 @@ async def send_illust(message: Message, illust: Illust) -> None:
illust.image_urls["large"],
caption=caption,
quote=False,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
else:
await message.reply_text(
caption,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)

View File

@ -2104,7 +2104,11 @@ class MathChallenge(CaptchaChallenge):
}
if previous_msg_id:
params["message_id"] = previous_msg_id
challenge_msg = await exec_api((bot.edit_message_text if previous_msg_id else bot.send_message)(**params))
challenge_msg = await exec_api(
(bot.edit_message_text if previous_msg_id else bot.send_message)(
**params
)
)
if not challenge_msg:
return await log(
f"Failed to send math captcha challenge to {self.user.id}"
@ -2403,7 +2407,9 @@ class Rule:
try:
exec(f"async def _(msg, text, user, me, bot):\n return {custom_rule}")
return bool(
await locals()["_"](self.msg, self._get_text(), self.user, bot.me, bot)
await locals()["_"](
self.msg, self._get_text(), self.user, bot.me, bot
)
)
except Exception as e:
await log(

View File

@ -35,8 +35,8 @@ async def qq_music(message: Message, client: AsyncClient):
uri,
thumb=cover or None,
caption=f"{text}",
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await msg.safe_delete()
except Exception as e:

View File

@ -34,8 +34,8 @@ async def gen_qr(client: Client, message: Message):
await client.send_document(
message.chat.id,
document="qr.webp",
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
except UnicodeEncodeError:
await message.edit(f"{lang('error_prefix')}{lang('genqr_e_encode')}")

View File

@ -4,7 +4,11 @@ from typing import Dict, List
from pyrogram import filters
from pyrogram.errors import ChatAdminRequired, UserAdminInvalid, FloodWait
from pyrogram.raw.functions.channels import GetAdminLog, GetMessages
from pyrogram.raw.types import ChannelAdminLogEventsFilter, ChannelAdminLogEventActionUpdatePinned, InputMessageID
from pyrogram.raw.types import (
ChannelAdminLogEventsFilter,
ChannelAdminLogEventActionUpdatePinned,
InputMessageID,
)
from pyrogram.raw.types.channels import AdminLogResults
from pyrogram.raw.types.messages import Messages
@ -49,7 +53,7 @@ async def try_ask_admin(message: Message, num_map: Dict[int, List[int]]) -> int:
async with bot.conversation(
message.chat.id, filters=filters.user(message.from_user.id)
) as conv:
await sleep(.1)
await sleep(0.1)
res: Message = await conv.get_response()
await res.safe_delete()
uid = int(res.text)
@ -76,7 +80,9 @@ async def pin_one(message: Message, mid: int):
async def get_unpin_messages(cid: int, ids: List[int]) -> List[int]:
ids = [InputMessageID(id=i) for i in ids]
r: Messages = await bot.invoke(GetMessages(channel=await bot.resolve_peer(cid), id=ids))
r: Messages = await bot.invoke(
GetMessages(channel=await bot.resolve_peer(cid), id=ids)
)
new_ids = []
for i in r.messages:
if not i.pinned:

View File

@ -27,7 +27,10 @@ def try_cast_or_fallback(val: Any, t: type) -> Any:
def check_chat_available(chat: Chat):
assert (chat.type in [ChatType.CHANNEL, ChatType.GROUP] and not chat.has_protected_content)
assert (
chat.type in [ChatType.CHANNEL, ChatType.GROUP]
and not chat.has_protected_content
)
@listener(
@ -137,13 +140,21 @@ async def shift_set(client: Client, message: Message):
await message.edit(f"备份频道 {source.id}{target.id} 已完成。")
# 列出要轉存的頻道
elif message.parameter[0] == "list":
from_ids = list(filter(lambda x: (x.startswith("shift.") and (not x.endswith("options"))), list(sqlite.keys())))
from_ids = list(
filter(
lambda x: (x.startswith("shift.") and (not x.endswith("options"))),
list(sqlite.keys()),
)
)
if not from_ids:
return await message.edit("沒有要轉存的頻道")
output = "總共有 %d 個頻道要轉存\n\n" % len(from_ids)
for from_id in from_ids:
to_id = sqlite[from_id]
output += "%s -> %s\n" % (format_channel_id(from_id[6:]), format_channel_id(to_id))
output += "%s -> %s\n" % (
format_channel_id(from_id[6:]),
format_channel_id(to_id),
)
await message.edit(output)
else:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")

View File

@ -118,8 +118,7 @@ async def speedtest(client: Client, message: Message, request: AsyncClient):
message.chat.id,
photo,
caption=des,
reply_to_message_id=message.reply_to_top_message_id
or message.reply_to_message_id,
message_thread_id=message.message_thread_id or message.reply_to_message_id,
)
except Exception:
return await msg.edit(des)

View File

@ -118,7 +118,7 @@ async def sticker_transfer(message: Message):
"stickers.csv",
caption=f"贴纸包导出文件,成功导出了 {num} 个贴纸包",
thumb=f"pagermaid{sep}assets{sep}logo.jpg",
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
safe_remove("stickers.csv")
await message.safe_delete()

View File

@ -29,7 +29,7 @@ async def tg_bg(client: Client, message: Message):
message.chat.id,
bg_doc.file_id,
file_name="bg.jpg",
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
return await message.safe_delete()
await message.edit("获取失败,请检查 URL")

View File

@ -49,8 +49,8 @@ async def weather_pic(client: Client, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
@ -67,8 +67,8 @@ async def weather_he(client: Client, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
@ -82,8 +82,8 @@ async def az_tts(client: Client, message: Message, mode: str):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
@ -143,7 +143,7 @@ async def draw_photo(client: Client, message: Message):
await conv.mark_as_read()
await answer.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()

View File

@ -17,8 +17,8 @@ async def weather_lite(request: AsyncClient, message: Message):
f.write(data.content)
await message.reply_photo(
"weather.png",
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
quote=False,
)
await message.safe_delete()

View File

@ -18,8 +18,8 @@ async def xjj(message: Message, client: AsyncClient):
await message.reply_video(
url,
quote=False,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
await message.safe_delete()
except Exception as e:

View File

@ -77,7 +77,7 @@ async def start_download(message: Message, url: str):
cid,
video=file,
supports_streaming=True,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
except Exception:
try:
@ -85,7 +85,7 @@ async def start_download(message: Message, url: str):
cid,
document=file,
force_document=True,
reply_to_message_id=message.reply_to_top_message_id,
message_thread_id=message.message_thread_id,
)
except Exception as e:
result["status"] = False

View File

@ -30,16 +30,16 @@ async def yv_lu(bot: Client, message: Message):
try:
await chat_response.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
except Flood as e:
await sleep(e.value + 1)
with contextlib.suppress(Exception):
await chat_response.copy(
message.chat.id,
reply_to_message_id=message.reply_to_message_id
or message.reply_to_top_message_id,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
except Exception:
pass

View File

@ -55,7 +55,6 @@ async def get_result(message, request, r18=2):
@listener(command="zpr", description="随机获取一组涩涩纸片人。", parameters="{r18}")
async def zpr(client: Client, message: Message, request: AsyncClient):
arguments = message.arguments.upper().strip()
message_thread_id = message.reply_to_top_message_id or message.reply_to_message_id
message = await message.edit("正在前往二次元。。。")
try:
photoList, des = await get_result(
@ -68,7 +67,10 @@ async def zpr(client: Client, message: Message, request: AsyncClient):
await message.edit("传送中。。。")
try:
await client.send_media_group(
message.chat.id, photoList, reply_to_message_id=message_thread_id
message.chat.id,
photoList,
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
)
except RPCError as e:
return await message.edit(