Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
inon-13 authored Oct 13, 2024
1 parent 02c6c90 commit 7ed7ea1
Show file tree
Hide file tree
Showing 13 changed files with 937 additions and 59 deletions.
106 changes: 103 additions & 3 deletions ChatLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const server = http.createServer(app);
const io = new Server(server);
const vec3 = require('vec3');
const reset = false;

// Create an interface for reading input from the console
const rl = readline.createInterface({
Expand All @@ -24,7 +25,58 @@
const scriptsPath = path.join(__dirname, 'scripts');
return fs.readdirSync(scriptsPath);
};

const getConfigFiles = () => {
const configsPath = path.join(__dirname, 'configs');
return fs.readdirSync(configsPath);
};

const getConfigContent = (fileName) => {
const filePath = path.join(__dirname, 'configs', fileName);
return fs.readFileSync(filePath, 'utf8');
};

// Function to edit a file in the /configs/ directory
const editConfigFile = (data) => {
const filePath = path.join(__dirname, 'configs', data.name);

// Check if data.code is already an object
const jsonData = typeof data.code === 'string' ? JSON.parse(data.code) : data.code;

const txtContent = Object.entries(jsonData)
.map(([key, value]) => `${key}: ${value}`)
.join('\n');

fs.writeFileSync(filePath, txtContent, 'utf8');
};


// Function to delete a file from the /configs/ directory
const deleteConfigFile = (fileName) => {
const filePath = path.join(__dirname, 'configs', fileName);
fs.unlinkSync(filePath);
};

// Function to create a new file in the /configs/ directory
const createConfigFile = (data) => {
const filePath = path.join(__dirname, 'configs', data.name);

// Check if data.code is already an object
const jsonData = typeof data.code === 'string' ? JSON.parse(data.code) : data.code;

const txtContent = Object.entries(jsonData)
.map(([key, value]) => `${key}: ${value}`)
.join('\n');

fs.writeFileSync(filePath, txtContent, 'utf8');
};

const renameConfigFile = (data) => {
const oldPath = path.join(__dirname, 'configs', data.oldName);
const newPath = path.join(__dirname, 'configs', data.newName);
fs.renameSync(oldPath, newPath);
}

const getScriptContent = (fileName) => {
const filePath = path.join(__dirname, 'scripts', fileName);
return fs.readFileSync(filePath, 'utf8');
Expand Down Expand Up @@ -87,6 +139,10 @@ const renameScriptFile = (data) => {

// Function to get bot settings from user input
const getBotSettingsFromUser = async () => {
if (reset == true) {
return config;
}
else {
const prefix = (await askQuestion('Enter a prefix for commands ("!!" if left empty): ') || '!!');
const serverIP = await askQuestion('Enter server IP: ');
const serverPort = (await askQuestion('Enter server port (25565 if left empty): ')) || '25565';
Expand Down Expand Up @@ -148,6 +204,7 @@ const renameScriptFile = (data) => {
prefix,
};
};
};
// Delay function
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));

Expand All @@ -162,9 +219,10 @@ const renameScriptFile = (data) => {
let usernames = []; // Initialize usernames array

if (configFileName) {
const configPath = path.join(__dirname, 'configs', configFileName);
const configPath = path.join(__dirname, 'configs', `${configFileName}.clc`);
if (fs.existsSync(configPath)) {
config = readConfigFile(configPath);
io.emit('config.selected', configPath)
console.log(config)

// Parse config data properly and set defaults
Expand Down Expand Up @@ -199,7 +257,7 @@ const renameScriptFile = (data) => {
};
io.emit('config', config);
} else {
console.log(chalk.red(`Config file "${configFileName}" not found in /configs folder.`));
console.log(chalk.red(`Config file "${configFileName.replace('.clc', '')}" not found in /configs folder.`));
return;
}
} else {
Expand Down Expand Up @@ -296,6 +354,7 @@ const renameScriptFile = (data) => {
}
break;


case 'br':
bot.dig(bot.blockAtCursor(7));
break;
Expand Down Expand Up @@ -672,6 +731,38 @@ const {
}
});

socket.on('config.set', (data) => {
config = data;
io.emit('config', config);
console.log(config)
});

socket.on('config.new', (data) => {
createConfigFile(data)
});

socket.on('config.rename', (data) => {
renameConfigFile(data)
});

socket.on('config.edit', (data) => {
editConfigFile(data)
});

socket.on('config.delete', (data) => {
deleteConfigFile(data)
});

socket.on('config.read', (data) => {
const configContent = readConfigFile(data)
socket.emit('config.send', configContent)
});

io.emit('config.list', getConfigFiles());
socket.on('config.get_list', () => {
socket.emit('config.list', getConfigFiles());
});

socket.on('script.new', (data) => {
createScriptFile(data)
});
Expand Down Expand Up @@ -752,6 +843,7 @@ const {

//actually fixed it now
// Listen for commands from trusted users in chat

bot.on('chat', (username, message) => {
if (message.startsWith(prefix) && trustedUsers.includes(username)) {
const command = message.slice(prefix.length).trim();
Expand Down Expand Up @@ -797,4 +889,12 @@ const {
};

// Start the bot
runBot().catch(console.error);
runBot().catch(console.error);
io.on('config.set', (configData) => {
bots.forEach(bot => bot.quit());
bots = [];
reset = true;
config = configData;

runBot().catch(console.error);
})
11 changes: 11 additions & 0 deletions configs/Example.clc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
serverIP: localhost
serverPort: 25565
version: 1.20.4
bot_amount: 1
useLogin: false
username: Bot
password: Password
useFiltering: true
whitelistedWords: word1, word2
trustedUsers: player1, player2
prefix: &&
76 changes: 28 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"express": "^4.21.1",
"fs": "^0.0.1-security",
"http": "^0.0.1-security",
"mineflayer": "^4.0.0",
"mineflayer": "^4.21.0",
"proxy-agent": "^6.4.0",
"readline": "^1.3.0",
"socket.io": "^4.8.0",
Expand Down
2 changes: 1 addition & 1 deletion public/bots/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h3>ChatLogger</h3>
<button class="tab-button" data-tab="">Console</button>
<button class="tab-button" data-tab="logs">Logs</button>
<button class="tab-button" data-tab="settings">Settings</button>
<button class="tab-button" data-tab="configs">Configs</button>
<button class="tab-button" data-tab="scripts">Scripts</button>
<button class="tab-button" data-tab="bots" id="tab-chosen">Bots</button>
<button class="tab-button" data-tab="info">Info</button>
Expand Down
Loading

0 comments on commit 7ed7ea1

Please sign in to comment.