all fix a bug

This commit is contained in:
xtaodada 2022-09-01 16:28:48 +08:00
parent a4ee0c703b
commit 5f8a442312
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
10 changed files with 69 additions and 70 deletions

View File

@ -1,22 +1,22 @@
from pyrogram.enums import ChatMembersFilter
from pagermaid.listener import listener
from pagermaid.single_utils import Message
from pagermaid.enums import Client, Message
@listener(command="atadmins",
description="一键 AT 本群管理员(仅在群组中有效)",
groups_only=True,
parameters="<要说的话>")
async def at_admins(message: Message):
async def at_admins(client: Client, message: Message):
admins = []
async for m in message.bot.get_chat_members(message.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
async for m in client.get_chat_members(message.chat.id, filter=ChatMembersFilter.ADMINISTRATORS):
if not m.user.is_bot and not m.user.is_deleted:
admins.append(m.user.mention)
if not admins:
return await message.edit("❌ 没有管理员")
say = message.arguments or "召唤本群所有管理员"
send_list = ' , '.join(admins)
await message.bot.send_message(message.chat.id, "%s\n\n%s" % (say, send_list),
reply_to_message_id=message.reply_to_message_id)
await client.send_message(message.chat.id, "%s\n\n%s" % (say, send_list),
reply_to_message_id=message.reply_to_message_id)
await message.safe_delete()

View File

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
from pyrogram.errors import FloodWait, ChatAdminRequired, UserAdminInvalid
from pagermaid.listener import listener
from pagermaid.single_utils import Message
from pagermaid.enums import Client, Message
@listener(command="getdel",
@ -11,21 +11,21 @@ from pagermaid.single_utils import Message
need_admin=True,
parameters="清理",
description="获取当前群组的死号数。")
async def get_del(message: Message):
async def get_del(client: Client, message: Message):
""" PagerMaid get_del. """
need_kick = message.arguments
member_count = 0
try:
await message.edit('遍历成员中。。。')
if need_kick:
user = await message.bot.get_chat_member(message.chat.id, (await message.bot.get_me()).id)
user = await client.get_chat_member(message.chat.id, (await client.get_me()).id)
need_kick = bool(user.privileges and user.privileges.can_restrict_members)
async for member in message.bot.get_chat_members(message.chat.id):
async for member in client.get_chat_members(message.chat.id):
if member.user.is_deleted:
member_count += 1
if need_kick:
try:
await message.bot.ban_chat_member(
await client.ban_chat_member(
message.chat.id,
member.user.id,
datetime.now() + timedelta(minutes=5))

View File

@ -5,7 +5,7 @@ from pyrogram import filters
from pagermaid import bot
from pagermaid.listener import listener
from pagermaid.single_utils import Message
from pagermaid.enums import Message
from pagermaid.utils import alias_command
@ -26,7 +26,7 @@ async def netease_start() -> None:
async def netease_search(keyword: str, message: Message):
async with message.bot.conversation("Music163bot") as conv:
async with bot.conversation("Music163bot") as conv:
await conv.send_message(f"/search {keyword}")
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=~filters.regex("搜索中..."))
@ -44,7 +44,7 @@ async def netease_search(keyword: str, message: Message):
async def netease_url(url: str, message: Message):
async with message.bot.conversation("Music163bot") as conv:
async with bot.conversation("Music163bot") as conv:
await conv.send_message(url)
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=filters.audio)
@ -54,7 +54,7 @@ async def netease_url(url: str, message: Message):
async def netease_id(music_id: str, message: Message):
async with message.bot.conversation("Music163bot") as conv:
async with bot.conversation("Music163bot") as conv:
await conv.send_message(f"/music {music_id}")
await conv.mark_as_read()
answer: Message = await conv.get_response(filters=filters.audio)

View File

@ -5,14 +5,13 @@ from pyrogram.errors import UserAdminInvalid, BadRequest, ChatAdminRequired
from pyrogram.types import ChatPermissions
from pagermaid.listener import listener
from pagermaid.utils import Message
from pagermaid.enums import Client, Message
@listener(command="portball", is_plugin=True, outgoing=True, need_admin=True,
description="回复你要临时禁言的人的消息来实现XX秒的禁言",
parameters="[理由]|<时间/秒>")
async def portball(_, message: Message):
bot = message.bot
async def portball(bot: Client, message: Message):
if message.chat.type in (ChatType.GROUP, ChatType.SUPERGROUP):
reply_to_message = message.reply_to_message
if reply_to_message is not None:

