From cfb45e47245f8fbe07706903bf07bcdc0f6ca96a Mon Sep 17 00:00:00 2001 From: Xtao_dada Date: Sat, 9 Oct 2021 21:55:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=F0=9F=90=9B=20Change=20the?= =?UTF-8?q?=20default=20location=20of=20update=20notifications=20and=20fix?= =?UTF-8?q?=20some=20bugs.=20(#137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⚡️ 修改更新通知默认位置 🐛 批量修复错误 --- config.gen.yml | 2 +- languages/built-in/zh-tw.yml | 5 ++++ pagermaid/assets/config.gen.yml | 2 +- pagermaid/bots/update.py | 41 +-------------------------------- pagermaid/listener.py | 7 ++++++ pagermaid/modules/fun.py | 3 ++- pagermaid/modules/update.py | 2 +- 7 files changed, 18 insertions(+), 44 deletions(-) diff --git a/config.gen.yml b/config.gen.yml index 81a4745..6ab3089 100644 --- a/config.gen.yml +++ b/config.gen.yml @@ -68,7 +68,7 @@ git_ssh: "https://github.com/Xtao-Labs/PagerMaid-Modify.git" # Update Notice update_check: "True" update_time: "86400" -update_username: "self" +update_username: "PagerMaid_Modify_bot" update_delete: "True" # ipv6 diff --git a/languages/built-in/zh-tw.yml b/languages/built-in/zh-tw.yml index 515eb70..7db2df2 100644 --- a/languages/built-in/zh-tw.yml +++ b/languages/built-in/zh-tw.yml @@ -84,6 +84,11 @@ block_des: 拉黑一個用戶 block_process: 正在拉黑中 . . . block_success: 成功拉黑 block_exist: 已存在黑名單中。 +# unblock +unblock_des: 取消拉黑一個用戶 +unblock_process: 正在取消拉黑中 . . . +unblock_success: 成功取消拉黑 +unblock_exist: 不存在黑名單中。 # avoid # ghost diff --git a/pagermaid/assets/config.gen.yml b/pagermaid/assets/config.gen.yml index 81a4745..6ab3089 100644 --- a/pagermaid/assets/config.gen.yml +++ b/pagermaid/assets/config.gen.yml @@ -68,7 +68,7 @@ git_ssh: "https://github.com/Xtao-Labs/PagerMaid-Modify.git" # Update Notice update_check: "True" update_time: "86400" -update_username: "self" +update_username: "PagerMaid_Modify_bot" update_delete: "True" # ipv6 diff --git a/pagermaid/bots/update.py b/pagermaid/bots/update.py index 8e33a04..1424f8d 100644 --- a/pagermaid/bots/update.py +++ b/pagermaid/bots/update.py @@ -1,11 +1,7 @@ """ Pulls in the new version of PagerMaid from the git server. """ import platform -import requests -import time from datetime import datetime -from distutils.util import strtobool -from json import JSONDecodeError from os import remove from subprocess import run, PIPE from sys import executable @@ -13,45 +9,10 @@ from sys import executable from git import Repo from git.exc import GitCommandError, InvalidGitRepositoryError, NoSuchPathError -from pagermaid import log, config, proxies +from pagermaid import log from pagermaid.listener import listener from pagermaid.utils import execute, lang, alias_command -try: - git_api = config['git_api'] - git_ssh = config['git_ssh'] - need_update_check = strtobool(config['update_check']) - update_time = config['update_time'] - update_username = config['update_username'] - update_delete = strtobool(config['update_delete']) -except KeyError: - git_api = "https://api.github.com/repos/Xtao-Labs/PagerMaid-Modify/commits/master" - git_ssh = 'https://github.com/Xtao-Labs/PagerMaid-Modify.git' - need_update_check = True - update_time = 86400 - update_username = 'self' - update_delete = True -try: - update_time = int(update_time) -except ValueError: - update_time = 86400 -try: - update_username = int(update_username) -except ValueError: - pass - - -def update_get(): - try: - data = requests.get(git_api, proxies=proxies).json() - except JSONDecodeError as e: - raise e - return data - - -update_get_time = 0 -update_id = 0 - @listener(is_plugin=False, incoming=True, owners_only=True, command=alias_command("update"), description=lang('update_des'), diff --git a/pagermaid/listener.py b/pagermaid/listener.py index 97f8df8..701c7ce 100644 --- a/pagermaid/listener.py +++ b/pagermaid/listener.py @@ -38,6 +38,7 @@ def listener(**args): is_plugin = args.get('is_plugin', True) owners_only = args.get("owners_only", False) admins_only = args.get("admins_only", False) + groups_only = args.get("groups_only", False) if command is not None: if command in help_messages: raise ValueError(f"{lang('error_prefix')} {lang('command')} \"{command}\" {lang('has_reg')}") @@ -64,6 +65,8 @@ def listener(**args): del args['owners_only'] if 'admins_only' in args: del args['admins_only'] + if 'groups_only' in args: + del args['groups_only'] def decorator(function): @@ -79,6 +82,10 @@ def listener(**args): if admins_only: if not (await admin_check(context)): return + # groups only + if groups_only: + if not context.is_group: + return try: analytic = True try: diff --git a/pagermaid/modules/fun.py b/pagermaid/modules/fun.py index 58d819b..e9de181 100644 --- a/pagermaid/modules/fun.py +++ b/pagermaid/modules/fun.py @@ -154,7 +154,8 @@ async def flip(context): await edit_reply(result, context) -@listener(is_plugin=False, outgoing=True, command=alias_command("ship"), +@listener(is_plugin=False, outgoing=True, groups_only=True, + command=alias_command("ship"), description=lang('ship_des'), parameters=" ") async def ship(context): diff --git a/pagermaid/modules/update.py b/pagermaid/modules/update.py index cb5941c..413d657 100644 --- a/pagermaid/modules/update.py +++ b/pagermaid/modules/update.py @@ -29,7 +29,7 @@ except KeyError: git_ssh = 'https://github.com/Xtao-Labs/PagerMaid-Modify.git' need_update_check = True update_time = 86400 - update_username = 'self' + update_username = 'PagerMaid_Modify_bot' update_delete = True try: update_time = int(update_time)