mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-07-24 08:55:23 +02:00
cleaned up stuff
This commit is contained in:
parent
6b170e492f
commit
166c01c52b
5 changed files with 49 additions and 50 deletions
|
@ -7,18 +7,18 @@ export default
|
|||
|
||||
"profiles": [
|
||||
"./andy.json",
|
||||
|
||||
// add more profiles here, check ./profiles/ for more
|
||||
// more than 1 profile will require you to /msg each bot indivually
|
||||
],
|
||||
"load_memory": false, // load memory from previous session
|
||||
"init_message": "Say hello world and your name", // sends to all on spawn
|
||||
|
||||
"language": "en", // translate to/from this language. Supports these language names: https://cloud.google.com/translate/docs/languages
|
||||
|
||||
"allow_insecure_coding": false, // allows newAction command and model can write/run code on your computer. enable at own risk
|
||||
"code_timeout_mins": 10, // minutes code is allowed to run. -1 for no timeout
|
||||
|
||||
"max_commands": -1, // max number of commands to use in a response. -1 for no limit
|
||||
"verbose_commands": true, // show full command syntax
|
||||
"narrate_behavior": true, // chat simple automatic actions ('Picking up item!')
|
||||
"language": "spanish", // the bot will respond/message in this language. All language names are based on google translate's names.
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { NPCContoller } from './npc/controller.js';
|
|||
import { MemoryBank } from './memory_bank.js';
|
||||
import { SelfPrompter } from './self_prompter.js';
|
||||
import settings from '../../settings.js';
|
||||
import { handleTranslation, handleEnglishTranslation } from './translator.js';
|
||||
import { handleTranslation, handleEnglishTranslation } from '../utils/translator.js';
|
||||
|
||||
export class Agent {
|
||||
async start(profile_fp, load_mem=false, init_message=null) {
|
||||
|
@ -79,8 +79,8 @@ export class Agent {
|
|||
this.handleMessage('system', init_message, 2);
|
||||
}
|
||||
else {
|
||||
const translation = await handleTranslation("Hello world! I am");
|
||||
this.bot.chat(translation+" "+this.name);
|
||||
const translation = await handleTranslation("Hello world! I am "+this.name);
|
||||
this.bot.chat(translation);
|
||||
this.bot.emit('finished_executing');
|
||||
|
||||
}
|
||||
|
@ -90,12 +90,17 @@ export class Agent {
|
|||
}
|
||||
|
||||
|
||||
async cleanChat(message) {
|
||||
async cleanChat(message, translate_up_to=-1) {
|
||||
let to_translate = message;
|
||||
let remainging = '';
|
||||
if (translate_up_to != -1) {
|
||||
to_translate = to_translate.substring(0, translate_up_to);
|
||||
remainging = message.substring(translate_up_to);
|
||||
}
|
||||
message = (await handleTranslation(to_translate)).trim() + " " + remainging;
|
||||
// newlines are interpreted as separate chats, which triggers spam filters. replace them with spaces
|
||||
message = message.replaceAll('\n', ' ');
|
||||
const preferred_lang = settings.preferred_language;
|
||||
let translation = await handleTranslation(message);
|
||||
return this.bot.chat(translation);
|
||||
message = message.replaceAll('\n', ' ');
|
||||
return this.bot.chat(message);
|
||||
}
|
||||
|
||||
shutUp() {
|
||||
|
@ -165,10 +170,10 @@ export class Agent {
|
|||
this.self_prompter.handleUserPromptedCmd(self_prompt, isAction(command_name));
|
||||
|
||||
if (settings.verbose_commands) {
|
||||
this.cleanChat(res);
|
||||
this.cleanChat(res, res.indexOf(command_name));
|
||||
}
|
||||
else { // only output command name
|
||||
let pre_message = res.substring(0, res.indexOf(command_name)).trim();
|
||||
let pre_message = res.substring(0, res.indexOf(command_name)).trim();
|
||||
let chat_message = `*used ${command_name.substring(1)}*`;
|
||||
if (pre_message.length > 0)
|
||||
chat_message = `${pre_message} ${chat_message}`;
|
||||
|
|
|
@ -285,6 +285,5 @@ export const actionsList = [
|
|||
agent.bot.emit('idle'); // to trigger the goal
|
||||
return 'Set npc goal: ' + agent.npc.data.curr_goal.name;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
];
|
||||
|
|
|
@ -2,13 +2,10 @@ import * as skills from './library/skills.js';
|
|||
import * as world from './library/world.js';
|
||||
import * as mc from '../utils/mcdata.js';
|
||||
import settings from '../../settings.js'
|
||||
import { handleTranslation, handleEnglishTranslation } from './translator.js';
|
||||
|
||||
|
||||
import { handleTranslation } from '../utils/translator.js';
|
||||
|
||||
|
||||
async function say(agent, message) {
|
||||
const preferred_lang = settings.preferred_language;
|
||||
if (agent.shut_up || !settings.narrate_behavior) return;
|
||||
var translation = await handleTranslation(message);
|
||||
agent.bot.chat(translation);
|
||||
|
|
|
@ -1,32 +1,30 @@
|
|||
import translate from 'google-translate-api-x';
|
||||
import settings from '../../settings.js';
|
||||
|
||||
|
||||
const preferred_lang = settings.language;
|
||||
|
||||
|
||||
export async function handleTranslation(message) {
|
||||
try {
|
||||
if (preferred_lang.toLowerCase() === 'en' || preferred_lang.toLowerCase() === 'english') {
|
||||
return message;
|
||||
} else {
|
||||
const lang = String(preferred_lang); // Ensure lang is a string
|
||||
|
||||
const translation = await translate(message, { to: lang });
|
||||
return translation.text || message; // Ensure translation.text is a string
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error translating message:', error);
|
||||
return message; // Fallback to the original message if translation fails
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleEnglishTranslation(message) {
|
||||
try {
|
||||
const translation = await translate(message, { to: 'english' });
|
||||
return translation.text || message; // Ensures translation.text is a string
|
||||
} catch (error) {
|
||||
console.error('Error translating message:', error);
|
||||
return message; // Fallback to the original message if translation fails
|
||||
}
|
||||
}
|
||||
import translate from 'google-translate-api-x';
|
||||
import settings from '../../settings.js';
|
||||
|
||||
const preferred_lang = settings.language;
|
||||
|
||||
export async function handleTranslation(message) {
|
||||
try {
|
||||
if (preferred_lang.toLowerCase() === 'en' || preferred_lang.toLowerCase() === 'english') {
|
||||
return message;
|
||||
} else {
|
||||
const lang = String(preferred_lang);
|
||||
|
||||
const translation = await translate(message, { to: lang });
|
||||
return translation.text || message;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error translating message:', error);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleEnglishTranslation(message) {
|
||||
try {
|
||||
const translation = await translate(message, { to: 'english' });
|
||||
return translation.text || message;
|
||||
} catch (error) {
|
||||
console.error('Error translating message:', error);
|
||||
return message;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue