返回顶部
7*24新情报

【教程】手把手教你开发第一个 OpenClaw Skill(进阶版)

[复制链接]
admin 显示全部楼层 发表于 昨天 17:54 |阅读模式 打印 上一主题 下一主题
一、进阶功能实现

在上一个教程基础上,添加更多实用功能。

功能1:数据库支持
  1. const sqlite3 = require('sqlite3').verbose();
  2. class TodoSkill {
  3.   constructor() {
  4.     this.db = new sqlite3.Database('todo.db');
  5.     this.initTable();
  6.   }
  7.   initTable() {
  8.     this.db.run(`
  9.       CREATE TABLE IF NOT EXISTS todos (
  10.         id INTEGER PRIMARY KEY,
  11.         task TEXT,
  12.         created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  13.       )
  14.     `);
  15.   }
  16. }
  17. module.exports = new TodoSkill();
复制代码

功能2:定时任务
  1. const cron = require('node-cron');
  2. module.exports = {
  3.   async onLoad(context) {
  4.     cron.schedule('0 9 * * *', () => {
  5.       context.send('早上好!今天也是充满希望的一天 ☀️');
  6.     });
  7.   }
  8. };
复制代码

功能3:消息监听
  1. module.exports = {
  2.   async onMessage(context, message) {
  3.     if (message.text.includes('红包')) {
  4.       return '红包已经被抢完啦~ 🧧';
  5.     }
  6.   }
  7. };
复制代码

功能4:调用 AI 模型
  1. module.exports = {
  2.   async onCommand(context, args) {
  3.     const prompt = args.join(' ');
  4.     const response = await context.ai.chat({
  5.       model: 'kimi',
  6.       messages: [{ role: 'user', content: prompt }]
  7.     });
  8.     return response.content;
  9.   }
  10. };
复制代码

二、发布到社区

1. 创建 GitHub 仓库
2. 完善 README 文档
3. 提交到 OpenClaw Skill 市场
4. 在本论坛分享你的作品!

期待看到你的 Skill!
回复

使用道具 举报

default_avator1
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
快速回复 返回顶部 返回列表