mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-26 02:11:03 +00:00
693cd774d3
* 重构插件传入 `service` 方式 重构插件传入 `service` 方式 将 `create_handlers`函数的修饰符改为 `classmethod`
19 lines
540 B
Python
19 lines
540 B
Python
from telegram.ext import CallbackContext, ExtBot
|
|
|
|
from service import BaseService
|
|
|
|
|
|
class PaimonContext(CallbackContext[ExtBot, dict, dict, dict]):
|
|
"""自定义的PaimoeContext"""
|
|
|
|
@property
|
|
def service(self) -> BaseService:
|
|
"""在回调中从 bot_data 获取 service 实例
|
|
|
|
:return: BaseService 实例
|
|
"""
|
|
value = self.application.bot_data.get("service")
|
|
if value is None:
|
|
raise RuntimeError("没有找到与此上下文对象关联的实例化服务")
|
|
return value
|