🔖 Update to v1.0.2

This commit is contained in:
xtaodada 2022-05-25 19:26:50 +08:00
parent 7767845b64
commit fade059e80
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
8 changed files with 98 additions and 48 deletions

View File

@ -9,7 +9,7 @@ import pyromod.listen
from pyrogram import Client from pyrogram import Client
import sys import sys
pgm_version = "1.0.1" pgm_version = "1.0.2"
CMD_LIST = {} CMD_LIST = {}
module_dir = __path__[0] module_dir = __path__[0]
working_dir = getcwd() working_dir = getcwd()
@ -17,9 +17,8 @@ working_dir = getcwd()
read_context = {} read_context = {}
help_messages = {} help_messages = {}
all_permissions = [] all_permissions = []
scheduler = AsyncIOScheduler() scheduler = AsyncIOScheduler(timezone="Asia/ShangHai")
if not scheduler.running: if not scheduler.running:
scheduler.configure(timezone="Asia/ShangHai")
scheduler.start() scheduler.start()
logs = getLogger(__name__) logs = getLogger(__name__)
logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s" logging_format = "%(levelname)s [%(asctime)s] [%(name)s] %(message)s"
@ -40,7 +39,12 @@ elif not Config.API_HASH:
sys.exit(1) sys.exit(1)
start_time = datetime.utcnow() start_time = datetime.utcnow()
bot = Client("pagermaid", api_id=Config.API_ID, api_hash=Config.API_HASH, ipv6=Config.IPV6, proxy=Config.PROXY) bot = Client("pagermaid",
session_string=Config.STRING_SESSION,
api_id=Config.API_ID,
api_hash=Config.API_HASH,
ipv6=Config.IPV6,
proxy=Config.PROXY)
async def log(message): async def log(message):

View File

@ -38,8 +38,6 @@ def listener(**args):
is_plugin = args.get('is_plugin', True) is_plugin = args.get('is_plugin', True)
incoming = args.get('incoming', False) incoming = args.get('incoming', False)
outgoing = args.get('outgoing', True) outgoing = args.get('outgoing', True)
owners_only = args.get("owners_only", False)
admins_only = args.get("admins_only", False)
groups_only = args.get("groups_only", False) groups_only = args.get("groups_only", False)
privates_only = args.get("privates_only", False) privates_only = args.get("privates_only", False)

View File

@ -87,27 +87,12 @@ async def profile(client: Client, message: Message):
parameters="(username/uid/reply)") parameters="(username/uid/reply)")
async def block_user(client: Client, message: Message): async def block_user(client: Client, message: Message):
""" Block a user. """ """ Block a user. """
current_chat = message.chat
if len(message.parameter) > 1: if len(message.parameter) > 1:
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}") await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return return
if not Config.SILENT: if not Config.SILENT:
await message.edit(lang('block_process')) await message.edit(lang('block_process'))
user = None user = message.obtain_user()
# Priority: reply > argument > current_chat
if message.reply_to_message: # Reply to a user
user = message.reply_to_message.from_user
if user:
user = user.id
if not user and len(message.parameter) == 1: # Argument provided
(raw_user,) = message.parameter
if raw_user.isnumeric():
user = int(raw_user)
elif message.entities is not None:
if message.entities[0].type == "text_mention":
user = message.entities[0].user.id
if not user and current_chat.type == "private": # Current chat
user = current_chat.id
if not user: if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}") return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
try: try:
@ -129,20 +114,7 @@ async def unblock_user(client: Client, message: Message):
return return
if not Config.SILENT: if not Config.SILENT:
await message.edit(lang('unblock_process')) await message.edit(lang('unblock_process'))
user = None user = message.obtain_user()
if message.reply_to_message: # Reply to a user
user = message.reply_to_message.from_user
if user:
user = user.id
if not user and len(message.parameter) == 1: # Argument provided
(raw_user,) = message.parameter
if raw_user.isnumeric():
user = int(raw_user)
elif message.entities is not None:
if message.entities[0].type == "text_mention":
user = message.entities[0].user.id
if not user and message.chat.type == "private": # Current chat
user = message.chat.id
if not user: if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}") return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
try: try:

View File