View File

@ -5,7 +5,8 @@ from pyrogram.enums.chat_type import ChatType
from pyrogram.errors.exceptions.flood_420 import FloodWait
from pagermaid import log
from pagermaid.single_utils import sqlite, Message
from pagermaid.single_utils import sqlite
from pagermaid.enums import Client, Message
from pagermaid.utils import lang
from pagermaid.listener import listener
@ -17,7 +18,7 @@ import contextlib
parameters="set <from channel> <to channel> 自动转发频道新消息(可以使用频道用户名或者 id\n"
"del <from channel> 删除转发\n"
"backup <from channel> <to channel> 备份频道(可以使用频道用户名或者 id")
async def shift_set(message: Message):
async def shift_set(client: Client, message: Message):
if not 1 < len(message.parameter) < 4:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
@ -26,14 +27,14 @@ async def shift_set(message: Message):
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
# 检查来源频道
try:
channel = await message.bot.get_chat(int(message.parameter[1]))
channel = await client.get_chat(int(message.parameter[1]))
if channel.type != ChatType.CHANNEL:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
if channel.has_protected_content:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
except Exception:
try:
channel = await message.bot.get_chat(message.parameter[1])
channel = await client.get_chat(message.parameter[1])
if channel.type != ChatType.CHANNEL:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
if channel.has_protected_content:
@ -44,10 +45,10 @@ async def shift_set(message: Message):
return await message.edit('出错了呜呜呜 ~ 此对话位于白名单中。')
# 检查目标频道
try:
to = await message.bot.get_chat(int(message.parameter[2]))
to = await client.get_chat(int(message.parameter[2]))
except Exception:
try:
to = await message.bot.get_chat(message.parameter[2])
to = await client.get_chat(message.parameter[2])
except Exception:
return await message.edit("出错了呜呜呜 ~ 无法识别的目标对话。")
if to.id in [-1001441461877]:
@ -61,10 +62,10 @@ async def shift_set(message: Message):
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
# 检查来源频道
try:
channel = await message.bot.get_chat(int(message.parameter[1]))
channel = await client.get_chat(int(message.parameter[1]))
except Exception:
try:
channel = await message.bot.get_chat(message.parameter[1])
channel = await client.get_chat(message.parameter[1])
except Exception:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
try:
@ -78,14 +79,14 @@ async def shift_set(message: Message):
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
# 检查来源频道
try:
channel = await message.bot.get_chat(int(message.parameter[1]))
channel = await client.get_chat(int(message.parameter[1]))
if channel.type != ChatType.CHANNEL:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
if channel.has_protected_content:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
except Exception:
try:
channel = await message.bot.get_chat(message.parameter[1])
channel = await client.get_chat(message.parameter[1])
if channel.type != ChatType.CHANNEL:
return await message.edit("出错了呜呜呜 ~ 无法识别的来源对话。")
if channel.has_protected_content:
@ -96,17 +97,17 @@ async def shift_set(message: Message):
return await message.edit('出错了呜呜呜 ~ 此对话位于白名单中。')
# 检查目标频道
try:
to = await message.bot.get_chat(int(message.parameter[2]))
to = await client.get_chat(int(message.parameter[2]))
except Exception:
try:
to = await message.bot.get_chat(message.parameter[2])
to = await client.get_chat(message.parameter[2])
except Exception:
return await message.edit("出错了呜呜呜 ~ 无法识别的目标对话。")
if to.id in [-1001441461877]:
return await message.edit('出错了呜呜呜 ~ 此对话位于白名单中。')
# 开始遍历消息
await message.edit(f'开始备份频道 {channel.id}{to.id}')
async for msg in message.bot.search_messages(channel.id):
async for msg in client.search_messages(channel.id):
await sleep(uniform(0.5, 1.0))
await forward_msg(message, msg, to.id)
await message.edit(f'备份频道 {channel.id}{to.id} 已完成。')

View File

