OpenAI Plus剩余额度查询 (#161)

This commit is contained in:
夏叶 2023-02-17 19:15:06 +08:00 committed by GitHub
parent dd805136e0
commit 37f75a64fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 22 deletions

View file

@ -90,6 +90,11 @@ export class chatgpt extends plugin {
reg: '#移出(chat)?队列首位',
fnc: 'removeQueueFirst',
permission: 'master'
},
{
reg: '#OpenAI(剩余)?(余额|额度)',
fnc: 'totalAvailable',
permission: 'master'
}
]
@ -524,6 +529,26 @@ export class chatgpt extends plugin {
}
}
async totalAvailable(e) {
// 查询OpenAI Plus剩余试用额度
fetch('https://api.openai.com/dashboard/billing/credit_grants', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + Config.apiKey,
}
})
.then(response => response.json())
.then(data => {
if (data.error) {
console.log(data.error)
return false
} else {
this.reply('总额度:$' + data.total_granted + '\n已使用额度$' + data.total_used + '\n当前剩余额度$' + data.total_available)
}
})
}
/**
* #chatgpt
* @param prompt 问题

View file

@ -71,6 +71,11 @@ let helpData = [
title: '#chatgpt设置必应token',
desc: '设置ChatGPT或bing的Token'
},
{
icon: 'help',
title: '#OpenAI剩余额度',
desc: '查询OpenAI Plus剩余试用额度'
},
{
icon: 'help',
title: '#chatgpt模式帮助',