Skip to content

Commit

Permalink
🔖 Update to v1.0.8
Browse files Browse the repository at this point in the history
fix #10
  • Loading branch information
omg-xtao committed Jun 8, 2022
1 parent 4401568 commit 2553fa9
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion config.gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mtp_port: ""
mtp_secret: ""

# Apt Git source
git_source: "https://raw.githubusercontent.com/TeamPGM/PagerMaid_Plugins/v2/"
git_source: "https://raw.githubusercontent.com/TeamPGM/PagerMaid_Plugins_Pyro/v2/"
git_ssh: "https://github.com/TeamPGM/PagerMaid-Pyro.git"

# Update Notice
Expand Down
2 changes: 1 addition & 1 deletion pagermaid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pyrogram import Client
import sys

pgm_version = "1.0.7"
pgm_version = "1.0.8"
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
Expand Down
43 changes: 25 additions & 18 deletions pagermaid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,46 @@ class Config:
API_ID = int(os.environ.get("API_ID", config["api_id"]))
API_HASH = os.environ.get("API_HASH", config["api_hash"])
STRING_SESSION = os.environ.get("STRING_SESSION")
DEBUG = strtobool(os.environ.get("DEBUG", config["debug"]))
ERROR_REPORT = strtobool(os.environ.get("ERROR_REPORT", config["error_report"]))
LANGUAGE = os.environ.get("LANGUAGE", config["application_language"])
REGION = os.environ.get("REGION", config["application_region"])
TTS = os.environ.get("TTS", config["application_tts"])
LOG = strtobool(os.environ.get("LOG", config["log"]))
LOG_ID = int(os.environ.get("LOG_ID", config["log_chatid"]))
IPV6 = strtobool(os.environ.get("IPV6", config["ipv6"]))
TIME_FORM = os.environ.get("TIME_FORM", config["time_form"])
DATE_FORM = os.environ.get("DATE_FORM", config["date_form"])
START_FORM = os.environ.get("START_FORM", config["start_form"])
SILENT = strtobool(os.environ.get("SILENT", config["silent"]))
PROXY_ADDRESS = os.environ.get("PROXY_ADDRESS", config["proxy_addr"])
PROXY_PORT = os.environ.get("PROXY_PORT", config["proxy_port"])
DEBUG = strtobool(os.environ.get("PGM_DEBUG", config["debug"]))
ERROR_REPORT = strtobool(os.environ.get("PGM_ERROR_REPORT", config["error_report"]))
LANGUAGE = os.environ.get("PGM_LANGUAGE", config["application_language"])
REGION = os.environ.get("PGM_REGION", config["application_region"])
TTS = os.environ.get("PGM_TTS", config["application_tts"])
LOG = strtobool(os.environ.get("PGM_LOG", config["log"]))
LOG_ID = int(os.environ.get("PGM_LOG_ID", config["log_chatid"]))
IPV6 = strtobool(os.environ.get("PGM_IPV6", config["ipv6"]))
TIME_FORM = os.environ.get("PGM_TIME_FORM", config["time_form"])
DATE_FORM = os.environ.get("PGM_DATE_FORM", config["date_form"])
START_FORM = os.environ.get("PGM_START_FORM", config["start_form"])
SILENT = strtobool(os.environ.get("PGM_PGM_SILENT", config["silent"]))
PROXY_ADDRESS = os.environ.get("PGM_PROXY_ADDRESS", config["proxy_addr"])
PROXY_PORT = os.environ.get("PGM_PROXY_PORT", config["proxy_port"])
PROXY = None
if PROXY_ADDRESS and PROXY_PORT:
PROXY = dict(
hostname=PROXY_ADDRESS,
port=PROXY_PORT,
)
GIT_SOURCE = os.environ.get("GIT_SOURCE", config["git_source"])
GIT_SOURCE = os.environ.get("PGM_GIT_SOURCE", config["git_source"])
GIT_SOURCE = GIT_SOURCE.replace("TeamPGM/PagerMaid-Pyro", "TeamPGM/PagerMaid_Plugins_Pyro")
try:
with open(f"languages{os.sep}built-in{os.sep}{LANGUAGE}.yml", "r", encoding="utf-8") as f:
lang_dict = safe_load(f)
except Exception as e:
print("Reading language YAML file failed")
print("[Degrade] Reading language YAML file failed, try to use the english language file.")
print(e)
sys.exit(1)
try:
with open(f"languages{os.sep}built-in{os.sep}{LANGUAGE}.yml", "r", encoding="utf-8") as f:
lang_dict = safe_load(f)
except Exception as e:
print("[Error] Reading English language YAML file failed.")
print(e)
sys.exit(1)
try:
with open(f"data{os.sep}alias.json", encoding="utf-8") as f:
alias_dict = load_json(f)
except Exception as e:
print(f"Reading alias file failed:{e}")
print(f"[Degrade] Reading alias file failed:{e}")
alias_dict = {}
except ValueError as e:
print(e)
Expand Down
10 changes: 5 additions & 5 deletions pagermaid/modules/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def profile(client: Client, message: Message):
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
if not Config.SILENT:
await message.edit(lang('profile_process'))
message = await message.edit(lang('profile_process'))
if message.reply_to_message:
user = message.reply_to_message.from_user
if not user:
Expand Down Expand Up @@ -91,13 +91,13 @@ async def block_user(client: Client, message: Message):
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
if not Config.SILENT:
await message.edit(lang('block_process'))
message = await message.edit(lang('block_process'))
user = message.obtain_user()
if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
try:
if await client.block_user(user):
await message.edit(f"{lang('block_success')} `{user}`")
return await message.edit(f"{lang('block_success')} `{user}`")
except Exception: # noqa
pass
await message.edit(f"`{user}` {lang('block_exist')}")
Expand All @@ -113,13 +113,13 @@ async def unblock_user(client: Client, message: Message):
await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
return
if not Config.SILENT:
await message.edit(lang('unblock_process'))
message = await message.edit(lang('unblock_process'))
user = message.obtain_user()
if not user:
return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")
try:
if await client.unblock_user(user):
await message.edit(f"{lang('unblock_success')} `{user}`")
return await message.edit(f"{lang('unblock_success')} `{user}`")
except Exception: # noqa
pass
await message.edit(f"`{user}` {lang('unblock_exist')}")
2 changes: 1 addition & 1 deletion pagermaid/modules/avoid.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
""" PagerMaid module for different ways to avoid users. """from pyrogram import Clientfrom pagermaid import logfrom pagermaid.single_utils import sqlitefrom pagermaid.utils import lang, Messagefrom pagermaid.listener import listener@listener(is_plugin=False, outgoing=True, command="ghost", description=lang('ghost_des'), parameters="<true|false|status>")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 client.get_me() self_user_id = myself.id if message.parameter[0] == "true": if message.chat.id == self_user_id: return await message.edit(lang('ghost_e_mark')) sqlite["ghosted.chat_id." + str(message.chat_id)] = True await message.safe_delete() await log(f"{lang('ghost_set_f')} ChatID {str(message.chat_id)} {lang('ghost_set_l')}") elif message.parameter[0] == "false": if message.chat_id == self_user_id: await message.edit(lang('ghost_e_mark')) return try: del sqlite["ghosted.chat_id." + str(message.chat_id)] except KeyError: return await message.edit(lang('ghost_e_noexist')) await message.safe_delete() await log(f"{lang('ghost_set_f')} ChatID {str(message.chat_id)} {lang('ghost_cancel')}") elif message.parameter[0] == "status": if sqlite.get("ghosted.chat_id." + str(message.chat_id), None): await message.edit(lang('ghost_e_exist')) else: await message.edit(lang('ghost_e_noexist')) else: await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")@listener(is_plugin=False, outgoing=True, command="deny", need_admin=True, description=lang('deny_des'), parameters="<true|false|status>")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 client.get_me() self_user_id = myself.id if message.parameter[0] == "true": if message.chat.id == self_user_id: return await message.edit(lang('ghost_e_mark')) sqlite["denied.chat_id." + str(message.chat_id)] = True await message.safe_delete() await log(f"ChatID {str(message.chat_id)} {lang('deny_set')}") elif message.parameter[0] == "false": if message.chat_id == self_user_id: await message.edit(lang('ghost_e_mark')) return try: del sqlite["denied.chat_id." + str(message.chat_id)] except KeyError: return await message.edit(lang('deny_e_noexist')) await message.safe_delete() await log(f"ChatID {str(message.chat_id)} {lang('deny_cancel')}") elif message.parameter[0] == "status": if sqlite.get("denied.chat_id." + str(message.chat_id), None): await message.edit(lang('deny_e_exist')) else: await message.edit(lang('deny_e_noexist')) else: await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)async def set_read_acknowledgement(client: Client, message: Message): """ Event handler to infinitely read ghosted messages. """ if sqlite.get("ghosted.chat_id." + str(message.chat.id), None): await client.read_chat_history(message.chat.id)@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)async def message_removal(_: Client, message: Message): """ Event handler to infinitely delete denied messages. """ if sqlite.get("denied.chat_id." + str(message.chat.id), None): try: await message.delete() except Exception as e: # noqa pass
""" PagerMaid module for different ways to avoid users. """from pyrogram import Clientfrom pagermaid import logfrom pagermaid.single_utils import sqlitefrom pagermaid.utils import lang, Messagefrom pagermaid.listener import listener@listener(is_plugin=False, outgoing=True, command="ghost", description=lang('ghost_des'), parameters="<true|false|status>")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 client.get_me() self_user_id = myself.id if message.parameter[0] == "true": if message.chat.id == self_user_id: return await message.edit(lang('ghost_e_mark')) sqlite["ghosted.chat_id." + str(message.chat_id)] = True await message.safe_delete() await log(f"{lang('ghost_set_f')} ChatID {str(message.chat_id)} {lang('ghost_set_l')}") elif message.parameter[0] == "false": if message.chat_id == self_user_id: await message.edit(lang('ghost_e_mark')) return try: del sqlite["ghosted.chat_id." + str(message.chat_id)] except KeyError: return await message.edit(lang('ghost_e_noexist')) await message.safe_delete() await log(f"{lang('ghost_set_f')} ChatID {str(message.chat_id)} {lang('ghost_cancel')}") elif message.parameter[0] == "status": if sqlite.get("ghosted.chat_id." + str(message.chat_id), None): await message.edit(lang('ghost_e_exist')) else: await message.edit(lang('ghost_e_noexist')) else: await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")@listener(is_plugin=False, outgoing=True, command="deny", need_admin=True, description=lang('deny_des'), parameters="<true|false|status>")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 client.get_me() self_user_id = myself.id if message.parameter[0] == "true": if message.chat.id == self_user_id: return await message.edit(lang('ghost_e_mark')) sqlite["denied.chat_id." + str(message.chat_id)] = True await message.safe_delete() await log(f"ChatID {str(message.chat_id)} {lang('deny_set')}") elif message.parameter[0] == "false": if message.chat_id == self_user_id: await message.edit(lang('ghost_e_mark')) return try: del sqlite["denied.chat_id." + str(message.chat_id)] except KeyError: return await message.edit(lang('deny_e_noexist')) await message.safe_delete() await log(f"ChatID {str(message.chat_id)} {lang('deny_cancel')}") elif message.parameter[0] == "status": if sqlite.get("denied.chat_id." + str(message.chat_id), None): await message.edit(lang('deny_e_exist')) else: await message.edit(lang('deny_e_noexist')) else: await message.edit(f"{lang('error_prefix')}{lang('arg_error')}")@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)async def set_read_acknowledgement(client: Client, message: Message): """ Event handler to infinitely read ghosted messages. """ if sqlite.get("ghosted.chat_id." + str(message.chat.id), None): await client.read_chat_history(message.chat.id)@listener(is_plugin=False, incoming=True, outgoing=False, ignore_edited=True)async def message_removal(_: Client, message: Message): """ Event handler to infinitely delete denied messages. """ if sqlite.get("denied.chat_id." + str(message.chat.id), None): await message.safe_delete()
Expand Down
7 changes: 3 additions & 4 deletions pagermaid/modules/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async def plugin(__: Client, message: Message):
await log(f"{lang('apt_install_success')} {path.basename(file_path)[:-3]}.")
exit(0)
elif len(message.parameter) >= 2:
await message.edit(lang('apt_processing'))
process_list = message.parameter
message = await message.edit(lang('apt_processing'))
del process_list[0]
success_list = []
failed_list = []
Expand Down Expand Up @@ -271,8 +271,7 @@ async def plugin(__: Client, message: Message):
await message.edit(f"<b>{lang('apt_name')}</b>\n\n" +
lang("apt_loading_from_online_but_nothing_need_to_update"))
else:
print(6)
await message.edit(lang("apt_loading_from_online_and_updating"))
message = await message.edit(lang("apt_loading_from_online_and_updating"))
plugin_directory = f"{working_dir}{sep}plugins{sep}"
for i in need_update_list:
remove_plugin(i)
Expand Down Expand Up @@ -334,7 +333,7 @@ async def plugin(__: Client, message: Message):
if not exists(f"{plugin_directory}version.json"):
await message.edit(lang("apt_why_not_install_a_plugin"))
return
await message.edit(lang("stats_loading"))
message = await message.edit(lang("stats_loading"))
list_plugin = []
with open(f"{plugin_directory}version.json", 'r', encoding="utf-8") as f:
version_json = json.load(f)
Expand Down
6 changes: 3 additions & 3 deletions pagermaid/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
description=lang('sysinfo_des'))
async def sysinfo(_: Client, message: Message):
""" Retrieve system information via neofetch. """
message = await message.edit(lang("sysinfo_loading"))
if not Config.SILENT:
message = await message.edit(lang("sysinfo_loading"))
if platform == 'win32':
await message.edit(neofetch_win(), parse_mode=ParseMode.HTML)
return
return await message.edit(neofetch_win(), parse_mode=ParseMode.HTML)
result = await execute("neofetch --config none --stdout")
await message.edit(f"`{result}`")

Expand Down
7 changes: 3 additions & 4 deletions pagermaid/modules/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
async def sh(_: Client, message: Message):
""" Use the command-line from Telegram. """
user = getuser()
command = message.text[4:]
command = message.arguments
hostname = node()

if not command:
Expand Down Expand Up @@ -67,8 +67,7 @@ async def sh_eval(_: Client, message: Message):
try:
cmd = message.text.split(" ", maxsplit=1)[1]
except IndexError:
await message.edit(lang('eval_need_dev'))
return
return await message.edit(lang('eval_need_dev'))
old_stderr = sys.stderr
old_stdout = sys.stdout
redirected_output = sys.stdout = io.StringIO()
Expand Down Expand Up @@ -97,7 +96,7 @@ async def sh_eval(_: Client, message: Message):
)
)
if len(final_output) > 4096:
await message.edit("**>>>** ```{}```".format(cmd))
message = await message.edit("**>>>** ```{}```".format(cmd))
await attach_log(bot, evaluation, message.chat.id, "output.log", message.id)
else:
await message.edit(final_output)
Expand Down
2 changes: 1 addition & 1 deletion pagermaid/modules/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ async def update(_: Client, message: Message):
await execute(f"{executable} -m pip install --upgrade -r requirements.txt")
await execute(f"{executable} -m pip install -r requirements.txt")
await message.edit(lang('update_success'))
exit(1)
exit(0)

0 comments on commit 2553fa9

Please sign in to comment.