From 624e1f6e1a542655afeeb19fdda17e4ea1666353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=8F=B6?= Date: Sun, 19 Feb 2023 00:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0OpenAI=20API=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E7=9A=84=E5=88=B0=E6=9C=9F=E6=97=A5=E6=9C=9F=EF=BC=8C?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=B0=8F=E6=95=B0=E7=82=B9=20(#168)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 13 +++++++++---- apps/help.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index 5ae128b..628917f 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -79,7 +79,7 @@ export class chatgpt extends plugin { permission: 'master' }, { - reg: '#OpenAI(剩余)?(余额|额度)', + reg: '#(OpenAI|openai)(剩余)?(余额|额度)', fnc: 'totalAvailable', permission: 'master' }, @@ -759,7 +759,7 @@ export class chatgpt extends plugin { this.reply('当前未配置OpenAI API key,请在插件配置文件config/index.js中配置。若使用免费的API3则无需关心计费。') return false } - // 查询OpenAI Plus剩余试用额度 + // 查询OpenAI API剩余试用额度 fetch('https://api.openai.com/dashboard/billing/credit_grants', { method: 'GET', headers: { @@ -770,10 +770,15 @@ export class chatgpt extends plugin { .then(response => response.json()) .then(data => { if (data.error) { - console.log(data.error) + // console.log(data.error) + this.reply('获取失败:' + data.error.code) return false } else { - this.reply('总额度:$' + data.total_granted + '\n已使用额度:$' + data.total_used + '\n当前剩余额度:$' + data.total_available) + let total_granted = data.total_granted.toFixed(2) + let total_used = data.total_used.toFixed(2) + let total_available = data.total_available.toFixed(2) + let expires_at = new Date(data.grants.data[0].expires_at * 1000).toLocaleDateString().replace(/\//g, '-') + this.reply('总额度:$' + total_granted + '\n已经使用额度:$' + total_used + '\n当前剩余额度:$' + total_available + '\n到期日期(UTC):' + expires_at) } }) } diff --git a/apps/help.js b/apps/help.js index 6c1222f..0baac30 100644 --- a/apps/help.js +++ b/apps/help.js @@ -89,7 +89,7 @@ let helpData = [ { icon: 'help', title: '#OpenAI剩余额度', - desc: '查询OpenAI Plus剩余试用额度' + desc: '查询OpenAI API剩余试用额度' }, { icon: 'help',