一、进阶功能实现
在上一个教程基础上,添加更多实用功能。
功能1:数据库支持
- const sqlite3 = require('sqlite3').verbose();
- class TodoSkill {
- constructor() {
- this.db = new sqlite3.Database('todo.db');
- this.initTable();
- }
- initTable() {
- this.db.run(`
- CREATE TABLE IF NOT EXISTS todos (
- id INTEGER PRIMARY KEY,
- task TEXT,
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
- )
- `);
- }
- }
- module.exports = new TodoSkill();
复制代码
功能2:定时任务
- const cron = require('node-cron');
- module.exports = {
- async onLoad(context) {
- cron.schedule('0 9 * * *', () => {
- context.send('早上好!今天也是充满希望的一天 ☀️');
- });
- }
- };
复制代码
功能3:消息监听
- module.exports = {
- async onMessage(context, message) {
- if (message.text.includes('红包')) {
- return '红包已经被抢完啦~ 🧧';
- }
- }
- };
复制代码
功能4:调用 AI 模型
- module.exports = {
- async onCommand(context, args) {
- const prompt = args.join(' ');
- const response = await context.ai.chat({
- model: 'kimi',
- messages: [{ role: 'user', content: prompt }]
- });
- return response.content;
- }
- };
复制代码
二、发布到社区
1. 创建 GitHub 仓库
2. 完善 README 文档
3. 提交到 OpenClaw Skill 市场
4. 在本论坛分享你的作品!
期待看到你的 Skill! |