forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote.ts
69 lines (67 loc) · 1.8 KB
/
vote.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
69
import {
SlashCommandBuilder,
ActionRowBuilder,
ButtonStyle,
ButtonBuilder,
} from "discord.js";
import { createInferenceClient } from "../modules/inference/client.js";
import redis from "../modules/redis.js";
export default {
data: {
customId: "vote",
description: "Vote buttons for the assistant messages.",
},
async execute(interaction, client, messageId, voteType) {
let chatId = await redis.get(`chat_${interaction.user.id}`);
if (!chatId)
return interaction.reply({
content: "You don't have an active chat.",
ephemeral: true,
});
await interaction.deferUpdate();
var row;
const OA = await createInferenceClient(
interaction.user.username,
interaction.user.id
);
let score = 0;
if (voteType == "up") {
score = 1;
row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setStyle(ButtonStyle.Primary)
.setLabel(`👍`)
.setDisabled(true)
.setCustomId(`vote__up`),
new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setLabel(`👎`)
.setDisabled(true)
.setCustomId(`vote__down`)
);
}
if (voteType == "down") {
row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setLabel(`👍`)
.setDisabled(true)
.setCustomId(`vote__up`),
new ButtonBuilder()
.setStyle(ButtonStyle.Primary)
.setLabel(`👎`)
.setDisabled(true)
.setCustomId(`vote__down`)
);
}
let vote = await OA.vote({
chat_id: chatId,
message_id: messageId,
score: score,
});
console.log(vote);
await interaction.editReply({
components: [row],
});
},
};