货币转换器
社区使用实时汇率进行货币转换。
安装
Save as `currency.js`.
源代码
JavaScriptTutorial.terminal
// currency.js
// Usage: currency <amount> <from> <to>
module.exports = async function(context) {
const amount = parseFloat(context.args[0]);
const from = (context.args[1] || 'USD').toUpperCase();
const to = (context.args[2] || 'EUR').toUpperCase();
if (isNaN(amount)) return { error: "Invalid amount" };
const url = `https://api.exchangerate-api.com/v4/latest/${from}`;
const res = await fetch(url);
const data = await res.json();
const rate = data.rates[to];
if (!rate) return { error: "Currency not supported" };
return {
from,
to,
rate,
original: amount,
converted: amount * rate
};
};
实时预览
● 实时演示Agent 会话
如何使用
- 确保已安装必要的依赖项(如果有)。
- 将文件放入您的 OpenClaw skills 文件夹(例如 ~/.openclaw/skills/)。
- 重启您的 Agent 或重新加载配置。
- 使用文件名(不带扩展名)作为工具名称调用它,或者如果描述清晰,可以通过自然语言调用。