daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Feb 24th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. const fs = require('fs');
  3.  
  4. let rawdata = fs.readFileSync('login.json');
  5. let logindata = JSON.parse(rawdata);
  6. console.log(logindata.email)
  7.  
  8. const Discord = require('discord.js')
  9. const token = logindata.token;
  10. const client = new Discord.Client()
  11. client.login(token);
  12.  
  13. let announce = []
  14. let serv = []
  15. let players = []
  16. let popped = []
  17.  
  18. client.on('ready', () => {
  19.   console.log("Connected as "+ client.user.tag)
  20. })
  21.  
  22. const cmd = "!";
  23.  
  24.   let mineflayer = require('mineflayer');
  25.  
  26.   let bot = mineflayer.createBot({
  27.     host: logindata.host, // optional
  28.     port: logindata.port,       // optional
  29.     username: logindata.email, // email and password are required only for
  30.     password: logindata.password,          // online-mode=true servers
  31.     version: logindata.version
  32.   });
  33.  
  34.   client.on("message", function (msg) {
  35.     if(msg.channel.id === logindata.relay){
  36.         bot.chat(msg.content)}
  37.  
  38.         if(msg.channel.id === logindata.relaycommands){
  39.           if(msg.member.id === logindata.discordid){
  40.             if(msg.content.startsWith(cmd + "disconnect")){
  41.               bot.quit()
  42.               client.channels.get(logindata.relaycommands).send("Disconnected from: " + logindata.host)
  43.           }
  44.             if(msg.content.startsWith(cmd + "connect")){
  45.               console.log("mentioned")
  46.               let splitMessage = msg.content.split(" ");
  47.  
  48.               let bot1 = mineflayer.createBot({
  49.                 host: splitMessage[1], // optional
  50.                 port: logindata.port,       // optional
  51.                 username: logindata.email, // email and password are required only for
  52.                 password: logindata.password,          // online-mode=true servers
  53.                 version: logindata.version
  54.               });
  55.              
  56.             }
  57.           if(msg.content.startsWith(cmd + "players")){
  58.             console.log('test')
  59.             for (var key in bot.players) {
  60.              
  61.               players.push(key)}
  62.  
  63.               const plyr = new Discord.RichEmbed()
  64.                 .setTitle("Online Players")
  65.                 .setDescription(players)
  66.               client.channels.get(logindata.relaycommands).send(plyr)
  67.             }
  68.          
  69.           if(msg.content.startsWith(cmd + "jump")){
  70.             bot.setControlState(`jump`,true)
  71.             bot.setControlState(`jump`, false)
  72.         }
  73.         }
  74.       }
  75.       })
  76.  
  77.   setInterval(function(){
  78.       if (announce.length > 0){
  79.         const embe = new Discord.RichEmbed()
  80.           .setDescription(announce)
  81.           client.channels.get(logindata.relay).send(embe)
  82.         announce = []
  83.     }}, 1000);
  84.  
  85.   bot.on('login', (login)=>{
  86.     console.log('Logged in!')
  87.     client.channels.get(logindata.relaycommands).send("Connected to: " + logindata.host)
  88.   });
  89.  
  90.   // formating
  91.   bot.on('message', (username, message) => {
  92.     let spl = (`${username}`).split(/> |: /);
  93.     let rankname = spl.shift();
  94.     let msg = spl.join(" ");
  95.     let usernme = rankname.split(" ").pop();
  96.     let rank = usernme.split(" ").shift();
  97.  
  98.     //MC commands
  99.     switch(msg) {
  100.       case cmd + "discord":
  101.         bot.chat("/msg " + usernme + " https://discord.gg/HtxcCvz");
  102.         break;
  103.       case cmd + "commands":
  104.         bot.chat("/msg " + usernme + " available commands: discord, calc")};
  105.    
  106.       //calculator command in mc
  107.     if(msg.startsWith(cmd + "calc")){
  108.       if(msg == cmd + "calc help"){
  109.         bot.chat("/msg " + usernme + " To calculate power, type !calc power>x:y:z, xyz being exposure and power being amount of power")
  110.       } else {
  111.       let variables = msg.split(/>|:| | /)
  112.       let power = variables[1], x = variables[2], y = variables[3], z = variables[4]
  113.  
  114.       let distance = Math.sqrt(x**2 + y**2 + z**2)
  115.       let xvelocity = (x / distance) * (1 - (distance / 8))
  116.       let yvelocity = (y / distance) * (1 - (distance / 8))
  117.       let zvelocity = (z / distance) * (1 - (distance / 8))
  118.       let xtravelled = xvelocity * power, ytravelled = yvelocity * power, ztravelled = zvelocity * power;
  119.  
  120.         bot.chat("/msg " + usernme + " x: " + xtravelled + " y: " + ytravelled + " z: " + ztravelled)
  121.     }}
  122.  
  123.     // Makes it so your own discord messages don't show on discord
  124.     if (usernme.includes(bot.username)){
  125.       console.log("Your message")} else {
  126.  
  127.     // Filtering
  128.       if (msg === ""){
  129.         if (usernme.includes("-> me")){
  130.           console.log(usernme)
  131.         } else {
  132.         announce.push(`${username}`)}
  133.  
  134.       } else {
  135.         //console.log(usernme + ": " + msg);
  136.         client.channels.get(logindata.relay).send({embed: {
  137.           color: 3447003,
  138.           author: {
  139.             name: usernme
  140.           },
  141.           timestamp: new Date(),
  142.           footer: {
  143.             text: msg
  144.         }
  145.       }})
  146.     }}}
  147.   );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top