mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
添加OpenAI API额度的到期日期,格式化小数点 (#168)
This commit is contained in:
parent
a4f12eaf09
commit
624e1f6e1a
2 changed files with 10 additions and 5 deletions
13
apps/chat.js
13
apps/chat.js
|
|
@ -79,7 +79,7 @@ export class chatgpt extends plugin {
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: '#OpenAI(剩余)?(余额|额度)',
|
reg: '#(OpenAI|openai)(剩余)?(余额|额度)',
|
||||||
fnc: 'totalAvailable',
|
fnc: 'totalAvailable',
|
||||||
permission: 'master'
|
permission: 'master'
|
||||||
},
|
},
|
||||||
|
|
@ -759,7 +759,7 @@ export class chatgpt extends plugin {
|
||||||
this.reply('当前未配置OpenAI API key,请在插件配置文件config/index.js中配置。若使用免费的API3则无需关心计费。')
|
this.reply('当前未配置OpenAI API key,请在插件配置文件config/index.js中配置。若使用免费的API3则无需关心计费。')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 查询OpenAI Plus剩余试用额度
|
// 查询OpenAI API剩余试用额度
|
||||||
fetch('https://api.openai.com/dashboard/billing/credit_grants', {
|
fetch('https://api.openai.com/dashboard/billing/credit_grants', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -770,10 +770,15 @@ export class chatgpt extends plugin {
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
console.log(data.error)
|
// console.log(data.error)
|
||||||
|
this.reply('获取失败:' + data.error.code)
|
||||||
return false
|
return false
|
||||||
} else {
|
} 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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ let helpData = [
|
||||||
{
|
{
|
||||||
icon: 'help',
|
icon: 'help',
|
||||||
title: '#OpenAI剩余额度',
|
title: '#OpenAI剩余额度',
|
||||||
desc: '查询OpenAI Plus剩余试用额度'
|
desc: '查询OpenAI API剩余试用额度'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: 'help',
|
icon: 'help',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue