mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-31 20:35:31 +02:00
fixed end executing, logging, added param
This commit is contained in:
parent
2af1fc16ee
commit
cee25212aa
3 changed files with 15 additions and 11 deletions
|
@ -62,7 +62,7 @@ export class Coder {
|
||||||
}
|
}
|
||||||
|
|
||||||
santitizeCode(code) {
|
santitizeCode(code) {
|
||||||
const remove_strs = ['javascript', 'js']
|
const remove_strs = ['Javascript', 'javascript', 'js']
|
||||||
for (let r of remove_strs) {
|
for (let r of remove_strs) {
|
||||||
if (code.startsWith(r)) {
|
if (code.startsWith(r)) {
|
||||||
code = code.slice(r.length);
|
code = code.slice(r.length);
|
||||||
|
@ -97,6 +97,8 @@ export class Coder {
|
||||||
let code_return = null;
|
let code_return = null;
|
||||||
let failures = 0;
|
let failures = 0;
|
||||||
for (let i=0; i<5; i++) {
|
for (let i=0; i<5; i++) {
|
||||||
|
if (this.agent.bot.interrupt_code)
|
||||||
|
return;
|
||||||
console.log(messages)
|
console.log(messages)
|
||||||
let res = await sendRequest(messages, system_message);
|
let res = await sendRequest(messages, system_message);
|
||||||
console.log('Code generation response:', res)
|
console.log('Code generation response:', res)
|
||||||
|
@ -142,11 +144,7 @@ export class Coder {
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content: code_return.message
|
content: code_return.message
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.agent.bot.interrupt_code)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +171,10 @@ export class Coder {
|
||||||
this.clear();
|
this.clear();
|
||||||
return {success:true, message: output, interrupted, timedout};
|
return {success:true, message: output, interrupted, timedout};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Code execution triggered catch: " + err);
|
this.executing = false;
|
||||||
clearTimeout(TIMEOUT);
|
clearTimeout(TIMEOUT);
|
||||||
|
|
||||||
|
console.error("Code execution triggered catch: " + err);
|
||||||
await this.stop();
|
await this.stop();
|
||||||
|
|
||||||
let message = this.formatOutput(this.agent.bot) + '!!Code threw exception!! Error: ' + err;
|
let message = this.formatOutput(this.agent.bot) + '!!Code threw exception!! Error: ' + err;
|
||||||
|
|
|
@ -64,10 +64,14 @@ export const actionsList = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '!givePlayer',
|
name: '!givePlayer',
|
||||||
description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe")',
|
description: 'Give the specified item to the given player. Ex: !givePlayer("steve", "stone_pickaxe", 1)',
|
||||||
params: { 'player_name': '(string) The name of the player to give the item to.', 'item_name': '(string) The name of the item to give.' },
|
params: {
|
||||||
perform: wrapExecution(async (agent, player_name, item_name) => {
|
'player_name': '(string) The name of the player to give the item to.',
|
||||||
await skills.giveToPlayer(agent.bot, item_name, player_name);
|
'item_name': '(string) The name of the item to give.' ,
|
||||||
|
'num': '(number) The number of items to give.'
|
||||||
|
},
|
||||||
|
perform: wrapExecution(async (agent, player_name, item_name, num) => {
|
||||||
|
await skills.giveToPlayer(agent.bot, item_name, player_name, num);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@ import pf from 'mineflayer-pathfinder';
|
||||||
import Vec3 from 'vec3';
|
import Vec3 from 'vec3';
|
||||||
|
|
||||||
|
|
||||||
function log(bot, message, chat=false) {
|
export function log(bot, message, chat=false) {
|
||||||
bot.output += message + '\n';
|
bot.output += message + '\n';
|
||||||
if (chat)
|
if (chat)
|
||||||
bot.chat(message);
|
bot.chat(message);
|
||||||
|
|
Loading…
Add table
Reference in a new issue