From 155c774de679812ce9e9819ae6b8c663cfab8971 Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Tue, 4 Jan 2022 19:34:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=E2=9C=A8=E2=AC=86=EF=B8=8F=20Fix?= =?UTF-8?q?=20edit=20inlinebot=20command=20message=20error=20and=20eval=20?= =?UTF-8?q?support=20dev=20file=20(#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 部分插件不再处理通过 inlinebot 发送的消息 ✨ eval 支持通过文件授权开发者权限 ⬆️ 升级 sentry 依赖包 --- languages/built-in/en.yml | 2 +- languages/built-in/zh-cn.yml | 2 +- languages/built-in/zh-tw.yml | 2 +- pagermaid/listener.py | 6 ++++++ pagermaid/modules/system.py | 19 ++++++++++++------- requirements.txt | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/languages/built-in/en.yml b/languages/built-in/en.yml index 771e6f2..94b73ee 100644 --- a/languages/built-in/en.yml +++ b/languages/built-in/en.yml @@ -457,7 +457,7 @@ eval_channel: Something went wrong ~ The current PagerMaid-Modify configuration eval_success: execute Python commands remotely eval_need_dev: '**Please note: This command can directly operate your account** -This command is only for developers. If you know what you are doing, please manually configure the `dev` item in the Redis database to any value.' +This command is only for developers. If you know what you are doing, please manually configure the `dev` item in the Redis database to any value or create the `dev` file in the `data` folder.' # restart restart_des: Restart PagerMaid-Modify restart_processing: Try to restart PagerMaid-Modify. diff --git a/languages/built-in/zh-cn.yml b/languages/built-in/zh-cn.yml index e136d9b..12446e1 100644 --- a/languages/built-in/zh-cn.yml +++ b/languages/built-in/zh-cn.yml @@ -472,7 +472,7 @@ eval_channel: 出错了呜呜呜 ~ 当前 PagerMaid-Modify 的配置禁止在频 eval_success: 远程执行 Python 命令 eval_need_dev: '**请注意:此命令可以直接操作您的账户** -此命令仅适用于开发者,如果您知道您在做什么的话,请手动在 Redis 数据库配置 dev 项为任意值。' +此命令仅适用于开发者,如果您知道您在做什么的话,请手动在 Redis 数据库配置 dev 项为任意值或者在 data 文件夹下创建 dev 文件。' ## restart restart_des: 使 PagerMaid-Modify 重新启动 restart_processing: 尝试重新启动 PagerMaid-Modify. diff --git a/languages/built-in/zh-tw.yml b/languages/built-in/zh-tw.yml index bb8d9de..967956b 100644 --- a/languages/built-in/zh-tw.yml +++ b/languages/built-in/zh-tw.yml @@ -457,7 +457,7 @@ eval_channel: Error!不能在頻道執行指令。 eval_success: 執行 Python 指令 eval_need_dev: '**請注意:此命令可以直接操作您的賬戶** -此命令僅適用於開發者,如果您知道您在做什麼的話,請手動在 Redis 數據庫配置 dev 項為任意值。' +此命令僅適用於開發者,如果您知道您在做什麼的話,請手動在 Redis 數據庫配置 dev 項為任意值或者在 data 文件夾下創建 dev 文件。' # restart restart_des: 重新啟動 restart_processing: 嘗試重新啟動 diff --git a/pagermaid/listener.py b/pagermaid/listener.py index 701c7ce..82f618c 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -39,6 +39,7 @@ def listener(**args): owners_only = args.get("owners_only", False) admins_only = args.get("admins_only", False) groups_only = args.get("groups_only", False) + support_inline = args.get("support_inline", False) if command is not None: if command in help_messages: raise ValueError(f"{lang('error_prefix')} {lang('command')} \"{command}\" {lang('has_reg')}") @@ -67,6 +68,8 @@ def listener(**args): del args['admins_only'] if 'groups_only' in args: del args['groups_only'] + if 'support_inline' in args: + del args['support_inline'] def decorator(function): @@ -86,6 +89,9 @@ def listener(**args): if groups_only: if not context.is_group: return + # filter inline bot msg + if not support_inline and context.via_bot_id: + return try: analytic = True try: diff --git a/pagermaid/modules/system.py b/pagermaid/modules/system.py index 9738177..d02604d 100644 --- a/pagermaid/modules/system.py +++ b/pagermaid/modules/system.py @@ -1,9 +1,10 @@ """ System related utilities for PagerMaid to integrate into the system. """ import io, sys, traceback +from os.path import exists from platform import node from getpass import getuser -from os import geteuid +from os import geteuid, sep from requests import head from asyncio import sleep from requests.exceptions import MissingSchema, InvalidURL, ConnectionError @@ -73,12 +74,16 @@ async def sh(context): parameters=lang('eval_parameters')) async def sh(context): """ Run python commands from Telegram. """ - if not redis_status(): - await context.edit(f"{lang('error_prefix')}{lang('redis_dis')}") - return - if not redis.get("dev"): - await context.edit(lang('eval_need_dev')) - return + dev_mode = False + # file + if exists(f"data{sep}dev"): + dev_mode = True + # redis + if redis_status(): + if redis.get("dev"): + dev_mode = True + if not dev_mode: + return await context.edit(lang('eval_need_dev')) if context.is_channel and not context.is_group: await context.edit(lang('eval_channel')) return diff --git a/requirements.txt b/requirements.txt index 447d6da..8701990 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,6 +35,6 @@ cheroot>=8.5.2 python-socks[asyncio]>=1.2.4 certifi>=2021.5.30 magic_google>=0.2.9 -sentry-sdk>=1.4.1 +sentry-sdk>=1.5.1 analytics-python>=1.4.0 beautifulsoup4>=4.9.3