@ -1,13 +1,12 @@
import contextlib
from PIL import Image
from os.path import exists
from httpx import ReadTimeout
from pagermaid.listener import listener
from pagermaid.single_utils import Message, safe_remove
from pagermaid.single_utils import safe_remove
from pagermaid.enums import Client, Message
from pagermaid.utils import lang, pip_install
pip_install("speedtest-cli", alias="speedtest")
@ -88,7 +87,7 @@ async def get_all_ids():
@listener(command="speedtest",
description=lang('speedtest_des'),
parameters="(Server ID/测速点列表)")
async def speedtest(message: Message):
async def speedtest(client: Client, message: Message):
""" Tests internet speed using speedtest. """
if message.arguments == "测速点列表":
msg = message
@ -110,7 +109,7 @@ async def speedtest(message: Message):
if not photo:
return await msg.edit(des)
try:
await message.bot.send_photo(message.chat.id, photo, caption=des)
await client.send_photo(message.chat.id, photo, caption=des)
except Exception:
return await msg.edit(des)
await msg.safe_delete()

View File

@ -45,8 +45,8 @@ async def unblock_sticker_bot():
await bot.unblock_user("Stickers")
async def get_all_packs(message: Message):
async with message.bot.conversation(429000) as conv:
async def get_all_packs():
async with bot.conversation(429000) as conv:
await conv.ask("/start")
await conv.mark_as_read()
await conv.ask("/cancel")
@ -113,7 +113,7 @@ class Sticker:
raise CannotToStickerSetError()
async def add_sticker(self):
async with self.message.bot.conversation(429000) as conv:
async with bot.conversation(429000) as conv:
await conv.ask("/start")
await conv.mark_as_read()
await conv.ask("/cancel")
@ -133,7 +133,7 @@ class Sticker:
await self.generate_sticker_set()
if not self.sticker_set:
raise NoStickerSetNameError()
packs = await get_all_packs(self.message)
packs = await get_all_packs()
if self.sticker_set not in packs:
# TODO: add a way to add a new pack
raise NoStickerSetNameError()

View File

@ -5,23 +5,23 @@ from pyrogram.raw.types import InputWallPaperSlug, WallPaper
from pyrogram.types.messages_and_media.document import Document
from pagermaid.listener import listener
from pagermaid.single_utils import Message
from pagermaid.enums import Client, Message
@listener(command="tgbg", description="解析 Telegram 聊天窗口背景图",
parameters="t.me/bg/xxx")
async def tg_bg(message: Message):
async def tg_bg(client: Client, message: Message):
argument = message.obtain_message()
if url := urlparse(argument):
if path := url.path:
if url.hostname == "t.me" and path.startswith("/bg/"):
slug = path[4:]
try:
bg: WallPaper = await message.bot.invoke(GetWallPaper(wallpaper=InputWallPaperSlug(slug=slug)))
bg: WallPaper = await client.invoke(GetWallPaper(wallpaper=InputWallPaperSlug(slug=slug)))
except Exception as e:
return await message.edit(f"获取失败: {str(e)}")
if bg.document:
bg_doc = Document._parse(message.bot, document=bg.document, file_name="bg.jpg") # noqa
await message.bot.send_document(message.chat.id, bg_doc.file_id, file_name="bg.jpg")
bg_doc = Document._parse(client, document=bg.document, file_name="bg.jpg") # noqa
await client.send_document(message.chat.id, bg_doc.file_id, file_name="bg.jpg")
return await message.safe_delete()
await message.edit("获取失败,请检查 URL")

View File

@ -4,7 +4,7 @@ from pyrogram.types import Chat
from pagermaid import bot
from pagermaid.listener import listener
from pagermaid.single_utils import Message
from pagermaid.enums import Client, Message
from pagermaid.utils import lang
@ -44,7 +44,7 @@ async def get_uid(chat: Chat, message: Message):
need_admin=True,
groups_only=True,
parameters="<reply|id|username>")
async def unban(message: Message):
async def unban(client: Client, message: Message):
chat = message.chat
try:
uid, member = await get_uid(chat, message)
@ -60,7 +60,7 @@ async def unban(message: Message):
if not member:
member = await bot.get_chat_member(chat.id, uid)
if member.status in [ChatMemberStatus.RESTRICTED, ChatMemberStatus.BANNED]:
await message.bot.unban_chat_member(chat.id, uid)
await client.unban_chat_member(chat.id, uid)
else:
return await message.edit("此用户未被限制。")
except UserNotParticipant:

View File

