mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-29 11:03:16 +00:00
🐛 Fix weapon plugin not handling notice correctly in AssetsCouldNotFound
exception
This commit is contained in:
parent
a10ff3728b
commit
304eb5e740
@ -45,7 +45,10 @@ class AssetsServiceError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class AssetsCouldNotFound(AssetsServiceError):
|
class AssetsCouldNotFound(AssetsServiceError):
|
||||||
pass
|
def __init__(self, message: str, target: str):
|
||||||
|
self.message = message
|
||||||
|
self.target = target
|
||||||
|
super().__init__(f"{message}: target={message}")
|
||||||
|
|
||||||
|
|
||||||
class _AssetsService(ABC):
|
class _AssetsService(ABC):
|
||||||
@ -223,7 +226,7 @@ class _AvatarAssets(_AssetsService):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
target = roleToId(target)
|
target = roleToId(target)
|
||||||
if isinstance(target, str) or target is None:
|
if isinstance(target, str) or target is None:
|
||||||
raise AssetsCouldNotFound(f"找不到对应的角色: target={temp}")
|
raise AssetsCouldNotFound("找不到对应的角色", temp)
|
||||||
result.id = target
|
result.id = target
|
||||||
result._enka_api = self._enka_api
|
result._enka_api = self._enka_api
|
||||||
return result
|
return result
|
||||||
@ -288,7 +291,7 @@ class _WeaponAssets(_AssetsService):
|
|||||||
if isinstance(target, str):
|
if isinstance(target, str):
|
||||||
target = int(target) if target.isnumeric() else weaponToId(target)
|
target = int(target) if target.isnumeric() else weaponToId(target)
|
||||||
if isinstance(target, str) or target is None:
|
if isinstance(target, str) or target is None:
|
||||||
raise AssetsCouldNotFound(f"找不到对应的武器: target={temp}")
|
raise AssetsCouldNotFound("找不到对应的武器", temp)
|
||||||
result.id = target
|
result.id = target
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -329,7 +332,7 @@ class _MaterialAssets(_AssetsService):
|
|||||||
else:
|
else:
|
||||||
target = {v["name"]: int(k) for k, v in MATERIAL_DATA.items()}.get(target)
|
target = {v["name"]: int(k) for k, v in MATERIAL_DATA.items()}.get(target)
|
||||||
if isinstance(target, str) or target is None:
|
if isinstance(target, str) or target is None:
|
||||||
raise AssetsCouldNotFound(f"找不到对应的素材: target={temp}")
|
raise AssetsCouldNotFound("找不到对应的素材", temp)
|
||||||
result.id = target
|
result.id = target
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ class DailyMaterial(Plugin, BasePlugin):
|
|||||||
material = HONEY_DATA["material"][mid]
|
material = HONEY_DATA["material"][mid]
|
||||||
materials.append(ItemData(id=mid, icon=path, name=material[1], rarity=material[2]))
|
materials.append(ItemData(id=mid, icon=path, name=material[1], rarity=material[2]))
|
||||||
except AssetsCouldNotFound as exc:
|
except AssetsCouldNotFound as exc:
|
||||||
logger.error(f"出错了呜呜呜 ~ {repr(exc)}")
|
logger.warning("%s mid[%s]", exc.message, exc.target)
|
||||||
await notice.edit_text("出错了呜呜呜 ~ 派蒙找不到一些素材")
|
await notice.edit_text("出错了呜呜呜 ~ 派蒙找不到一些素材")
|
||||||
return
|
return
|
||||||
areas.append(
|
areas.append(
|
||||||
|
@ -2,7 +2,7 @@ from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
|||||||
from telegram.constants import ChatAction
|
from telegram.constants import ChatAction
|
||||||
from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters
|
from telegram.ext import CallbackContext, CommandHandler, MessageHandler, filters
|
||||||
|
|
||||||
from core.base.assets import AssetsService
|
from core.base.assets import AssetsService, AssetsCouldNotFound
|
||||||
from core.baseplugin import BasePlugin
|
from core.baseplugin import BasePlugin
|
||||||
from core.plugin import Plugin, handler
|
from core.plugin import Plugin, handler
|
||||||
from core.template import TemplateService
|
from core.template import TemplateService
|
||||||
@ -109,7 +109,15 @@ class WeaponPlugin(Plugin, BasePlugin):
|
|||||||
}
|
}
|
||||||
return _template_data
|
return _template_data
|
||||||
|
|
||||||
|
try:
|
||||||
template_data = await input_template_data(weapon_data)
|
template_data = await input_template_data(weapon_data)
|
||||||
|
except AssetsCouldNotFound as exc:
|
||||||
|
logger.warning("%s weapon_name[%s]", exc.message, weapon_name)
|
||||||
|
reply_message = await message.reply_text(f"数据库中没有找到 {weapon_name}")
|
||||||
|
if filters.ChatType.GROUPS.filter(reply_message):
|
||||||
|
self._add_delete_message_job(context, message.chat_id, message.message_id)
|
||||||
|
self._add_delete_message_job(context, reply_message.chat_id, reply_message.message_id)
|
||||||
|
return
|
||||||
png_data = await self.template_service.render(
|
png_data = await self.template_service.render(
|
||||||
"genshin/weapon/weapon.html", template_data, {"width": 540, "height": 540}, ttl=31 * 24 * 60 * 60
|
"genshin/weapon/weapon.html", template_data, {"width": 540, "height": 540}, ttl=31 * 24 * 60 * 60
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user