Fix incorrect writing of messages to storage

This commit is contained in:
powermaker450 2024-07-23 18:10:02 -04:00
parent d8e3b36d64
commit b257da540e
2 changed files with 27 additions and 13 deletions

View file

@ -140,7 +140,11 @@ client.connect().then(async () => {
content: `[md]${contentOf(response)}[/md]`,
});
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
fs.writeFileSync(
"./messages.json",
JSON.stringify(session.data),
"utf8",
);
console.log("Now our conversation is", session);
} else {
const username = await getUsername(HOST, message.author!);
@ -171,7 +175,11 @@ client.connect().then(async () => {
content: `[md]${contentOf(response)}[/md]`,
});
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
fs.writeFileSync(
"./messages.json",
JSON.stringify(session.data),
"utf8",
);
}
} catch (err) {
console.log("Failed", err);
@ -210,7 +218,11 @@ client.connect().then(async () => {
content: `[md]${contentOf(response)}[/md]`,
});
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
fs.writeFileSync(
"./messages.json",
JSON.stringify(session.data),
"utf8",
);
} catch (err) {
console.log("Failed", err);

View file

@ -49,6 +49,7 @@ export function checkFile(
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
try {
// @ts-ignore
if (final.at(0).role) {
console.warn(
@ -60,6 +61,7 @@ export function checkFile(
final = [];
}
} catch {}
} else {
fs.createWriteStream(file);
final = [];