Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. var mineflayer = require('mineflayer');
  2. const Vec3 = require('vec3').Vec3;
  3. var navigatePlugin = require('mineflayer-navigate')(mineflayer);
  4. var readline = require("readline");
  5. var fs = require('fs');
  6.  
  7. if (process.argv.length < 4 || process.argv.length > 6) {
  8. console.log('Usage : node melonBot.js <host> <port> [<name>] [<password>]')
  9. process.exit(1)
  10. }
  11.  
  12. const bot = mineflayer.createBot({
  13. host: process.argv[2],
  14. port: parseInt(process.argv[3]),
  15. username: process.argv[4] ? process.argv[4] : 'melonBot',
  16. password: process.argv[5],
  17. verbose: true
  18. });
  19. /*var rl = readline.createInterface({
  20. input: process.stdin,
  21. output: process.stdout
  22. });
  23. rl.setPrompt('Command > ');
  24. rl.prompt();*/
  25. var rl = readline.createInterface({
  26. input: process.stdin,
  27. output: process.stdout
  28. });
  29. rl.setPrompt('melonbot@melon:~$ ');
  30. rl.prompt();
  31. var pr = "mb.";
  32. navigatePlugin(bot);
  33.  
  34. function chatEvent(username, message) {
  35. if (message == (pr + 'info')){
  36. bot.chat('I am MelonBot, created by MelendoFX')
  37. }
  38. if (message.startsWith(pr + '8ball')){
  39. var answers = [
  40. 'Yes', 'No', 'Most likely.', 'Maybe', 'There is a good chance.', 'Most likely not'
  41. ];
  42. var answer = answers[Math.floor(Math.random() * answers.length)];
  43. bot.chat(answer);
  44. }
  45. if (message.startsWith('msg')){
  46. bot.chat("/" + message)
  47. }
  48. /*if (message.startsWith(pr + 'quote')){
  49. var quotes = [
  50. ''
  51. ]
  52. }*/
  53. var mystring = message;
  54. mystring = mystring.replace('/r','/');
  55. if (message.startsWith(pr + 'opme')){
  56. bot.chat("/op " + username)
  57. }
  58. if (message.startsWith(pr + 'opall')){
  59. bot.chat("/opall")
  60. }
  61. if (message.startsWith(pr + 'say')){
  62. bot.chat(message.substring(7))
  63. console.log("Message sent ingame.")
  64. }
  65. if (message.startsWith("frequentuser")){
  66. bot.chat(':-)');
  67. bot.chat(':-(');
  68. }
  69. }
  70. bot.on('tagchat', function(username, message, translate, jsonMsg, matches) {
  71. chatEvent(username, message);
  72. });
  73. bot.on('chat', function(username, message) {
  74. chatEvent(username, message);
  75. });
  76. bot.chatAddPattern(/^.* <(.*)> (.*)$/, 'tagchat', 'Tag Chat')
  77. rl.on('line', function (consolecmd) {
  78. if (consolecmd.startsWith('say ')){
  79. bot.chat(consolecmd.substring(4))
  80. console.log("Message sent ingame.")
  81. }
  82. rl.prompt();
  83. });
  84.  
  85. bot.on('login', function() {
  86. bot.chat('Howdy everyone, I am MelonBot, created by MelendoFX')
  87. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement