new-message-storage #1
18
src/bot.ts
18
src/bot.ts
|
@ -140,7 +140,11 @@ client.connect().then(async () => {
|
||||||
content: `[md]${contentOf(response)}[/md]`,
|
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);
|
console.log("Now our conversation is", session);
|
||||||
} else {
|
} else {
|
||||||
const username = await getUsername(HOST, message.author!);
|
const username = await getUsername(HOST, message.author!);
|
||||||
|
@ -171,7 +175,11 @@ client.connect().then(async () => {
|
||||||
content: `[md]${contentOf(response)}[/md]`,
|
content: `[md]${contentOf(response)}[/md]`,
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
|
fs.writeFileSync(
|
||||||
|
"./messages.json",
|
||||||
|
JSON.stringify(session.data),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Failed", err);
|
console.log("Failed", err);
|
||||||
|
@ -210,7 +218,11 @@ client.connect().then(async () => {
|
||||||
content: `[md]${contentOf(response)}[/md]`,
|
content: `[md]${contentOf(response)}[/md]`,
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync("./messages.json", JSON.stringify(session), "utf8");
|
fs.writeFileSync(
|
||||||
|
"./messages.json",
|
||||||
|
JSON.stringify(session.data),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Failed", err);
|
console.log("Failed", err);
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ export function checkFile(
|
||||||
|
|
||||||
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
|
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (final.at(0).role) {
|
if (final.at(0).role) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
@ -60,6 +61,7 @@ export function checkFile(
|
||||||
|
|
||||||
final = [];
|
final = [];
|
||||||
}
|
}
|
||||||
|
} catch {}
|
||||||
} else {
|
} else {
|
||||||
fs.createWriteStream(file);
|
fs.createWriteStream(file);
|
||||||
final = [];
|
final = [];
|
||||||
|
|
Loading…
Reference in a new issue