Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 88e343c

Browse files
committed
fix: id instead of token
1 parent 43fe2cc commit 88e343c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/modules/gpt-api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ async function chat(message) {
3636
if (token.error) {
3737
return token.error;
3838
}
39-
await addMessage(token.token);
39+
await addMessage(token.id);
4040
try {
4141
var response = await token.client.sendMessage(message);
42-
await removeMessage(token.token);
42+
await removeMessage(token.id);
4343
return response;
4444
} catch (err) {
4545
console.log(err);
46-
await removeMessage(token.token);
46+
await removeMessage(token.id);
4747
return `Something wrong happened, please wait we are solving this issue [dsc.gg/turing](https://dsc.gg/turing)`;
4848
}
4949
}

src/modules/loadbalancer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ async function useToken() {
5757
function getRndInteger(min, max) {
5858
return Math.floor(Math.random() * (max - min + 1)) + min;
5959
}
60-
async function addMessage(token) {
60+
async function addMessage(id) {
6161
let { data: accounts, error } = await supabase
6262
.from("accounts")
6363
.select("*")
64-
.eq("sessionToken", token);
64+
.eq("id", id);
6565
var tokenObj = accounts[0];
6666
if (tokenObj) {
6767
if (tokenObj.totalMessages >= 30) {
@@ -72,8 +72,8 @@ async function addMessage(token) {
7272
totalMessages: tokenObj.totalMessages + 1,
7373
lastUse: Date.now(),
7474
})
75-
.eq("sessionToken", token);
76-
var index = clients.findIndex((x) => x.token == tokenObj.sessionToken);
75+
.eq("id", id);
76+
var index = clients.findIndex((x) => x.id == tokenObj.id);
7777
clients.splice(index, 1); // 2nd parameter means remove one item only
7878
} else {
7979
const { data, error } = await supabase
@@ -82,21 +82,21 @@ async function addMessage(token) {
8282
messages: tokenObj.messages + 1,
8383
totalMessages: tokenObj.totalMessages + 1,
8484
})
85-
.eq("sessionToken", token);
85+
.eq("id", id);
8686
}
8787
}
8888
}
89-
async function removeMessage(token) {
89+
async function removeMessage(id) {
9090
let { data: accounts, error } = await supabase
9191
.from("accounts")
9292
.select("*")
93-
.eq("sessionToken", token);
93+
.eq("id", id);
9494
var tokenObj = accounts[0];
9595
if (tokenObj) {
9696
const { data, error } = await supabase
9797
.from("accounts")
9898
.update({ messages: tokenObj.messages - 1 })
99-
.eq("sessionToken", token);
99+
.eq("id", id);
100100
}
101101
}
102102

0 commit comments

Comments
 (0)