Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mineflayer = require('mineflayer');
- const fs = require('fs');
- const datetime = require('node-datetime');
- var config = require('./config');
- var trueList = ["1", "yes", "true"];
- var errorSyntax = " Error: Invalid syntax";
- var errorCmd = " Error: Invalid command";
- var bot;
- if (process.argv.length === 4) {
- bot = mineflayer.createBot({
- username: config.login.username,
- password: config.login.password,
- host: process.argv[2],
- port: parseInt(process.argv[3]),
- verbose: true
- });
- } else if (process.argv.length === 6) {
- bot = mineflayer.createBot({
- username: process.argv[2] ? process.argv[2] : 'echo',
- password: process.argv[3],
- host: process.argv[4],
- port: parseInt(process.argv[5]),
- verbose: true
- });
- } else {
- console.log('Usage: node bot.js <username> <password> <host> <port>');
- process.exit(1);
- }
- function parseCommand(username, message) {
- var name = username.trim();
- if (!message.startsWith(config.prefix)) {
- if (message.toLowerCase() === "good bot")
- bot.whisper(username, "Thanks!");
- return;
- }
- if (name === bot.username || config.blacklist.includes(name)) return;
- var index = message.indexOf(" ");
- if (index < 0) {
- var keyword = message.substring(config.prefix.length).toLowerCase();
- var args = [];
- } else {
- var keyword = message.substring(config.prefix.length, index).toLowerCase();
- var args = message.substring(index + 1).split(", ");
- }
- console.log("Command: " + keyword);
- console.log("Arguments: [" + args.join(", ") + "]");
- for (i = 0; i < cmdsNormal.length; i++) {
- if (keyword === cmdsNormal[i].name) {
- cmdsNormal[i](name, args);
- return
- }
- }
- if (config.admin.includes(name)) {
- for (i = 0; i < cmdsAdmin.length; i++) {
- if (keyword === cmdsAdmin[i].name) {
- cmdsAdmin[i](name, args);
- return
- }
- }
- }
- if (keyword in config.customcmds) {
- console.log(config.customcmds[keyword]);
- bot.chat(config.customcmds[keyword]);
- return;
- }
- if (keyword in config.admincmds) {
- console.log(config.admincmds[keyword]);
- bot.whisper(username, config.admincmds[keyword]);
- return;
- }
- bot.whisper(username, errorCmd);
- return;
- }
- //Helper functions
- function saveConfig() {
- var json = JSON.stringify(config);
- fs.writeFile("./config.json", json);
- }
- function amountOfGay(str) {
- var hash = str.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
- return (Math.round((1000*hash + 250*Math.pow(2, 33))/(Math.pow(2, 32)))/10);
- }
- //Commands for everyone
- function help(username, args) {
- bot.whisper(username, "https://pastebin.com/yy0iSAuQ");
- }
- function ping(username, args) {
- bot.chat("Pong, " + username + "!");
- }
- function say(username, args) {
- if (args.length < 1) {
- bot.whisper(username, errorSyntax);
- return;
- }
- bot.chat(" " + args[0]);
- }
- function msg(username, args) {
- if (args.length < 2) {
- bot.whisper(username, errorSyntax);
- return;
- }
- bot.whisper(args[0], args[1]);
- }
- function suicide(username, args) {
- bot.chat("/suicide");
- }
- function coords(username, args) {
- bot.chat("My coordinates are (" + Math.round(bot.entity.position.x) + ", " + Math.round(bot.entity.position.y) + ", " + Math.round(bot.entity.position.z) + ").");
- }
- function gay(username, args) {
- if (args.length < 1) {
- bot.chat(username + ", you are " + amountOfGay(username) + "% gay.");
- } else {
- bot.chat(args[0] + " is " + amountOfGay(args[0]) + "% gay.");
- }
- }
- function holding(username, args) {
- var item = bot.entity.heldItem;
- if (item != undefined) {
- bot.chat("I am holding " + item.count + " " + item.displayName + ".");
- } else {
- bot.chat("My hand is empty.");
- }
- }
- function status(username, args) {
- var health = bot.health;
- var hunger = bot.food;
- bot.chat("I have " + health + " health and " + hunger + " hunger points.");
- }
- function time(username, args) {
- if (args.length < 1) {
- bot.whisper(username, errorSyntax);
- return;
- }
- if (args[0] === "irl") {
- var dt = datetime.create();
- var formatted = dt.format('Y-m-d H:M:S');
- bot.chat("The current time is " + formatted);
- } else if (args[0] === "minecraft") {
- var ticks = bot.time.day;
- var hours = Math.floor(ticks / 1000);
- var minutes = Math.floor((ticks % 1000) * 0.06);
- bot.chat("The current ingame time is " + ("00" + hours).substr(-2,2) + ":" + ("00" + minutes).substr(-2,2) + ".");
- }
- }
- //Commands for admins only
- function blacklist(username, args) {
- if (args.length < 2) {
- bot.whisper(username, errorSyntax);
- return;
- }
- if (trueList.includes(args[1].toLowerCase())) {
- if (config.blacklist.includes(args[0])) return;
- config.blacklist.push(args[0]);
- bot.chat(args[0] + " was blacklisted.");
- } else {
- if (!config.blacklist.includes(args[0])) return;
- var index = config.blacklist.indexOf(args[0]);
- config.blacklist.splice(index, 1);
- bot.chat(args[0] + " was unblacklisted.");
- }
- saveConfig();
- }
- function admin(username, args) {
- if (args.length < 2) {
- bot.whisper(username, errorSyntax);
- return;
- }
- if (trueList.includes(args[1].toLowerCase())) {
- if (config.admin.includes(args[0])) return;
- config.admin.push(args[0]);
- bot.chat(args[0] + " is now admin.");
- } else {
- if (!config.admin.includes(args[0])) return;
- var index = config.admin.indexOf(args[0]);
- config.admin.splice(index, 1);
- bot.chat(args[0] + " is no longer admin.");
- }
- saveConfig();
- }
- function prefix(username, args) {
- if (args.length < 1) {
- bot.whisper(username, errorSyntax);
- return;
- }
- config.prefix = args[0];
- saveConfig();
- bot.chat("Prefix changed to " + config.prefix + ".");
- }
- function quit(username, args) {
- bot.quit();
- }
- function command(username, args) {
- if (args.length < 2) {
- bot.whisper(username, errorSyntax);
- return;
- }
- if (args[-1] === "-a") {
- if (config.admin.includes(username)) {
- if (args[0].toLowerCase() === "set") {
- config.admincmds[args[1]] = args[2];
- } else if (args[0].toLowerCase() === "del") {
- delete config.admincmds[args[1]];
- } else if (args[0].toLowerCase() === "clear") {
- config.admincmds === {};
- }
- } else {
- if (args[0].toLowerCase() === "set") {
- config.customcmds[args[1]] = args[2];
- } else if (args[0].toLowerCase() === "del") {
- delete config.customcmds[args[1]];
- } else if (args[0].toLowerCase() === "clear") {
- config.customcmds === {};
- }
- }
- saveConfig();
- }
- var cmdsNormal = [help, ping, say, msg, suicide, coords, gay, holding, status, time];
- var cmdsAdmin = [blacklist, admin, prefix, quit, command];
- bot.on('login', () => {
- bot.chat("Bot is now active! (Try " + config.prefix + "help for the full list of commands!)");
- });
- bot.on('chat', (username, message) => {
- parseCommand(username, message);
- });
- =-=-=-=-=-=-=-=-=-=ERROR=-=-=-=-=-=--=-=-=-=-=-=
- /Users/5space/Desktop/5Bot/5bot.js:319
- });
- ^
- SyntaxError: Unexpected token )
- at createScript (vm.js:56:10)
- at Object.runInThisContext (vm.js:97:10)
- at Module._compile (module.js:542:28)
- at Object.Module._extensions..js (module.js:579:10)
- at Module.load (module.js:487:32)
- at tryModuleLoad (module.js:446:12)
- at Function.Module._load (module.js:438:3)
- at Module.runMain (module.js:604:10)
- at run (bootstrap_node.js:389:7)
- at startup (bootstrap_node.js:149:9)
- what the fuck please help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement