🔖 Update to v1.2.9

This commit is contained in:
xtaodada 2022-09-01 16:35:19 +08:00
parent 5ab4f0a54c
commit d47f117be3
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
8 changed files with 48 additions and 51 deletions

View File

@ -13,7 +13,7 @@ from pagermaid.scheduler import scheduler
import pyromod.listen
from pyrogram import Client
pgm_version = "1.2.8"
pgm_version = "1.2.9"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()

View File

@ -119,9 +119,6 @@ def listener(**args):
def decorator(function):
async def handler(client: Client, message: Message):
message.bot = client
message.request = httpx_client
try:
try:
parameter = message.matches[0].group(2).split(" ")
@ -235,9 +232,6 @@ def raw_listener(filter_s):
def decorator(function):
async def handler(client, message):
message.bot = client
message.request = httpx_client
try:
if function.__code__.co_argcount == 1:
await function(message)

View File

@ -5,7 +5,8 @@ from pyrogram.types import User
from pagermaid import Config
from pagermaid.listener import listener
from pagermaid.utils import lang, Message
from pagermaid.enums import Message, Client
from pagermaid.utils import lang
import contextlib
@ -13,7 +14,7 @@ import contextlib
@listener(is_plugin=False, command="profile",
description=lang('profile_des'),
parameters="<username>")
async def profile(message: Message):
async def profile(client: Client, message: Message):
""" Queries profile of a user. """
if len(message.parameter) > 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
@ -30,7 +31,7 @@ async def profile(message: Message):
if user.isdigit():
user = int(user)
else:
user = await message.bot.get_me()
user = await client.get_me()
if message.entities is not None:
if message.entities[0].type == "text_mention":
user = message.entities[0].user
@ -40,7 +41,7 @@ async def profile(message: Message):
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
if not isinstance(user, User):
try:
user = await message.bot.get_users(user)
user = await client.get_users(user)
except PeerIdInvalid:
return await message.edit(f"{lang('error_prefix')}{lang('profile_e_nof')}")
except UsernameNotOccupied:
@ -67,10 +68,10 @@ async def profile(message: Message):
f"{lang('profile_restricted')}: {restricted} \n" \
f"{lang('profile_type')}: {user_type} \n" \
f"[{first_name}](tg://user?id={user.id})"
photo = await message.bot.download_media(user.photo.big_file_id)
photo = await client.download_media(user.photo.big_file_id)
reply_to = message.reply_to_message
try:
await message.bot.send_photo(
await client.send_photo(
message.chat.id,
photo,
caption=caption,
@ -86,7 +87,7 @@ async def profile(message: Message):
need_admin=True,
description=lang('block_des'),
parameters="(username/uid/reply)")
async def block_user(message: Message):
async def block_user(client: Client, message: Message):
""" Block a user. """
if len(message.parameter) > 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
@ -97,7 +98,7 @@ async def block_user(message: Message):
if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
with contextlib.suppress(Exception):
if await message.bot.block_user(user):
if await client.block_user(user):
return await message.edit(f"{lang('block_success')} `{user}`")
await message.edit(f"`{user}` {lang('block_exist')}")
@ -106,7 +107,7 @@ async def block_user(message: Message):
need_admin=True,
description=lang('unblock_des'),
parameters="<username/uid/reply>")
async def unblock_user(message: Message):
async def unblock_user(client: Client, message: Message):
""" Unblock a user. """
if len(message.parameter) > 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
@ -117,6 +118,6 @@ async def unblock_user(message: Message):
if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
with contextlib.suppress(Exception):
if await message.bot.unblock_user(user):
if await client.unblock_user(user):
return await message.edit(f"{lang('unblock_success')} `{user}`")
await message.edit(f"`{user}` {lang('unblock_exist')}")

View File

