MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / searchCurrency

Method searchCurrency

rate/rate.ts:501–556  ·  view source on GitHub ↗
(query: string)

Source from the content-addressed store, hash-verified

499 if (qLower === 'rm') {
500 const result = { id: 'myr', symbol: 'MYR', name: 'Malaysian Ringgit', type: 'fiat' as const };
501 this.currencyCache[qLower] = result;
502 return result;
503 }
504
505 if (this.currencyCache[qLower]) {
506 return this.currencyCache[qLower];
507 }
508
509 console.log(`[RatePlugin] 识别货币类型: ${query}`);
510
511 // 先检查内置法币映射
512 if (FIAT_CURRENCIES[qLower]) {
513 const fiatInfo = FIAT_CURRENCIES[qLower];
514 const result = {
515 id: qLower,
516 symbol: fiatInfo.symbol,
517 name: fiatInfo.name,
518 type: 'fiat' as const
519 };
520 this.currencyCache[qLower] = result;
521 console.log(`[RatePlugin] ${query} 从内置映射识别为法币`);
522 return result;
523 }
524
525 // 再检查内置加密货币映射
526 if (CRYPTO_CURRENCIES[qLower]) {
527 const cryptoInfo = CRYPTO_CURRENCIES[qLower];
528 const result = {
529 id: qLower,
530 symbol: cryptoInfo.symbol,
531 name: cryptoInfo.name,
532 type: 'crypto' as const
533 };
534 this.currencyCache[qLower] = result;
535 console.log(`[RatePlugin] ${query} 从内置映射识别为加密货币`);
536 return result;
537 }
538
539 // 回退到动态检查
540 if (await this.isFiat(qLower)) {
541 console.log(`[RatePlugin] ${query} 动态识别为法币`);
542 const result = { id: qLower, symbol: query.toUpperCase(), name: query.toUpperCase(), type: 'fiat' as const };
543 this.currencyCache[qLower] = result;
544 return result;
545 }
546
547 console.log(`[RatePlugin] ${query} 默认识别为加密货币`);
548 const result = { id: qLower, symbol: query.toUpperCase(), name: query.toUpperCase(), type: 'crypto' as const };
549 this.currencyCache[qLower] = result;
550 return result;
551 }
552
553 private formatPrice(value: number): string {
554 if (value >= 1) {
555 return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
556 } else if (value >= 0.01) {
557 return value.toFixed(4);
558 } else if (value >= 0.0001) {

Callers 1

handleRateMethod · 0.95

Calls 1

isFiatMethod · 0.95

Tested by

no test coverage detected