alicebot.adapter.apscheduler
APScheduler 适配器。
本适配器用于实现定时任务,适配器将使用 APScheduler 实现定时任务,在设定的时间产生一个事件供插件处理。 APScheduler 使用方法请参考:APScheduler。
class APSchedulerAdapter
Bases: alicebot.adapter.Adapter
APScheduler 适配器。
Attributes
name (str)
scheduler (apscheduler.schedulers.asyncio.AsyncIOScheduler)
plugin_class_to_job (Dict[Type[alicebot.plugin.Plugin[Any, Any, Any]], apscheduler.job.Job])
class Config
Bases: alicebot.config.ConfigModel
APScheduler 配置类,将在适配器被加载时被混入到机器人主配置中。
Attributes
- scheduler_config (Dict[str, Any]) - 调度器配置。
method __init__(__pydantic_self__, **data)
{#BaseModel.__init__}
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
__init__
uses __pydantic_self__
instead of the more common self
for the first arg to allow self
as a field name.
Arguments
- data (Any)
Returns
Type: None
method __init__(self, bot)
{#Adapter.__init__}
初始化。
Arguments
- bot (Bot) - 当前机器人对象。
Returns
Type: None
async method create_event(self, plugin_class)
{#APSchedulerAdapter.create_event}
创建 APSchedulerEvent
事件。
Arguments
- plugin_class (Type[alicebot.plugin.Plugin[Any, Any, Any]]) -
Plugin
类。
- plugin_class (Type[alicebot.plugin.Plugin[Any, Any, Any]]) -
Returns
Type: None
async method run(self)
启动调度器。
Returns
Type: None
async method send(self, *args, **kwargs)
APScheduler 适配器不适用发送消息。
Arguments
args (Any)
kwargs (Any)
Returns
Type: Any
async method shutdown(self)
关闭调度器。
Returns
Type: None
async method startup(self)
创建 AsyncIOScheduler
对象。
Returns
Type: None
function scheduler_decorator(trigger, trigger_args, override_rule = False)
{#scheduler_decorator}
用于为插件类添加计划任务功能的装饰器。
Arguments
trigger (str) - APScheduler 触发器。
trigger_args (Dict[str, Any]) - APScheduler 触发器参数。
override_rule (bool) - 是否重写
rule()
方法。 若为True
,则会在rule()
方法中添加处理本插件定义的计划任务事件的逻辑。
Returns
Type: Callable[[Type[~PluginT]], Type[~PluginT]]