@ -1,17 +1,17 @@
from pyrogram.enums import ParseMode
from pagermaid.listener import listener
from pagermaid.utils import Message
from pagermaid.enums import Client, Message
@listener(command="duckduckgo",
description="Duckduckgo 搜索",
parameters="<query>")
async def duckduckgo(message: Message):
async def duckduckgo(client: Client, message: Message):
text = message.arguments
if not text:
return await message.edit("请输入查询内容")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/duckduckgo {text}")
await conv.mark_as_read()
await message.edit(answer.text.html, parse_mode=ParseMode.HTML)
@ -20,11 +20,11 @@ async def duckduckgo(message: Message):
@listener(command="caiyun",
description="彩云翻译",
parameters="<query>")
async def caiyun_translate(message: Message):
async def caiyun_translate(client: Client, message: Message):
text = message.arguments
if not text:
return await message.edit("请输入查询内容")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/translate {text}")
await conv.mark_as_read()
await message.edit(answer.text)
@ -33,11 +33,11 @@ async def caiyun_translate(message: Message):
@listener(command="weather",
description="使用彩云天气 api 查询国内实时天气。",
parameters="<位置>")
async def weather(message: Message):
async def weather(client: Client, message: Message):
text = message.arguments
if not text:
return await message.edit("请输入正确的地址")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/weather_api {text}")
await conv.mark_as_read()
await message.edit(answer.text)
@ -46,11 +46,11 @@ async def weather(message: Message):
@listener(command="weather_pic",
description="使用彩云天气 api 查询国内实时天气,但是显示图片。",
parameters="<位置>")
async def weather_pic(message: Message):
async def weather_pic(client: Client, message: Message):
text = message.arguments
if not text:
return await message.edit("请输入正确的地址")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/weather {text}")
await conv.mark_as_read()
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
@ -60,22 +60,22 @@ async def weather_pic(message: Message):
@listener(command="weather_he",
description="使用和风天气 api 查询国内实时天气,但是显示图片。",
parameters="<位置>")
async def weather_he(message: Message):
async def weather_he(client: Client, message: Message):
text = message.arguments
if not text:
return await message.edit("请输入正确的地址")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/weather_he {text}")
await conv.mark_as_read()
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
await message.safe_delete()
async def az_tts(message: Message, mode: str):
async def az_tts(client: Client, message: Message, mode: str):
text = message.arguments
if not text:
return await message.edit("请输入需要 tts 的内容")
async with message.bot.conversation("PagerMaid_Modify_bot") as conv:
async with client.conversation("PagerMaid_Modify_bot") as conv:
answer: Message = await conv.ask(f"/tts {text} {mode}")
await conv.mark_as_read()
await answer.copy(message.chat.id, reply_to_message_id=message.reply_to_message_id)
@ -85,33 +85,33 @@ async def az_tts(message: Message, mode: str):
@listener(command="tts_nan",
description="通过 Azure 文本到语音 基于字符串生成 简体男声 语音消息。",
parameters="<字符串>")
async def az_tts_nan(message: Message):
await az_tts(message, "")
async def az_tts_nan(client: Client, message: Message):
await az_tts(client, message, "")
@listener(command="tts_nv",
description="通过 Azure 文本到语音 基于字符串生成 简体女声 语音消息。",
parameters="<字符串>")
async def az_tts_nv(message: Message):
await az_tts(message, "nv")
async def az_tts_nv(client: Client, message: Message):
await az_tts(client, message, "nv")
@listener(command="tts_tw",
description="通过 Azure 文本到语音 基于字符串生成 繁体男声 语音消息。",
parameters="<字符串>")
async def az_tts_tw(message: Message):
await az_tts(message, "tw")
async def az_tts_tw(client: Client, message: Message):
await az_tts(client, message, "tw")
@listener(command="tts_ne",
description="通过 Azure 文本到语音 基于字符串生成 简体新闻男声 语音消息。",
parameters="<字符串>")
async def az_tts_ne(message: Message):
await az_tts(message, "ne")
async def az_tts_ne(client: Client, message: Message):
await az_tts(client, message, "ne")
@listener(command="tts_en",
description="通过 Azure 文本到语音 基于字符串生成 英文男声 语音消息。",
parameters="<字符串>")
async def az_tts_en(message: Message):
await az_tts(message, "en")
async def az_tts_en(client: Client, message: Message):
await az_tts(client, message, "en")