load history before chatting

This commit is contained in:
Maximus 2023-12-26 14:42:45 -07:00
parent 1a854fe0d5
commit a056575073

View file

@ -12,24 +12,36 @@ export class Agent {
this.name = name;
this.bot = initBot(name);
this.history = new History(this);
this.history.loadExamples();
this.coder = new Coder(this);
this.history.load(profile);
this.events = new Events(this, this.history.events)
this.bot.on('login', () => {
this.bot.on('login', async () => {
this.bot.chat('Hello world! I am ' + this.name);
console.log(`${this.name} logged in.`);
const ignore_messages = [
"Set own game mode to",
"Set the time to",
"Set the difficulty to",
"Teleported ",
"Set the weather to",
"Gamerule "
];
this.bot.on('chat', (username, message) => {
if (username === this.name) return;
if (ignore_messages.some((m) => message.startsWith(m))) return;
console.log('received message from', username, ':', message);
this.handleMessage(username, message);
});
await this.history.loadExamples();
if (init_message) {
this.handleMessage('system', init_message);
} else {
@ -39,6 +51,7 @@ export class Agent {
}
async handleMessage(source, message) {
if (!!source && !!message)
await this.history.add(source, message);
for (let i=0; i<5; i++) {