new-message-storage #1

Merged
powermaker450 merged 4 commits from new-message-storage into main 2024-07-25 00:37:59 -04:00
2 changed files with 27 additions and 13 deletions
Showing only changes of commit b257da540e - Show all commits

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,17 +49,19 @@ export function checkFile(
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
// @ts-ignore
if (final.at(0).role) {
console.warn(
chalk.yellow(
"Your persistent storage uses the old data structure for persistent messages. These messages will be moved to a backup file and the existing file will be overwritten.",
),
);
fs.writeFileSync(`${file}.bak`, data);
try {
// @ts-ignore
if (final.at(0).role) {
console.warn(
chalk.yellow(
"Your persistent storage uses the old data structure for persistent messages. These messages will be moved to a backup file and the existing file will be overwritten.",
),
);
fs.writeFileSync(`${file}.bak`, data);
final = [];
}
final = [];
}
} catch {}
} else {
fs.createWriteStream(file);
final = [];