Loading...
Loading...
Compare original and translation side by side
/pair Request pairing (generates code)
/pair-code ABC123 Enter pairing code
/unpair Remove your pairing/pair 请求配对(生成验证码)
/pair-code ABC123 输入配对验证码
/unpair 解除配对/pairing list List pending requests
/pairing approve <code> Approve pairing request
/pairing reject <code> Reject pairing request
/pairing users List paired users
/pairing remove <user> Remove user pairing/pairing list 列出待处理的配对请求
/pairing approve <code> 批准配对请求
/pairing reject <code> 拒绝配对请求
/pairing users 列出已配对用户
/pairing remove <user> 移除用户配对/trust <user> owner Grant owner trust
/trust <user> paired Standard trust
/trust list List trust levels/trust <user> owner 授予所有者信任级别
/trust <user> paired 设置标准信任级别
/trust list 列出所有信任级别import { createPairingService } from 'clodds/pairing';
const pairing = createPairingService({
// Code settings
codeLength: 8,
codeExpiryMinutes: 60,
maxPendingPerChannel: 3,
// Auto-approve settings
autoApproveLocal: true, // Auto-approve localhost
autoApproveTailscale: true, // Auto-approve Tailscale IPs
autoApproveOwners: true, // Owners auto-approve their requests
// Storage
storage: 'sqlite',
dbPath: './pairing.db',
});import { createPairingService } from 'clodds/pairing';
const pairing = createPairingService({
// 验证码设置
codeLength: 8,
codeExpiryMinutes: 60,
maxPendingPerChannel: 3,
// 自动批准设置
autoApproveLocal: true, // 自动批准本地主机请求
autoApproveTailscale: true, // 自动批准Tailscale IP请求
autoApproveOwners: true, // 所有者自动批准自身的其他渠道请求
// 存储设置
storage: 'sqlite',
dbPath: './pairing.db',
});// User requests pairing
const request = await pairing.createPairingRequest({
channelId: 'telegram-123',
userId: 'telegram-user-456',
username: 'johndoe',
displayName: 'John Doe',
});
console.log(`Pairing code: ${request.code}`);
console.log(`Expires: ${request.expiresAt}`);
console.log(`Share this code with an admin to get approved`);// 用户发起配对请求
const request = await pairing.createPairingRequest({
channelId: 'telegram-123',
userId: 'telegram-user-456',
username: 'johndoe',
displayName: 'John Doe',
});
console.log(`配对验证码:${request.code}`);
console.log(`过期时间:${request.expiresAt}`);
console.log(`请将此验证码分享给管理员以完成批准`);// Check if code is valid
const valid = await pairing.validateCode({
code: 'ABC123XY',
});
if (valid) {
console.log(`Valid code for user: ${valid.username}`);
console.log(`Channel: ${valid.channelId}`);
}// 检查验证码是否有效
const valid = await pairing.validateCode({
code: 'ABC123XY',
});
if (valid) {
console.log(`验证码有效,所属用户:${valid.username}`);
console.log(`渠道ID:${valid.channelId}`);
}// Admin approves pairing
await pairing.approveRequest({
code: 'ABC123XY',
approvedBy: 'admin-user-id',
trustLevel: 'paired',
});// 管理员批准配对请求
await pairing.approveRequest({
code: 'ABC123XY',
approvedBy: 'admin-user-id',
trustLevel: 'paired',
});// Admin rejects pairing
await pairing.rejectRequest({
code: 'ABC123XY',
rejectedBy: 'admin-user-id',
reason: 'Unknown user',
});// 管理员拒绝配对请求
await pairing.rejectRequest({
code: 'ABC123XY',
rejectedBy: 'admin-user-id',
reason: '未知用户',
});// Check if user is paired
const isPaired = await pairing.isPaired({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
if (isPaired) {
console.log('User is paired and can use Clodds');
}// 检查用户是否已配对
const isPaired = await pairing.isPaired({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
if (isPaired) {
console.log('用户已完成配对,可使用Clodds服务');
}const trust = await pairing.getTrustLevel({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
console.log(`Trust level: ${trust}`);
// 'owner' | 'paired' | 'stranger'
// Check specific permission
if (trust === 'owner') {
console.log('Full admin access');
} else if (trust === 'paired') {
console.log('Standard trading access');
} else {
console.log('No access - must pair first');
}const trust = await pairing.getTrustLevel({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
console.log(`信任级别:${trust}`);
// 'owner' | 'paired' | 'stranger'
// 检查特定权限
if (trust === 'owner') {
console.log('拥有完整管理员权限');
} else if (trust === 'paired') {
console.log('拥有标准交易权限');
} else {
console.log('无访问权限 - 需先完成配对');
}const pending = await pairing.listPendingRequests({
channelId: 'telegram-123', // Optional: filter by channel
});
for (const req of pending) {
console.log(`Code: ${req.code}`);
console.log(`User: ${req.username} (${req.displayName})`);
console.log(`Requested: ${req.createdAt}`);
console.log(`Expires: ${req.expiresAt}`);
}const pending = await pairing.listPendingRequests({
channelId: 'telegram-123', // 可选:按渠道筛选
});
for (const req of pending) {
console.log(`验证码:${req.code}`);
console.log(`用户:${req.username}(${req.displayName})`);
console.log(`请求时间:${req.createdAt}`);
console.log(`过期时间:${req.expiresAt}`);
}const users = await pairing.listPairedUsers({
channelId: 'telegram-123', // Optional: filter by channel
});
for (const user of users) {
console.log(`${user.username}: ${user.trustLevel}`);
console.log(` Paired: ${user.pairedAt}`);
console.log(` Approved by: ${user.approvedBy}`);
}const users = await pairing.listPairedUsers({
channelId: 'telegram-123', // 可选:按渠道筛选
});
for (const user of users) {
console.log(`${user.username}:${user.trustLevel}`);
console.log(` 配对时间:${user.pairedAt}`);
console.log(` 批准人:${user.approvedBy}`);
}const isOwner = await pairing.isOwner({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
if (isOwner) {
console.log('User has owner privileges');
}const isOwner = await pairing.isOwner({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});
if (isOwner) {
console.log('用户拥有所有者权限');
}// Remove user's pairing
await pairing.removePairing({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});// 移除用户的配对关系
await pairing.removePairing({
channelId: 'telegram-123',
userId: 'telegram-user-456',
});| Level | Access |
|---|---|
| owner | Full admin: approve users, manage settings, trading |
| paired | Standard: trading, portfolio, queries |
| stranger | None: must pair first |
| 级别 | 访问权限 |
|---|---|
| owner | 完整管理员:批准用户、管理设置、交易权限 |
| paired | 标准权限:交易、投资组合、查询功能 |
| stranger | 无权限:需先完成配对 |
ABC234XYABC234XY| Condition | Behavior |
|---|---|
| Localhost | Auto-approve with owner trust |
| Tailscale IP | Auto-approve with owner trust |
| Owner request | Auto-approve their other channels |
| 条件 | 行为 |
|---|---|
| 本地主机 | 自动批准并授予所有者信任级别 |
| Tailscale IP | 自动批准并授予所有者信任级别 |
| 所有者发起的请求 | 自动批准其其他渠道的配对请求 |
| Feature | Description |
|---|---|
| Code expiry | Codes expire after 1 hour |
| Rate limiting | Max 3 pending per channel |
| Unambiguous codes | No confusable characters |
| Audit trail | Who approved/rejected when |
| 特性 | 描述 |
|---|---|
| 验证码过期 | 验证码1小时后过期 |
| 请求频率限制 | 每个渠道最多允许3个待处理请求 |
| 无歧义验证码 | 不使用易混淆字符 |
| 审计追踪 | 记录谁在何时批准/拒绝了请求 |
undefinedundefined
---
---