-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatScore.ts
68 lines (51 loc) · 1.45 KB
/
chatScore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
type ChatGPTQuestion = {
question: string;
answer: string;
};
export class BotStorage {
private static instance: BotStorage;
score: number = 0;
scoreQueue: number[] = [];
latestImageURL: string = "";
tasks:{[x: string]: string} = {}
latestQuestion: ChatGPTQuestion = { question: "", answer: "" };
latestMessage: string = "";
regexp = /fla[0-9]{0,4}\w/gi;
overlayBackground = "#000000";
private constructor() {}
public static getInstance(): BotStorage {
if (!BotStorage.instance) {
BotStorage.instance = new BotStorage();
}
return BotStorage.instance;
}
async calculateChatScore(new_score: number) {
if (this.scoreQueue.length > 6) {
this.scoreQueue.shift();
}
this.scoreQueue.push(new_score);
let scoreSum = 0;
this.scoreQueue.forEach((a) => (scoreSum += a));
this.score = scoreSum / this.scoreQueue.length;
}
public setLatestMessage(message: string) {
this.latestMessage = message;
}
public setOverlayBackground(background: string) {
this.overlayBackground = background;
}
public setLatestImageURL(url: string) {
this.latestImageURL = url;
}
public setLatestQuestion(chatGPTQuestion: ChatGPTQuestion) {
this.latestQuestion = chatGPTQuestion;
}
public setUserTask(user: string, task: string) {
this.tasks[user] = task;
}
public removeUserTask(user: string) {
const task = this.tasks[user];
delete this.tasks[user];
return task;
}
}