From 9ced9a7b28edc9e6db827a4e6bfb46c256cc4788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 22 Jun 2022 13:42:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20`RestrictsCalls`=20?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E5=8F=AA=E5=88=A0=E9=99=A4=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E5=8F=91=E5=87=BA=E7=9A=84=E5=91=BD=E4=BB=A4=20=E5=B9=B6?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=85=B6=E4=BB=96=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/artifact_rate.py | 3 ++- plugins/base.py | 3 ++- plugins/cookies.py | 3 ++- plugins/daily_note.py | 3 ++- plugins/gacha.py | 2 +- plugins/ledger.py | 3 ++- plugins/sign.py | 3 ++- plugins/strategy.py | 5 +++-- plugins/uid.py | 3 ++- plugins/weapon.py | 5 +++-- 10 files changed, 21 insertions(+), 12 deletions(-) diff --git a/plugins/artifact_rate.py b/plugins/artifact_rate.py index 35716ef2..d97a521e 100644 --- a/plugins/artifact_rate.py +++ b/plugins/artifact_rate.py @@ -6,7 +6,7 @@ from telegram.helpers import escape_markdown from logger import Log from model.apihelper.artifact import ArtifactOcrRate, get_comment, get_format_sub_item -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService @@ -64,6 +64,7 @@ class ArtifactRate(BasePlugins): "_评分、识图均来自 genshin\\.pub_" @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> int: message = update.message user = update.effective_user diff --git a/plugins/base.py b/plugins/base.py index 4a346291..5cc631a3 100644 --- a/plugins/base.py +++ b/plugins/base.py @@ -129,7 +129,8 @@ class RestrictsCalls: if time.time() - command_time <= 20: if _try_delete_message: try: - await message.delete() + if filters.ChatType.GROUPS.filter(message): + await message.delete() except BadRequest as error: Log.warning("删除消息失败", error) return _return_data diff --git a/plugins/cookies.py b/plugins/cookies.py index fbdfe99f..b70723fb 100644 --- a/plugins/cookies.py +++ b/plugins/cookies.py @@ -9,7 +9,7 @@ from telegram.helpers import escape_markdown from logger import Log from model.base import ServiceEnum -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService from service.base import UserInfoData @@ -65,6 +65,7 @@ class Cookies(BasePlugins): return self.CHECK_SERVER @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def check_server(self, update: Update, context: CallbackContext) -> int: user = update.effective_user cookies_command_data: CookiesCommandData = context.chat_data.get("cookies_command_data") diff --git a/plugins/daily_note.py b/plugins/daily_note.py index f18157a5..e0ec8461 100644 --- a/plugins/daily_note.py +++ b/plugins/daily_note.py @@ -10,7 +10,7 @@ from telegram.ext import CallbackContext, CommandHandler, MessageHandler, Conver from logger import Log from model.base import ServiceEnum -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService from service.base import UserInfoData @@ -102,6 +102,7 @@ class DailyNote(BasePlugins): return png_data @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> int: user = update.effective_user message = update.message diff --git a/plugins/gacha.py b/plugins/gacha.py index 6be28ce7..7df23b8b 100644 --- a/plugins/gacha.py +++ b/plugins/gacha.py @@ -27,7 +27,7 @@ class Gacha(BasePlugins): CHECK_SERVER, COMMAND_RESULT = range(10600, 10602) - @RestrictsCalls(return_data=ConversationHandler.END, try_delete_message=True) + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) @conversation_error_handler async def command_start(self, update: Update, context: CallbackContext) -> None: message = update.message diff --git a/plugins/ledger.py b/plugins/ledger.py index 5fc5404b..f84513f2 100644 --- a/plugins/ledger.py +++ b/plugins/ledger.py @@ -10,7 +10,7 @@ from telegram.ext import CallbackContext, CommandHandler, MessageHandler, Conver from logger import Log from model.base import ServiceEnum -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService from service.base import UserInfoData @@ -123,6 +123,7 @@ class Ledger(BasePlugins): return png_data @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> int: user = update.effective_user message = update.message diff --git a/plugins/sign.py b/plugins/sign.py index d1c01c9c..cdbaaab9 100644 --- a/plugins/sign.py +++ b/plugins/sign.py @@ -10,7 +10,7 @@ from telegram.ext import CallbackContext, CommandHandler, MessageHandler, Conver from logger import Log from model.base import ServiceEnum -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService from service.base import UserInfoData @@ -90,6 +90,7 @@ class Sign(BasePlugins): return message @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> int: user = update.effective_user message = update.message diff --git a/plugins/strategy.py b/plugins/strategy.py index 2549b619..82e3cb8e 100644 --- a/plugins/strategy.py +++ b/plugins/strategy.py @@ -2,12 +2,12 @@ import re from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction, ParseMode -from telegram.ext import CallbackContext, filters +from telegram.ext import CallbackContext, filters, ConversationHandler from logger import Log from metadata.shortname import roleToName from model.helpers import url_to_file -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler @@ -17,6 +17,7 @@ class Strategy(BasePlugins): """ @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> None: message = update.message user = update.effective_user diff --git a/plugins/uid.py b/plugins/uid.py index 0d260332..f6d566ba 100644 --- a/plugins/uid.py +++ b/plugins/uid.py @@ -11,7 +11,7 @@ from telegram.ext import CallbackContext, CommandHandler, MessageHandler, Conver from logger import Log from model.base import ServiceEnum from model.helpers import url_to_file -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler from service import BaseService from service.base import UserInfoData @@ -139,6 +139,7 @@ class Uid(BasePlugins): return png_data @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, return_data=ConversationHandler.END, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> int: user = update.effective_user message = update.message diff --git a/plugins/weapon.py b/plugins/weapon.py index c94c0f61..5e916caf 100644 --- a/plugins/weapon.py +++ b/plugins/weapon.py @@ -2,12 +2,12 @@ import re from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.constants import ChatAction -from telegram.ext import CallbackContext, filters +from telegram.ext import CallbackContext, filters, ConversationHandler from logger import Log from metadata.shortname import weaponToName from model.helpers import url_to_file -from plugins.base import BasePlugins +from plugins.base import BasePlugins, RestrictsCalls from plugins.errorhandler import conversation_error_handler @@ -17,6 +17,7 @@ class Weapon(BasePlugins): """ @conversation_error_handler + @RestrictsCalls(filters_chat=filters.ALL, try_delete_message=True) async def command_start(self, update: Update, context: CallbackContext) -> None: message = update.message user = update.effective_user