@ -2,19 +2,20 @@
from pagermaid import log
from pagermaid.single_utils import sqlite
from pagermaid.utils import lang, Message
from pagermaid.utils import lang
from pagermaid.enums import Client, Message
from pagermaid.listener import listener
@listener(is_plugin=False, outgoing=True, command="ghost",
description=lang('ghost_des'),
parameters="<true|false|status>")
async def ghost(message: Message):
async def ghost(client: Client, message: Message):
""" Toggles ghosting of a user. """
if len(message.parameter) != 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
myself = await message.bot.get_me()
myself = await client.get_me()
self_user_id = myself.id
if message.parameter[0] == "true":
if message.chat.id == self_user_id:
@ -45,12 +46,12 @@ async def ghost(message: Message):
need_admin=True,
description=lang('deny_des'),
parameters="<true|false|status>")
async def deny(message: Message):
async def deny(client: Client, message: Message):
""" Toggles denying of a user. """
if len(message.parameter) != 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
myself = await message.bot.get_me()
myself = await client.get_me()
self_user_id = myself.id
if message.parameter[0] == "true":
if message.chat.id == self_user_id:
@ -78,10 +79,10 @@ async def deny(message: Message):
@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)
async def set_read_acknowledgement(message: Message):
async def set_read_acknowledgement(client: Client, message: Message):
""" Event handler to infinitely read ghosted messages. """
if sqlite.get(f"ghosted.chat_id.{str(message.chat.id)}", None):
await message.bot.read_chat_history(message.chat.id)
await client.read_chat_history(message.chat.id)
@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)

View File

