🎨 Handle Not Enough Permissions Exception

This commit is contained in:
洛水居室 2022-12-18 22:24:27 +08:00
parent c73fbaaf07
commit 807ae86e8a
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 18 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import random
from telegram import Update, Poll
from telegram.constants import ChatAction
from telegram.error import BadRequest
from telegram.ext import CallbackContext, CommandHandler, filters
from core.admin import BotAdminService
@ -50,14 +51,20 @@ class QuizPlugin(Plugin, BasePlugin):
return None
random.shuffle(_options)
index = _options.index(correct_option)
poll_message = await update.effective_message.reply_poll(
question.text,
_options,
correct_option_id=index,
is_anonymous=False,
open_period=self.time_out,
type=Poll.QUIZ,
)
try:
poll_message = await message.reply_poll(
question.text,
_options,
correct_option_id=index,
is_anonymous=False,
open_period=self.time_out,
type=Poll.QUIZ,
)
except BadRequest as exc:
if "Not enough rights" in exc.message:
poll_message = await message.reply_text("出错了呜呜呜 ~ 权限不足,请请检查投票权限是否开启")
else:
raise exc
if filters.ChatType.GROUPS.filter(message):
self._add_delete_message_job(context, message.chat_id, message.message_id, 300)
self._add_delete_message_job(context, poll_message.chat_id, poll_message.message_id, 300)

View File

@ -146,6 +146,9 @@ def error_callable(func: Callable) -> Callable:
text = "气死我了!怎么有人喜欢发一个命令就秒删了!"
elif "Message is not modified" in exc.message:
telegram_warning(update, exc.message)
elif "Not enough rights" in exc.message:
telegram_warning(update, exc.message)
text = "出错了呜呜呜 ~ 权限不足,请检查对应权限是否开启"
else:
logger.error("python-telegram-bot 请求错误")
logger.exception(exc)