renaming directories and moving some code
This commit is contained in:
55
commands/system/view-session-history.js
Normal file
55
commands/system/view-session-history.js
Normal file
@ -0,0 +1,55 @@
|
||||
const axios = require('axios');
|
||||
const jsonfile = require('jsonfile');
|
||||
let session2;
|
||||
|
||||
function parseQuestionsAndAnswers(jsonStr) {
|
||||
const obj = JSON.parse(jsonStr);
|
||||
const questions = obj.questions;
|
||||
const answers = questions.map(q => q.answer);
|
||||
return { questions, answers };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: "view-session-history",
|
||||
description: "View your current conversation.",
|
||||
run: async (client, interaction) => {
|
||||
const file = './cache/' + interaction.user.id;
|
||||
|
||||
await jsonfile.readFile(file, async function (err, session) {
|
||||
|
||||
if (err) return interaction.editReply('Please create a session using /create-session.');
|
||||
|
||||
session2 = session.id;
|
||||
|
||||
if (!session2) {
|
||||
console.log("No Session!");
|
||||
isProcessing = false;
|
||||
return;
|
||||
}
|
||||
const headers = {
|
||||
'authority': process.env.PUBLIC_URL,
|
||||
'accept': 'text/event-stream',
|
||||
};
|
||||
const response = await axios.get(`http://${process.env.INTERNAL_IP}:8008/api/chat/` + session2, {
|
||||
headers,
|
||||
auth: {
|
||||
username: process.env.USERNAME,
|
||||
password: process.env.PASS
|
||||
}
|
||||
});
|
||||
|
||||
console.log(response.data)
|
||||
|
||||
if (!response.data.questions) return interaction.editReply("You have no history in this session yet :) ");
|
||||
|
||||
const result = parseQuestionsAndAnswers(JSON.stringify(response.data));
|
||||
let pairsString = "";
|
||||
for (const question of result.questions) {
|
||||
pairsString += `***Question:*** ${question.question}\n***Answer:*** ${question.answer}\n`;
|
||||
}
|
||||
interaction.editReply(pairsString);
|
||||
})
|
||||
if (err) console.error("woo" + err)
|
||||
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user