Advertisement
Guest User

help

a guest
Oct 31st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. const mineflayer = require('mineflayer');
  2. const fs = require('fs');
  3. const datetime = require('node-datetime');
  4.  
  5. var config = require('./config');
  6. var trueList = ["1", "yes", "true"];
  7.  
  8. var errorSyntax = " Error: Invalid syntax";
  9. var errorCmd = " Error: Invalid command";
  10.  
  11. var bot;
  12.  
  13. if (process.argv.length === 4) {
  14. bot = mineflayer.createBot({
  15. username: config.login.username,
  16. password: config.login.password,
  17. host: process.argv[2],
  18. port: parseInt(process.argv[3]),
  19. verbose: true
  20. });
  21. } else if (process.argv.length === 6) {
  22. bot = mineflayer.createBot({
  23. username: process.argv[2] ? process.argv[2] : 'echo',
  24. password: process.argv[3],
  25. host: process.argv[4],
  26. port: parseInt(process.argv[5]),
  27. verbose: true
  28. });
  29. } else {
  30. console.log('Usage: node bot.js <username> <password> <host> <port>');
  31. process.exit(1);
  32. }
  33.  
  34. function parseCommand(username, message) {
  35.  
  36. var name = username.trim();
  37.  
  38. if (!message.startsWith(config.prefix)) {
  39.  
  40. if (message.toLowerCase() === "good bot")
  41. bot.whisper(username, "Thanks!");
  42.  
  43. return;
  44. }
  45.  
  46. if (name === bot.username || config.blacklist.includes(name)) return;
  47.  
  48. var index = message.indexOf(" ");
  49.  
  50. if (index < 0) {
  51.  
  52. var keyword = message.substring(config.prefix.length).toLowerCase();
  53. var args = [];
  54.  
  55. } else {
  56.  
  57. var keyword = message.substring(config.prefix.length, index).toLowerCase();
  58. var args = message.substring(index + 1).split(", ");
  59. }
  60.  
  61. console.log("Command: " + keyword);
  62. console.log("Arguments: [" + args.join(", ") + "]");
  63.  
  64. for (i = 0; i < cmdsNormal.length; i++) {
  65. if (keyword === cmdsNormal[i].name) {
  66. cmdsNormal[i](name, args);
  67. return
  68. }
  69. }
  70.  
  71. if (config.admin.includes(name)) {
  72. for (i = 0; i < cmdsAdmin.length; i++) {
  73. if (keyword === cmdsAdmin[i].name) {
  74. cmdsAdmin[i](name, args);
  75. return
  76. }
  77. }
  78. }
  79.  
  80. if (keyword in config.customcmds) {
  81. console.log(config.customcmds[keyword]);
  82. bot.chat(config.customcmds[keyword]);
  83. return;
  84. }
  85.  
  86. if (keyword in config.admincmds) {
  87. console.log(config.admincmds[keyword]);
  88. bot.whisper(username, config.admincmds[keyword]);
  89. return;
  90. }
  91.  
  92. bot.whisper(username, errorCmd);
  93. return;
  94. }
  95.  
  96. //Helper functions
  97. function saveConfig() {
  98.  
  99. var json = JSON.stringify(config);
  100. fs.writeFile("./config.json", json);
  101. }
  102.  
  103. function amountOfGay(str) {
  104.  
  105. var hash = str.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
  106.  
  107. return (Math.round((1000*hash + 250*Math.pow(2, 33))/(Math.pow(2, 32)))/10);
  108. }
  109.  
  110. //Commands for everyone
  111. function help(username, args) {
  112.  
  113. bot.whisper(username, "https://pastebin.com/yy0iSAuQ");
  114. }
  115.  
  116. function ping(username, args) {
  117. bot.chat("Pong, " + username + "!");
  118. }
  119.  
  120. function say(username, args) {
  121.  
  122. if (args.length < 1) {
  123. bot.whisper(username, errorSyntax);
  124. return;
  125. }
  126.  
  127. bot.chat(" " + args[0]);
  128. }
  129.  
  130. function msg(username, args) {
  131.  
  132. if (args.length < 2) {
  133. bot.whisper(username, errorSyntax);
  134. return;
  135. }
  136.  
  137. bot.whisper(args[0], args[1]);
  138. }
  139.  
  140. function suicide(username, args) {
  141.  
  142. bot.chat("/suicide");
  143. }
  144.  
  145. function coords(username, args) {
  146.  
  147. bot.chat("My coordinates are (" + Math.round(bot.entity.position.x) + ", " + Math.round(bot.entity.position.y) + ", " + Math.round(bot.entity.position.z) + ").");
  148. }
  149.  
  150. function gay(username, args) {
  151.  
  152. if (args.length < 1) {
  153. bot.chat(username + ", you are " + amountOfGay(username) + "% gay.");
  154. } else {
  155. bot.chat(args[0] + " is " + amountOfGay(args[0]) + "% gay.");
  156. }
  157. }
  158.  
  159. function holding(username, args) {
  160.  
  161. var item = bot.entity.heldItem;
  162.  
  163. if (item != undefined) {
  164. bot.chat("I am holding " + item.count + " " + item.displayName + ".");
  165. } else {
  166. bot.chat("My hand is empty.");
  167. }
  168. }
  169.  
  170. function status(username, args) {
  171.  
  172. var health = bot.health;
  173. var hunger = bot.food;
  174.  
  175. bot.chat("I have " + health + " health and " + hunger + " hunger points.");
  176. }
  177.  
  178. function time(username, args) {
  179.  
  180. if (args.length < 1) {
  181. bot.whisper(username, errorSyntax);
  182. return;
  183. }
  184.  
  185. if (args[0] === "irl") {
  186.  
  187. var dt = datetime.create();
  188. var formatted = dt.format('Y-m-d H:M:S');
  189.  
  190. bot.chat("The current time is " + formatted);
  191.  
  192. } else if (args[0] === "minecraft") {
  193.  
  194. var ticks = bot.time.day;
  195.  
  196. var hours = Math.floor(ticks / 1000);
  197. var minutes = Math.floor((ticks % 1000) * 0.06);
  198.  
  199. bot.chat("The current ingame time is " + ("00" + hours).substr(-2,2) + ":" + ("00" + minutes).substr(-2,2) + ".");
  200. }
  201. }
  202.  
  203. //Commands for admins only
  204. function blacklist(username, args) {
  205.  
  206. if (args.length < 2) {
  207. bot.whisper(username, errorSyntax);
  208. return;
  209. }
  210.  
  211. if (trueList.includes(args[1].toLowerCase())) {
  212.  
  213. if (config.blacklist.includes(args[0])) return;
  214. config.blacklist.push(args[0]);
  215.  
  216. bot.chat(args[0] + " was blacklisted.");
  217.  
  218. } else {
  219.  
  220. if (!config.blacklist.includes(args[0])) return;
  221. var index = config.blacklist.indexOf(args[0]);
  222. config.blacklist.splice(index, 1);
  223.  
  224. bot.chat(args[0] + " was unblacklisted.");
  225. }
  226.  
  227. saveConfig();
  228. }
  229.  
  230. function admin(username, args) {
  231.  
  232. if (args.length < 2) {
  233. bot.whisper(username, errorSyntax);
  234. return;
  235. }
  236.  
  237. if (trueList.includes(args[1].toLowerCase())) {
  238.  
  239. if (config.admin.includes(args[0])) return;
  240. config.admin.push(args[0]);
  241.  
  242. bot.chat(args[0] + " is now admin.");
  243.  
  244. } else {
  245.  
  246. if (!config.admin.includes(args[0])) return;
  247. var index = config.admin.indexOf(args[0]);
  248. config.admin.splice(index, 1);
  249.  
  250. bot.chat(args[0] + " is no longer admin.");
  251. }
  252.  
  253. saveConfig();
  254. }
  255.  
  256. function prefix(username, args) {
  257.  
  258. if (args.length < 1) {
  259. bot.whisper(username, errorSyntax);
  260. return;
  261. }
  262.  
  263. config.prefix = args[0];
  264. saveConfig();
  265.  
  266. bot.chat("Prefix changed to " + config.prefix + ".");
  267. }
  268.  
  269. function quit(username, args) {
  270.  
  271. bot.quit();
  272. }
  273.  
  274. function command(username, args) {
  275.  
  276. if (args.length < 2) {
  277. bot.whisper(username, errorSyntax);
  278. return;
  279. }
  280.  
  281. if (args[-1] === "-a") {
  282.  
  283. if (config.admin.includes(username)) {
  284.  
  285. if (args[0].toLowerCase() === "set") {
  286. config.admincmds[args[1]] = args[2];
  287. } else if (args[0].toLowerCase() === "del") {
  288. delete config.admincmds[args[1]];
  289. } else if (args[0].toLowerCase() === "clear") {
  290. config.admincmds === {};
  291. }
  292. } else {
  293.  
  294. if (args[0].toLowerCase() === "set") {
  295. config.customcmds[args[1]] = args[2];
  296. } else if (args[0].toLowerCase() === "del") {
  297. delete config.customcmds[args[1]];
  298. } else if (args[0].toLowerCase() === "clear") {
  299. config.customcmds === {};
  300. }
  301. }
  302.  
  303. saveConfig();
  304. }
  305.  
  306. var cmdsNormal = [help, ping, say, msg, suicide, coords, gay, holding, status, time];
  307. var cmdsAdmin = [blacklist, admin, prefix, quit, command];
  308.  
  309. bot.on('login', () => {
  310.  
  311. bot.chat("Bot is now active! (Try " + config.prefix + "help for the full list of commands!)");
  312. });
  313.  
  314. bot.on('chat', (username, message) => {
  315.  
  316. parseCommand(username, message);
  317. });
  318.  
  319.  
  320. =-=-=-=-=-=-=-=-=-=ERROR=-=-=-=-=-=--=-=-=-=-=-=
  321.  
  322. /Users/5space/Desktop/5Bot/5bot.js:319
  323. });
  324. ^
  325.  
  326. SyntaxError: Unexpected token )
  327. at createScript (vm.js:56:10)
  328. at Object.runInThisContext (vm.js:97:10)
  329. at Module._compile (module.js:542:28)
  330. at Object.Module._extensions..js (module.js:579:10)
  331. at Module.load (module.js:487:32)
  332. at tryModuleLoad (module.js:446:12)
  333. at Function.Module._load (module.js:438:3)
  334. at Module.runMain (module.js:604:10)
  335. at run (bootstrap_node.js:389:7)
  336. at startup (bootstrap_node.js:149:9)
  337.  
  338. what the fuck please help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement