2024-01-25 13:25:36 -08:00
import * as skills from '../library/skills.js' ;
2024-01-30 16:43:30 -06:00
import settings from '../../settings.js' ;
2024-01-09 22:50:22 -06:00
2024-02-02 15:34:17 -06:00
function wrapExecution ( func , timeout = - 1 , resume _name = null ) {
2024-01-11 15:59:52 -06:00
return async function ( agent , ... args ) {
2024-01-26 12:11:32 -08:00
let code _return ;
2024-02-02 15:34:17 -06:00
if ( resume _name != null ) {
code _return = await agent . coder . executeResume ( async ( ) => {
2024-01-26 12:11:32 -08:00
await func ( agent , ... args ) ;
2024-02-02 15:34:17 -06:00
} , resume _name , timeout ) ;
2024-01-26 12:11:32 -08:00
} else {
code _return = await agent . coder . execute ( async ( ) => {
await func ( agent , ... args ) ;
} , timeout ) ;
}
2024-01-15 12:04:18 -06:00
if ( code _return . interrupted && ! code _return . timedout )
return ;
return code _return . message ;
2024-01-09 22:50:22 -06:00
}
}
export const actionsList = [
{
2024-01-11 15:59:52 -06:00
name : '!newAction' ,
description : 'Perform new and unknown custom behaviors that are not available as a command by writing code.' ,
2024-01-09 22:50:22 -06:00
perform : async function ( agent ) {
2024-01-30 16:43:30 -06:00
if ( ! settings . allow _insecure _coding )
2024-02-20 19:09:56 -06:00
return 'newAction Failed! Agent is not allowed to write code. Notify the user.' ;
2024-02-16 11:57:48 -06:00
return await agent . coder . generateCode ( agent . history ) ;
2024-01-09 22:50:22 -06:00
}
} ,
{
name : '!stop' ,
description : 'Force stop all actions and commands that are currently executing.' ,
perform : async function ( agent ) {
await agent . coder . stop ( ) ;
2024-01-23 18:01:38 -06:00
agent . coder . clear ( ) ;
2024-02-05 13:21:32 -06:00
agent . coder . cancelResume ( ) ;
2024-01-09 22:50:22 -06:00
return 'Agent stopped.' ;
}
} ,
2024-01-27 19:16:54 -06:00
{
name : '!restart' ,
description : 'Restart the agent process.' ,
perform : async function ( agent ) {
process . exit ( 1 ) ;
}
} ,
{
2024-02-16 11:57:48 -06:00
name : '!clearChat' ,
2024-01-27 19:16:54 -06:00
description : 'Clear the chat history.' ,
perform : async function ( agent ) {
agent . history . clear ( ) ;
return agent . name + "'s chat history was cleared, starting new conversation from scratch." ;
}
} ,
2024-01-23 18:01:38 -06:00
{
name : '!setMode' ,
description : 'Set a mode to on or off. A mode is an automatic behavior that constantly checks and responds to the environment. Ex: !setMode("hunting", true)' ,
params : {
'mode_name' : '(string) The name of the mode to enable.' ,
'on' : '(bool) Whether to enable or disable the mode.'
} ,
perform : async function ( agent , mode _name , on ) {
const modes = agent . bot . modes ;
if ( ! modes . exists ( mode _name ) )
2024-01-25 13:25:36 -08:00
return ` Mode ${ mode _name } does not exist. ` + modes . getStr ( ) ;
2024-01-23 18:01:38 -06:00
if ( modes . isOn ( mode _name ) === on )
return ` Mode ${ mode _name } is already ${ on ? 'on' : 'off' } . ` ;
modes . setOn ( mode _name , on ) ;
return ` Mode ${ mode _name } is now ${ on ? 'on' : 'off' } . ` ;
}
} ,
2024-01-11 15:59:52 -06:00
{
name : '!goToPlayer' ,
2024-02-05 19:08:08 -06:00
description : 'Go to the given player. Ex: !goToPlayer("steve", 3)' ,
params : {
'player_name' : '(string) The name of the player to go to.' ,
'closeness' : '(number) How close to get to the player.'
} ,
perform : wrapExecution ( async ( agent , player _name , closeness ) => {
return await skills . goToPlayer ( agent . bot , player _name , closeness ) ;
2024-01-11 15:59:52 -06:00
} )
} ,
2024-01-11 18:04:59 -06:00
{
name : '!followPlayer' ,
2024-02-16 11:57:48 -06:00
description : 'Endlessly follow the given player. Will defend that player if self_defense mode is on. Ex: !followPlayer("stevie", 4)' ,
2024-02-05 19:08:08 -06:00
params : {
'player_name' : '(string) The name of the player to follow.' ,
'follow_dist' : '(number) The distance to follow from.'
} ,
perform : wrapExecution ( async ( agent , player _name , follow _dist ) => {
await skills . followPlayer ( agent . bot , player _name , follow _dist ) ;
2024-01-26 12:11:32 -08:00
} , - 1 , 'followPlayer' )
2024-01-11 18:04:59 -06:00
} ,
2024-02-02 11:54:17 -06:00
{
name : '!moveAway' ,
description : 'Move away from the current location in any direction by a given distance. Ex: !moveAway(2)' ,
params : { 'distance' : '(number) The distance to move away.' } ,
perform : wrapExecution ( async ( agent , distance ) => {
await skills . moveAway ( agent . bot , distance ) ;
} )
} ,
2024-01-25 13:25:36 -08:00
{
name : '!givePlayer' ,
2024-01-26 15:05:36 -06:00
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.' ,
'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 ) ;
2024-01-25 13:25:36 -08:00
} )
} ,
2024-01-11 18:04:59 -06:00
{
name : '!collectBlocks' ,
description : 'Collect the nearest blocks of a given type.' ,
params : {
'type' : '(string) The block type to collect. Ex: !collectBlocks("stone", 10)' ,
'num' : '(number) The number of blocks to collect.'
} ,
perform : wrapExecution ( async ( agent , type , num ) => {
await skills . collectBlock ( agent . bot , type , num ) ;
2024-01-23 18:01:38 -06:00
} , 10 ) // 10 minute timeout
2024-01-11 18:04:59 -06:00
} ,
2024-01-26 12:11:32 -08:00
{
name : '!collectAllBlocks' ,
description : 'Collect all the nearest blocks of a given type until told to stop.' ,
params : {
'type' : '(string) The block type to collect. Ex: !collectAllBlocks("stone")'
} ,
perform : wrapExecution ( async ( agent , type ) => {
2024-02-05 13:21:32 -06:00
let success = await skills . collectBlock ( agent . bot , type , 1 ) ;
if ( ! success )
agent . coder . cancelResume ( ) ;
2024-01-26 12:11:32 -08:00
} , 10 , 'collectAllBlocks' ) // 10 minute timeout
} ,
2024-01-16 15:53:27 -06:00
{
name : '!craftRecipe' ,
description : 'Craft the given recipe a given number of times. Ex: I will craft 8 sticks !craftRecipe("stick", 2)' ,
params : {
'recipe_name' : '(string) The name of the output item to craft.' ,
'num' : '(number) The number of times to craft the recipe. This is NOT the number of output items, as it may craft many more items depending on the recipe.'
} ,
perform : wrapExecution ( async ( agent , recipe _name , num ) => {
for ( let i = 0 ; i < num ; i ++ ) {
await skills . craftRecipe ( agent . bot , recipe _name ) ;
}
} )
} ,
{
name : '!placeHere' ,
description : 'Place a given block in the current location. Do NOT use to build structures, only use for single blocks/torches. Ex: !placeBlockHere("crafting_table")' ,
params : { 'type' : '(string) The block type to place.' } ,
perform : wrapExecution ( async ( agent , type ) => {
let pos = agent . bot . entity . position ;
await skills . placeBlock ( agent . bot , type , pos . x , pos . y , pos . z ) ;
} )
} ,
2024-01-11 18:04:59 -06:00
{
name : '!attack' ,
description : 'Attack and kill the nearest entity of a given type.' ,
params : { 'type' : '(string) The type of entity to attack.' } ,
perform : wrapExecution ( async ( agent , type ) => {
2024-01-24 17:24:52 -06:00
await skills . attackNearest ( agent . bot , type , true ) ;
2024-01-11 18:04:59 -06:00
} )
2024-01-13 12:11:04 -06:00
} ,
2024-01-16 15:53:27 -06:00
{
name : '!goToBed' ,
description : 'Go to the nearest bed and sleep.' ,
perform : wrapExecution ( async ( agent ) => {
await skills . goToBed ( agent . bot ) ;
} )
2024-02-02 11:54:17 -06:00
} ,
{
name : '!stay' ,
description : 'Stay in the current location no matter what. Pauses all modes.' ,
perform : wrapExecution ( async ( agent ) => {
await skills . stay ( agent . bot ) ;
} )
2024-01-11 18:04:59 -06:00
}
2024-01-09 22:50:22 -06:00
] ;