@ -1,6 +1,6 @@
from os import sep, remove, mkdir from os import sep, remove, mkdir
from os.path import exists from os.path import exists
from typing import List from typing import List, Optional
from pyrogram.types import Message from pyrogram.types import Message
from sqlitedict import SqliteDict from sqlitedict import SqliteDict
@ -29,12 +29,13 @@ class Message(Message): # noqa
arguments: str arguments: str
parameter: List parameter: List
async def safe_delete(self, revoke: bool = True): def obtain_message(self) -> Optional[str]:
try: """ Obtains a message from either the reply message or command arguments. """
return await self._client.delete_messages( return
chat_id=self.chat.id,
message_ids=self.id, def obtain_user(self) -> Optional[int]:
revoke=revoke """ Obtains a user from either the reply message or command arguments. """
) return
except Exception as e: # noqa
return False async def safe_delete(self, revoke: bool = True) -> None:
return

View File

@ -160,6 +160,31 @@ class Message(pyrogram.types.Message):
except Exception as e: # noqa except Exception as e: # noqa
return False return False
@patchable
def obtain_message(self) -> Optional[str]:
""" Obtains a message from either the reply message or command arguments. """
return self.arguments if self.arguments else (self.reply_to_message.text if self.reply_to_message else None)
@patchable
def obtain_user(self) -> Optional[int]:
""" Obtains a user from either the reply message or command arguments. """
user = None
# Priority: reply > argument > current_chat
if self.reply_to_message: # Reply to a user
user = self.reply_to_message.from_user
if user:
user = user.id
if not user and len(self.parameter) == 1: # Argument provided
(raw_user,) = self.parameter
if raw_user.isnumeric():
user = int(raw_user)
elif self.entities is not None:
if self.entities[0].type == pyrogram.enums.MessageEntityType.TEXT_MENTION:
user = self.entities[0].user.id
if not user and self.chat.type == pyrogram.enums.ChatType.PRIVATE: # Current chat
user = self.chat.id
return user
@patchable @patchable
async def edit_text( async def edit_text(
self, self,

50
utils/gensession.py Normal file
View File

@ -0,0 +1,50 @@
import asyncio
import os
from sys import executable, exit
try:
from pyrogram.errors import ApiIdInvalid, PhoneNumberInvalid
from pyrogram import Client
print("Found an existing installation of Pyrogram...\nSuccessfully Imported.")
except ImportError:
print("Installing Pyrogram...")
os.system(f"{executable} -m pip install pyrogram")
print("Done. Installed and imported pyrogram.")
from pyrogram.errors import ApiIdInvalid, PhoneNumberInvalid
from pyrogram import Client
async def main():
API_ID = 0
try:
API_ID = int(input("Please enter your API ID: "))
except ValueError:
print("APP ID must be an integer.\nQuitting...")
exit(0)
except Exception as e:
raise e
API_HASH = input("Please enter your API HASH: ")
try:
async with Client("pagermaid", API_ID, API_HASH) as bot:
print("Generating a user session...")
await bot.send_message(
"me",
f"**PagerMaid** `String SESSION`:\n\n`{await bot.export_session_string()}`",
)
print("Your SESSION has been generated. Check your telegram saved messages!")
exit(0)
except ApiIdInvalid:
print("Your API ID/API HASH combination is invalid. Kindly recheck.\nQuitting...")
exit(0)
except ValueError:
print("API HASH must not be empty!\nQuitting...")
exit(0)
except PhoneNumberInvalid:
print("The phone number is invalid!\nQuitting...")
exit(0)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

View File

@ -252,7 +252,7 @@ debian_require_install() {
download_repo() { download_repo() {
echo "下载 repository 中 . . ." echo "下载 repository 中 . . ."
rm -rf /var/lib/pagermaid >>/dev/null 2>&1 rm -rf /var/lib/pagermaid >>/dev/null 2>&1
git clone https://gitlab.com/Xtao-Labs/pagermaid-modify.git /var/lib/pagermaid >>/dev/null 2>&1 git clone https://github.com/TeamPGM/PagerMaid-Pyro.git /var/lib/pagermaid >>/dev/null 2>&1
cd /var/lib/pagermaid >>/dev/null 2>&1 cd /var/lib/pagermaid >>/dev/null 2>&1
echo "Hello World!" >/var/lib/pagermaid/public.lock echo "Hello World!" >/var/lib/pagermaid/public.lock
} }