2022-06-24 11:48:19 +00:00
|
|
|
from telegram.ext import CallbackContext, ExtBot
|
|
|
|
|
|
|
|
from service import BaseService
|
|
|
|
|
|
|
|
|
|
|
|
class PaimonContext(CallbackContext[ExtBot, dict, dict, dict]):
|
2022-07-07 01:36:34 +00:00
|
|
|
"""自定义的PaimoeContext"""
|
2022-06-24 11:48:19 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def service(self) -> BaseService:
|
2022-07-07 01:36:34 +00:00
|
|
|
"""在回调中从 bot_data 获取 service 实例
|
|
|
|
|
|
|
|
:return: BaseService 实例
|
|
|
|
"""
|
|
|
|
value = self.application.bot_data.get("service")
|
2022-06-24 11:48:19 +00:00
|
|
|
if value is None:
|
2022-07-07 01:36:34 +00:00
|
|
|
raise RuntimeError("没有找到与此上下文对象关联的实例化服务")
|
2022-06-24 11:48:19 +00:00
|
|
|
return value
|