Compare commits
	
		
			2 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 400995a311 | |||
| 3442d09f0b | 
| @ -1,22 +1,23 @@ | ||||
| 'use strict'; | ||||
| 'use strict';																			//enables Javascript's strict mode...enforces stricter error handling for cleaner code | ||||
|  | ||||
|  | ||||
| const {sleep} = require('../utils'); | ||||
| const {sleep} = require('../utils');													//require() enables other files to be loaded in. (..) goes up one folder in the filepath | ||||
| const conf = require('../conf'); | ||||
| const {CJbot} = require('../model/minecraft'); | ||||
| const {CJbot} = require('../model/minecraft');											 | ||||
| const inventoryViewer = require('mineflayer-web-inventory'); | ||||
|  | ||||
| const commands = require('./commands'); | ||||
| const {onJoin} = require('./player_list') | ||||
|  | ||||
| for(let name in conf.mc.bots){ | ||||
| 	if(CJbot.bots[name]) continue; | ||||
| 	let bot = new CJbot({name, host: conf.mc.host, ...conf.mc.bots[name]}); | ||||
| 	CJbot.bots[name] = bot; | ||||
| for(let name in conf.mc.bots){															//navigates to object in mc-bot-town/nodejs/conf/base.js | ||||
| 	if(CJbot.bots[name]) continue;														//Checks if the bot name in mc-bot-town/nodejs/conf/base.js is already present in the CJbot class (located in mc-bot-town-2/nodejs/model/minecraft.js). If it does, it skips over this if statement. | ||||
| 	let bot = new CJbot({name, host: conf.mc.host, ...conf.mc.bots[name]});				//If not,adds a new bot to the CJbot class, with data from conf.mc.host to provide the bot name, host (server), and other information. | ||||
| 																						//... expands an object into key:value pairs. conf.mc.bots[name] contains information regarding commands, autolog, etc. | ||||
| 	CJbot.bots[name] = bot;																//refers to line 29 in model/minecraft.js. In the CJbot class, an empty object named bots is created. This appends the bot name to this object, and is used to list all available bots. | ||||
|  | ||||
| 	for(let command of conf.mc.bots[name].commands || ['default']){ | ||||
| 		for(let [name, toAdd] of Object.entries(commands[command])){ | ||||
| 			bot.addCommand(name, toAdd) | ||||
| 	for(let command of conf.mc.bots[name].commands || ['default']){						//Navigates to the commands object in nodejs/conf/base.js and runs lines 19-21 on each command. If no command is found, a list of default commands are used. | ||||
| 		for(let [name, toAdd] of Object.entries(commands[command])){					//looks at each key:value pair in the commands array. Object.entries returns an array for each keyvalue pair | ||||
| 			bot.addCommand(name, toAdd)													//adss the command to the specified bot in the class CJbot. addCommand is a function defined in model/minecraft.js line 329. | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|  | ||||
							
								
								
									
										70
									
								
								ops/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								ops/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,70 @@ | ||||
| ## Useage | ||||
|  | ||||
| To get started, clone this repo move to the `nodejs` folder and run `npm install` | ||||
|  | ||||
| `npm install` will install the reuired packaged need to use this codebase. | ||||
|  | ||||
| Once you have the needed packages, you need to set up a local(setrets.js) conf file. For reference, | ||||
| a sample one can be found at `./ops/conf.js` Use this to file as a templet and place one with your | ||||
| configuration in `./nodejs/conf/secrets.js` | ||||
|  | ||||
| To execute the app, move to the `./nodejs` directory and run `node index.js` | ||||
|  | ||||
| ## Service | ||||
|  | ||||
| A sample systemD service file can be found at `./ops/mc-bot.service` | ||||
|  | ||||
| To use this file, copy it to `/etc/systemd/system`, change `/opt/theta42/mc-cj-bot/index.js` | ||||
| one the line `ExecStart=/usr/bin/env node /opt/theta42/mc-cj-bot/index.js` file to match where | ||||
| you have cloned the project. | ||||
|  | ||||
| Once you have the service file in place, run | ||||
|  | ||||
| ```bash | ||||
| systemctl start mc-bot.service | ||||
| ``` | ||||
|  | ||||
| Make sure this starts with out errors. Check the status of the service with: | ||||
|  | ||||
| ```bash | ||||
| systemctl status mc-bot.service | ||||
| ``` | ||||
|  | ||||
| Once you have a running service, run this command to activate it to start on boot | ||||
|  | ||||
| ```bash | ||||
| systemctl enable mc-bot.service | ||||
| ``` | ||||
|  | ||||
| ## File structure | ||||
|  | ||||
| ```bash | ||||
| . | ||||
| ├── nodejs      // Where the code for the project lives | ||||
| │   ├── index.js // Entry point for the project | ||||
| │   ├── package.json // Holds information about the project and what packages are required | ||||
| │   ├── package-lock.json // Hold what auto install packages(at version) are currently installed | ||||
| │   ├── conf // Configuration for the project | ||||
| │   │   ├── base.js // conf file to always be applied | ||||
| │   │   ├── index.js // code to build and return the conf object | ||||
| │   │   └── secrets.js // local settings file. This override all other conf files | ||||
| │   ├── controller // Logic to tie functionality together | ||||
| │   │   ├── mc-bot.js // Executes and manages the bot(s) | ||||
| │   │   └── player_list.js // Builds file for daily player list | ||||
| │   │   ├── commands // Commands players can run on the bot | ||||
| │   │   │   ├── default.js | ||||
| │   │   │   ├── fun.js | ||||
| │   │   │   ├── index.js | ||||
| │   │   │   ├── invite.js | ||||
| │   │   │   └── trade.js | ||||
| │   ├── model // Data interaction classed | ||||
| │   │   ├── minecraft.js // Abstraction of the Mineflayer class. | ||||
| │   │   ├── mcaction.js // Class to abstract bot actions and movement, currently unused left for reference  | ||||
| │   │   ├── matrix_quotes.js // Holds list of quotes | ||||
| │   │   └── pink_quotes.js | ||||
| │   └── utils // Holds common JS helper functions used in the project | ||||
| │       └── index.js | ||||
| └── ops         // Operational concerns, like deploy scripts and services | ||||
|     ├── conf.js        // Sample secret.js file | ||||
|     └── mc-bot.service | ||||
| ``` | ||||
		Reference in New Issue
	
	Block a user