@ -13,7 +13,7 @@ import contextlib
@listener(is_plugin=False, outgoing=True, command="prune",
need_admin=True,
description=lang('prune_des'))
async def prune(message: Message):
async def prune(client: Client, message: Message):
""" Purge every single message after the message you replied to. """
if not message.reply_to_message:
await message.edit(lang('not_reply'))
@ -21,8 +21,9 @@ async def prune(message: Message):
input_chat = message.chat.id
messages = []
count = 0
async for msg in message.bot.get_chat_history(input_chat,
limit=message.id - message.reply_to_message.id + 1):
async for msg in client.get_chat_history(
input_chat,
limit=message.id - message.reply_to_message.id + 1):
if msg.id < message.reply_to_message.id:
break
messages.append(msg.id)
@ -30,13 +31,13 @@ async def prune(message: Message):
if msg.reply_to_message:
messages.append(msg.reply_to_message.id)
if len(messages) == 100:
await message.bot.delete_messages(input_chat, messages)
await client.delete_messages(input_chat, messages)
messages = []
if messages:
await message.bot.delete_messages(input_chat, messages)
await client.delete_messages(input_chat, messages)
await log(f"{lang('prune_hint1')} {str(count)} {lang('prune_hint2')}")
notification = await send_prune_notify(message, count, count)
notification = await send_prune_notify(client, message, count, count)
await sleep(1)
await notification.delete()
@ -67,7 +68,7 @@ async def self_prune(bot: Client, message: Message):
msgs.append(msg.id)
count_buffer += 1
if len(msgs) == 100:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
msgs = []
async for msg in bot.search_messages(message.chat.id, from_user="me", offset=offset):
if count_buffer == count:
@ -75,16 +76,16 @@ async def self_prune(bot: Client, message: Message):
msgs.append(msg.id)
count_buffer += 1
if len(msgs) == 100:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
msgs = []
if msgs:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
await log(
f"{lang('prune_hint1')}{lang('sp_hint')} {str(count_buffer)} / {count} {lang('prune_hint2')}"
)
with contextlib.suppress(ValueError):
notification = await send_prune_notify(message, count_buffer, count)
notification = await send_prune_notify(bot, message, count_buffer, count)
await sleep(1)
await notification.delete()
@ -119,7 +120,7 @@ async def your_prune(bot: Client, message: Message):
msgs.append(msg.id)
count_buffer += 1
if len(msgs) == 100:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
msgs = []
async for msg in bot.search_messages(message.chat.id, from_user=target.from_user.id):
if count_buffer == count:
@ -127,16 +128,16 @@ async def your_prune(bot: Client, message: Message):
count_buffer += 1
msgs.append(msg.id)
if len(msgs) == 100:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
msgs = []
if msgs:
await message.bot.delete_messages(message.chat.id, msgs)
await bot.delete_messages(message.chat.id, msgs)
await log(
f"{lang('prune_hint1')}{lang('yp_hint')} {str(count_buffer)} / {count} {lang('prune_hint2')}"
)
with contextlib.suppress(ValueError):
notification = await send_prune_notify(message, count_buffer, count)
notification = await send_prune_notify(bot, message, count_buffer, count)
await sleep(1)
await notification.delete()
@ -155,8 +156,8 @@ async def delete(message: Message):
await message.delete()
async def send_prune_notify(message: Message, count_buffer, count):
return await message.bot.send_message(
async def send_prune_notify(bot: Client, message: Message, count_buffer, count):
return await bot.send_message(
message.chat.id,
f"{lang('spn_deleted')} {str(count_buffer)} / {str(count)} {lang('prune_hint2')}",
)

View File

@ -19,8 +19,9 @@ from shutil import disk_usage
from subprocess import Popen, PIPE
from pagermaid import start_time, Config, pgm_version
from pagermaid.enums import Client, Message
from pagermaid.listener import listener
from pagermaid.utils import lang, Message, execute
from pagermaid.utils import lang, execute
DCs = {
1: "149.154.175.50",
@ -84,10 +85,10 @@ async def status(message: Message):
@listener(is_plugin=False, command="stats",
description=lang("stats_des"))
async def stats(message: Message):
async def stats(client: Client, message: Message):
msg = await message.edit(lang("stats_loading"))
a, u, g, s, c, b = 0, 0, 0, 0, 0, 0
async for dialog in message.bot.get_dialogs():
async for dialog in client.get_dialogs():
chat_type = dialog.chat.type
if chat_type == ChatType.BOT:
b += 1
@ -141,10 +142,10 @@ async def ping_dc(message: Message):
@listener(is_plugin=False, command="ping",
description=lang("ping_des"))
async def ping(message: Message):
async def ping(client: Client, message: Message):
""" Calculates latency between PagerMaid and Telegram. """
start = datetime.now()
await message.bot.invoke(Ping(ping_id=0))
await client.invoke(Ping(ping_id=0))
end = datetime.now()
ping_duration = (end - start).microseconds / 1000
start = datetime.now()

View File

@ -3,7 +3,8 @@ from pagermaid.listener import listener
from pagermaid.group_manager import add_permission_for_group, Permission, remove_permission_for_group, \
add_user_to_group, remove_user_from_group, add_permission_for_user, remove_permission_for_user, \
permissions
from pagermaid.utils import lang, Message, edit_delete, _status_sudo
from pagermaid.enums import Client, Message
from pagermaid.utils import lang, edit_delete, _status_sudo
from pagermaid.single_utils import get_sudo_list
@ -18,7 +19,7 @@ def from_msg_get_sudo_id(message: Message) -> int:
need_admin=True,
parameters="{on|off|add|remove|gaddp|gaddu|gdelp|gdelu|glist|uaddp|udelp|list}",
description=lang('sudo_des'))
async def sudo_change(message: Message):
async def sudo_change(client: Client, message: Message):
""" To enable or disable sudo of your userbot. """
input_str = message.arguments
sudo = get_sudo_list()
@ -76,10 +77,10 @@ async def sudo_change(message: Message):
for i in sudo:
try:
if i > 0:
user = await message.bot.get_users(i)
user = await client.get_users(i)
text += f"{user.mention()} - {' '.join(permissions.get_roles_for_user(str(i)))}\n"
else:
chat = await message.bot.get_chat(i)
chat = await client.get_chat(i)
text += f"{chat.title} - {' '.join(permissions.get_roles_for_user(str(i)))}\n"
for j in permissions.get_permissions_for_user(str(i)):
text += f"{'-' if j[2] == 'ejection' else ''}{j[1]}\n"

View File

@ -58,8 +58,6 @@ class Client(Client): # noqa
class Message(Message): # noqa
arguments: str
parameter: List
bot: Client
request: Optional[AsyncClient] = None
def obtain_message(self) -> Optional[str]:
""" Obtains a message from either the reply message or command arguments. """