### AI-Generated Module Example Source: https://www.erisdev.com This snippet demonstrates a basic structure for a module that could be generated with AI assistance. It includes a simple `on_load` method for logging. ```python # 将 ErisPulse 物料投喂给 AI # 即可直接生成可用模块 class AIModule(BaseModule): async def on_load(self): self.logger.info("AI 生成就绪") ``` -------------------------------- ### Configure Module Loading Strategy Source: https://www.erisdev.com Define a custom module with a specific loading strategy. This example sets the module to be lazy-loaded. ```python # pip install ErisPulse-MyModule # or: epsdk install MyModule class MyModule(BaseModule): @staticmethod def get_load_strategy(): return ModuleLoadStrategy(lazy_load=True) ``` -------------------------------- ### Interactive Conversation with ErisPulse Source: https://www.erisdev.com Implement interactive conversations using built-in primitives like `choose` for selection and `confirm` for confirmation. This example guides a user through a color preference survey. ```python @command("survey", help="问卷调查") async def survey_handler(event): choice = await event.choose( "你喜欢什么颜色?", ["红色", "绿色", "蓝色"] ) if await event.confirm("确认提交?"): await event.reply("感谢参与!") ``` -------------------------------- ### SendDSL Chain API for Messaging Source: https://www.erisdev.com Utilize the SendDSL chain API for constructing and sending messages. This example shows how to target a group, mention a user, reply to a message, and send text content. ```python adapter.Send.To("group", "G1001") \ .At("U2001") \ .Reply("msg123") \ .Text("Hello World") ``` -------------------------------- ### Multi-Platform Command Handler Source: https://www.erisdev.com Write a single command handler that works across multiple platforms like Yunhu, Telegram, and QQ. The `event.get_platform()` method helps identify the current platform. ```python @command("hello") async def hello(event): # 云湖 · Telegram · QQ · 邮件... # 同一份代码,所有平台运行 platform = event.get_platform() await event.reply(f"Hello from {platform}!") ``` -------------------------------- ### Constructing Messages with MessageBuilder Source: https://www.erisdev.com Use the `MessageBuilder` to construct structured messages with various components like mentions, text, and images. The `build()` method finalizes the message, which can then be sent using the adapter. ```python from ErisPulse.Core import MessageBuilder msg = ( MessageBuilder() .mention("U1001") .text(" 请查看这张图:") .image("https://example.com/img.jpg") .build() ) await adapter.Send.To("group", "G1").Raw_ob12(msg) ``` -------------------------------- ### Define Commands with ErisPulse Source: https://www.erisdev.com Register command handlers using the `@command()` decorator. This allows for platform-agnostic command execution, as the same code can run across different platforms. ```python @command("hello") async def hello_handler(event): platform = event.get_platform() # 同一份代码,多平台运行 await event.reply("Hello!") ``` -------------------------------- ### Lifecycle Event Hooks Source: https://www.erisdev.com Register event listeners for various lifecycle events such as bot online status and module loading. These hooks allow custom actions to be performed at specific points in the bot's lifecycle. ```python @sdk.lifecycle.on("adapter.bot.online") async def on_bot_online(data): platform = data["platform"] bot_id = data["bot_id"] sdk.logger.info(f"Bot上线: {platform}/{bot_id}") @sdk.lifecycle.on("module.load") async def on_module_load(data): print(f"模块加载: {data['module_name']}") ``` -------------------------------- ### Handle Incoming Messages with ErisPulse Source: https://www.erisdev.com Use the `@message.on_message()` decorator to define a handler for incoming messages. This function processes the message text and replies to the sender. ```python @message.on_message() async def handler(event): text = event.get_text() await event.reply(f"收到: {text}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.