390 lines
No EOL
20 KiB
JavaScript
390 lines
No EOL
20 KiB
JavaScript
async function sleep(ms) {
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
}
|
|
function makeid(length) {
|
|
let result = '';
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
const charactersLength = characters.length;
|
|
let counter = 0;
|
|
while (counter < length) {
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
counter += 1;
|
|
}
|
|
return result;
|
|
}
|
|
function makeid(length) {
|
|
let result = '';
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
const charactersLength = characters.length;
|
|
let counter = 0;
|
|
while (counter < length) {
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
counter += 1;
|
|
}
|
|
return result
|
|
}
|
|
const host2 = process.argv[2]
|
|
const port2 = parseInt(process.argv[3]) ? process.argv[3]: 25565
|
|
const version2 = process.argv[4]
|
|
const corejs = require("./plugins/cmdCore.js");
|
|
const crypto = require('crypto');
|
|
const config = require("./conf.json");
|
|
const fs = require("fs/promises")
|
|
const mf = require("mineflayer");
|
|
const chalk = require('chalk')
|
|
const readline = require('readline')
|
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
const creator = "m_c_player"
|
|
|
|
rl.on('line', line => bot.cmdCore.run(`bcraw ${config.rank}&r ${config.consoleuname}&r: ${line}`))
|
|
var haash = makeid(15);
|
|
console.log(haash)
|
|
var ownerhaash = makeid(25);
|
|
console.log(ownerhaash)
|
|
|
|
function hash() {
|
|
haash = makeid(15);
|
|
console.log(haash)
|
|
}
|
|
function ownerhash() {
|
|
ownerhaash = makeid(25);
|
|
console.log(ownerhaash)
|
|
}
|
|
const bot = mf.createBot({
|
|
host: host2,
|
|
port: port2,
|
|
username: makeid(10)+"§ ",
|
|
version: version2
|
|
});
|
|
function lookAtNearestPlayer () {
|
|
const playerFilter = (entity) => entity.type === 'player'
|
|
const playerEntity = bot.nearestEntity(playerFilter)
|
|
|
|
if (!playerEntity) return
|
|
|
|
const pos = playerEntity.position.offset(0, playerEntity.height, 0)
|
|
bot.lookAt(pos)
|
|
}
|
|
|
|
bot.on('physicTick', lookAtNearestPlayer)
|
|
|
|
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
|
|
bot.once('spawn', () => {
|
|
const port3 = between(0, 65535)
|
|
mineflayerViewer(bot, { port: port3, firstPerson: false }) // port is the minecraft server port, if first person is false, you get a bird's-eye view
|
|
console.log("localhost:"+port3)
|
|
})
|
|
|
|
function chat(message) {
|
|
bot.chat(message);
|
|
}
|
|
|
|
function between(min, max) {
|
|
return Math.floor(Math.random() * (max - min) + min);
|
|
}
|
|
|
|
|
|
bot.on("pos", async () => {
|
|
bot.creative.startFlying();
|
|
await sleep(150);
|
|
bot.chat(`/prefix &4[&cPrefix: ${config.prefix}&4]`)
|
|
await sleep(150);
|
|
bot.chat(`/god on`)
|
|
await sleep(150);
|
|
bot.chat(`/tptoggle off`)
|
|
await sleep(150);
|
|
bot.chat(`/v on`)
|
|
await sleep(150);
|
|
bot.chat(`/gamemode creative`)
|
|
await sleep(150);
|
|
bot.chat(`/op @s[type=player]`)
|
|
await sleep(150);
|
|
bot.chat(`/cspy on`)
|
|
await sleep(150);
|
|
//bot.chat(`/username &c&lmBot`)
|
|
//await sleep(500);
|
|
bot.chat("&c&lmBot&r - a bot created by &c&lm_c_player")
|
|
await sleep(150);
|
|
bot.chat("Prefix: "+config.prefix)
|
|
});
|
|
async function repeatcmd(func, times, delay) {
|
|
for (let step = 0; step < times; step++) {
|
|
eval(func);
|
|
await sleep(delay);
|
|
}
|
|
}
|
|
bot.on("login", async () => {
|
|
fs.appendFile("/Users/m_c_player/mcbot/chatlog.txt", `\n//// Host: ${host2}, Port: ${port2}, Time: ${Date.now()} ////`)
|
|
corejs.injectTo(bot);
|
|
// make the bot use the /fill cmd and /tppos cmd
|
|
//bot.chat(`/tppos -284 70 -358`)
|
|
setTimeout(() => {
|
|
setInterval(() => {
|
|
//invis
|
|
bot.cmdCore.run(`effect give @e[tag=invis] invisibility infinite 255 true`)
|
|
//timebar
|
|
let currentTime = new Date();
|
|
let options = { timeStyle: 'long', hour12: true };
|
|
let timeString = currentTime.toLocaleTimeString('en-US', options);
|
|
bot.cmdCore.run(`title @a[tag=timebar] actionbar ${JSON.stringify(`${timeString}`)}`)
|
|
//selfcare
|
|
if(bot.game.gameMode = 0) {
|
|
bot.cmdCore.run(`gamemode creative ${bot.username}`)
|
|
}
|
|
|
|
}, 200);
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
|
|
const chatListener = (uname, msg, jsonMsg, rank) => {
|
|
if(msg.startsWith("/")) {
|
|
console.log(chalk.yellow(`${uname}: ${msg}`))
|
|
fs.appendFile("/Users/m_c_player/mcbot/chatlog.txt", `\n${uname}: ${msg}`)
|
|
if(uname === config.consoleuname && rank === undefined) { // Allows running commands in console
|
|
bot.cmdCore.run(msg)
|
|
}
|
|
} else {
|
|
console.log(``+rank+``)
|
|
fs.appendFile("/Users/m_c_player/mcbot/chatlog.txt", `\n[`+rank+`] ${uname}: ${msg}`)
|
|
}
|
|
if (!msg.startsWith(config.prefix)) return;
|
|
|
|
const args = msg.slice(config.prefix.length).trim().split(/ +/);
|
|
const cmd = args.shift().toLowerCase();
|
|
|
|
const cmds = {
|
|
help: () => {
|
|
bot.cmdCore.run(`tellraw ${uname} ${JSON.stringify(["",{"text":"Commands () ","bold":true},"- help, loghash, fakeacc (username), unfakeacc, testcore, say (text), cb (command), selfcare, refillcore, stringify (text), invis (username), uninvis (username), opsword (player), opzombie (player), timebar (player), untimebar (player), asciiart (file) (player), asciiartlist, tptovoid (player), translate (translate), jsonparse (text), repeat (times) (command), musicdisc (disc) (player) (volume) (pitch), hole (player) (depth), cloop (speed) (use core? true or false) (command), stopcloop (id), ",{"text":"crash (hash) (type) (player),","color":"red"},{"text":" eval (hash) (code), end (hash)","color":"dark_red"}])}]`)
|
|
},
|
|
loghash: () => {
|
|
console.log("Trusted Hash: "+haash+"")
|
|
console.log("Owner Hash: "+ownerhaash+"")
|
|
bot.cmdCore.run(`tellraw @a "Hash logged to console."`)
|
|
},
|
|
fakeacc: (args) => {
|
|
try {const fakeacc = mf.createBot({
|
|
host: host2,
|
|
port: port2,
|
|
username: `${args.join(" ")}`,
|
|
version: version2
|
|
});
|
|
const chatListener = (uname, msg) => {
|
|
if (!msg.startsWith(config.prefix)) return;
|
|
const args = msg.slice(config.prefix.length).trim().split(/ +/);
|
|
const cmd = args.shift().toLowerCase();
|
|
const cmds = {
|
|
unfakeacc: () => {
|
|
fakeacc.end()
|
|
}
|
|
};if (cmds[cmd]) cmds[cmd](args);
|
|
|
|
}
|
|
fakeacc.on("chat", chatListener);
|
|
|
|
fakeacc.on("end", () => {
|
|
fakeacc.off("chat", chatListener);
|
|
});} catch (err) {console.error(err)}
|
|
},
|
|
unfakeacc: (args) => {
|
|
//prevent the "Unknown command" text
|
|
},
|
|
testcore: () => {
|
|
bot.cmdCore.run(`tellraw @a "core tested. it works!"`)
|
|
},
|
|
say: (args) => {
|
|
/*if (args[0].startsWith("/") || args[0].startsWith("#cb") || uname != creator) { // If the first word/letters after "mbot:say" start with the slash, or use HBot's "#cb" command, and the player executing isn't the creator, refuse
|
|
bot.cmdCore.run(`minecraft:tellraw @a {"text": "I don't run commands for users."}`)
|
|
}
|
|
else*/ bot.chat(args.join(" "));
|
|
},
|
|
cb: (args) => {
|
|
bot.cmdCore.run(args.join(" "));
|
|
},
|
|
selfcare: () => {
|
|
bot.cmdCore.run("minecraft:op @s");
|
|
bot.cmdCore.run("minecraft:gamemode creative");
|
|
bot.cmdCore.refillCmdCore();
|
|
bot.chat("/vanish on")
|
|
bot.chat("/evanish on")
|
|
bot.chat("/cspy on")
|
|
},
|
|
refillcore: () => {
|
|
bot.cmdCore.refillCmdCore();
|
|
bot.cmdCore.run(`tellraw @a "Refilled Core."`)
|
|
},
|
|
stringify: (args) => {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`${JSON.stringify(args.join(" "))}`)}`)
|
|
},
|
|
invis: (args) => {
|
|
bot.cmdCore.run(`tag ${args} add invis`)
|
|
bot.cmdCore.run(`tellraw @a[name=${args},tag=invis] "You are invisible!"`)
|
|
},
|
|
uninvis: (args) => {
|
|
bot.cmdCore.run(`tellraw @a[name=${args},tag=invis] "You are no longer invisible!"`)
|
|
bot.cmdCore.run(`tag ${args} remove invis`)
|
|
bot.cmdCore.run(`effect clear ${args} invisibility`)
|
|
},
|
|
opsword: (args) => {
|
|
bot.cmdCore.run(`give ${args} netherite_sword{display:{Name:'["",{"text":"OP Sword","italic":false,"color":"#ff0000","bold":true}]'},AttributeModifiers:[{Slot:"mainhand", AttributeName:"generic.attack_damage", Name:"generic.attack_damage", Amount:999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0, Operation:0, UUID:[I; 42853, 1689024593, -201178, -1559272105]},{unbreakable:1}]} 1`)
|
|
bot.cmdCore.run(`tellraw ${args} "You have recieved the OP Sword!"`)
|
|
|
|
},
|
|
opzombie: (args) => {
|
|
bot.cmdCore.run(`give ${args} zombie_spawn_egg{EntityTag:{CustomName:'[{"text":"OP Zombie","color":"#ff0000","bold":true}]',HandItems:[{id:netherite_sword,tag:{display:{Name:'["",{"text":"OP Sword","italic":false,"color":"#ff0000","bold":true}]'},AttributeModifiers:[{Slot:mainhand,AttributeName:"generic.attack_damage",Name:"generic.attack_damage",Amount:999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0,Operation:0,UUID:[I;42853,1689024593,-201178,-1559272105]},{unbreakable:1}]},Count:1},{id:totem_of_undying,Count:64}],ArmorItems:[{id:netherite_boots,tag:{Enchantments:[{lvl:255,id:blast_protection},{lvl:255,id:fire_protection},{lvl:2,id:frost_walker},{lvl:255,id:projectile_protection},{lvl:255,id:protection},{lvl:255,id:respiration},{lvl:3,id:soul_speed},{lvl:3,id:swift_sneak},{lvl:255,id:thorns}],Unbreakable:1,AttributeModifiers:[{AttributeName:"generic.attack_damage",Slot:mainhand,Name:"generic.attack_damage",UUID:[I;-124629,62740,21110,-125480]},{AttributeName:"generic.movement_speed",Amount:1,Slot:feet,UUID:[I;-124629,63040,21110,-126080],Name:1722315216629}]},Count:1},{id:netherite_leggings,tag:{Enchantments:[{lvl:255,id:blast_protection},{lvl:255,id:fire_protection},{lvl:2,id:frost_walker},{lvl:255,id:projectile_protection},{lvl:255,id:protection},{lvl:255,id:respiration},{lvl:3,id:soul_speed},{lvl:3,id:swift_sneak},{lvl:255,id:thorns}],Unbreakable:1,AttributeModifiers:[{AttributeName:"generic.attack_damage",Slot:mainhand,Name:"generic.attack_damage",UUID:[I;-124629,54940,21110,-109880]},{AttributeName:"generic.armor",UUID:[I;-124629,55240,21110,-110480],Name:1722314194540}]},Count:1},{id:netherite_chestplate,tag:{Enchantments:[{lvl:255,id:blast_protection},{lvl:255,id:fire_protection},{lvl:2,id:frost_walker},{lvl:255,id:projectile_protection},{lvl:255,id:protection},{lvl:255,id:respiration},{lvl:3,id:soul_speed},{lvl:3,id:swift_sneak},{lvl:255,id:thorns}],Unbreakable:1,AttributeModifiers:[{AttributeName:"generic.attack_damage",Slot:mainhand,Name:"generic.attack_damage",UUID:[I;-124629,54940,21110,-109880]},{AttributeName:"generic.armor",UUID:[I;-124629,55240,21110,-110480],Name:1722314194540}]},Count:1},{id:netherite_helmet,tag:{Enchantments:[{lvl:255,id:blast_protection},{lvl:255,id:fire_protection},{lvl:2,id:frost_walker},{lvl:255,id:projectile_protection},{lvl:255,id:protection},{lvl:255,id:respiration},{lvl:3,id:soul_speed},{lvl:3,id:swift_sneak},{lvl:255,id:thorns}],Unbreakable:1,AttributeModifiers:[{AttributeName:"generic.attack_damage",Slot:mainhand,Name:"generic.attack_damage",UUID:[I;-124629,54940,21110,-109880]},{AttributeName:"generic.armor",UUID:[I;-124629,55240,21110,-110480],Name:1722314194540}]},Count:1}],HandDropChances:[0f,0f],ArmorDropChances:[0f,0f,0f,0f]},display:{Name:'[{"text":"OP Zombie Spawn Egg","italic":false,"color":"#ff0000","bold":true}]'}} 1`)
|
|
bot.cmdCore.run(`tellraw ${args} "You have recieved the OP Zombie Spawn Egg!"`)
|
|
|
|
},
|
|
timebar: (args) => {
|
|
bot.cmdCore.run(`tag ${args} add timebar`)
|
|
},
|
|
untimebar: (args) => {
|
|
bot.cmdCore.run(`tag ${args} remove timebar`)
|
|
},
|
|
asciiart: async (args) => {
|
|
try {
|
|
const data = await fs.readFile('/Users/m_c_player/mcbot/ascii/'+args[0], { encoding: 'utf8' });
|
|
bot.cmdCore.run(`tellraw ${args[1]} "${data}"`)
|
|
} catch (err) {
|
|
bot.cmdCore.run(`tellraw @a "File not found"`);
|
|
}
|
|
},
|
|
asciiartlist: async () => {
|
|
try {const data = await fs.readdir('/Users/m_c_player/mcbot/ascii');
|
|
bot.cmdCore.run(`tellraw ${uname} ${JSON.stringify(`List of files:\n${data}`)}`)
|
|
} catch(err) {
|
|
console.error(`${err}`)
|
|
}
|
|
},
|
|
tptovoid: (args) => {
|
|
bot.cmdCore.run(`tp ${args} 0 -1000000 0`)
|
|
},
|
|
translate: (args) => {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify({"translate":""+args+""})}`)
|
|
},
|
|
jsonparse: (args) => {
|
|
try {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`${JSON.parse(args.join(" "))}`)}`)
|
|
} catch (err) {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`${err}`)}`);
|
|
}
|
|
},
|
|
musicdisc: (args) => {
|
|
try {bot.cmdCore.run(`playsound minecraft:music_disc.${args[0].toLowerCase()} master ${args[1]} ~ ~ ~ ${args[2]} ${args[3]} 0`)
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`Playing ${args[0].toLowerCase()} to ${args[1]} with ${args[2]} volume and ${args[3]} pitch`)}`)
|
|
} catch (err) {
|
|
console.log(err)
|
|
}
|
|
},
|
|
hole: (args) => {
|
|
bot.cmdCore.run(`execute at ${args[0]} run setblock ~ ~ ~ command_block{Command:"fill ~-1 ~ ~1 ~1 ~-${args[1]} ~-1 air",auto:1b}`)
|
|
},
|
|
repeat: (args) => {
|
|
repeatcmd(bot.cmdCore.run(msg.slice(config.prefix.length+cmd.length+1+args[0].length+args[1].length+1)), args[0], args[1])
|
|
},
|
|
stop: (args) => {
|
|
if(args == ""+ownerhaash+"") {
|
|
throw e
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Invalid Owner Hash."`)
|
|
}
|
|
},
|
|
eval: (args) => {
|
|
if(args[0] == ""+ownerhaash+"") {
|
|
try {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`${eval(msg.slice(config.prefix.length+cmd.length+1+args[0].length+1))}`)}`)
|
|
} catch (err) {
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`${err}`)}`)
|
|
}
|
|
ownerhash()
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Invalid Owner Hash."`)
|
|
}
|
|
},
|
|
crash: (args) => {
|
|
if(args[0] == ""+haash+"") {
|
|
if(args[1] === "particle") {
|
|
// Crash made by zXzy
|
|
bot.cmdCore.run(``)
|
|
} else {
|
|
if(args[1] === "translate") {
|
|
// Crash made by Parker2991
|
|
bot.cmdCore.run(`tellraw ${args[2]} `)
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Invalid Crash Type."`)
|
|
}
|
|
|
|
}
|
|
hash()
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Invalid Hash."`)
|
|
}
|
|
},
|
|
end: (args) => {
|
|
if(args[0] == ""+ownerhaash+"") {
|
|
bot.end()
|
|
ownerhash()
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Invalid Hash."`)
|
|
}
|
|
},
|
|
cloop: async (args) => {
|
|
if (args.length == 0) return;
|
|
let cloopCallbackID;
|
|
if (args[1] == "true") {
|
|
cloopCallbackID = setInterval(() => runBackgroundTask(args[0], args.join(" "), true), args[0]);
|
|
console.log(`${cloopCallbackID} is the callback ID. Save it :)`)
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`Started cloop with id ${cloopCallbackID}`)}`)
|
|
}
|
|
else if (args[1] == "false") {
|
|
cloopCallbackID = setInterval(() => runBackgroundTask(args[0], args.join(" "), false), args[0]);
|
|
console.log(`${cloopCallbackID} is the callback ID. Save it :)`)
|
|
bot.cmdCore.run(`tellraw @a ${JSON.stringify(`Started cloop with id ${cloopCallbackID}`)}`)
|
|
}
|
|
else {
|
|
bot.cmdCore.run(`tellraw @a`)
|
|
}
|
|
await sleep(200)
|
|
},
|
|
stopcloop: (args) => {
|
|
let cloopCallbackID = args[0]
|
|
try {
|
|
clearInterval(cloopCallbackID)
|
|
if (args[0] == "all") {
|
|
for (const cloopID of cloopIDs) {
|
|
clearInterval(cloopID)
|
|
}
|
|
}
|
|
}
|
|
catch (err) {
|
|
console.warn(String(err?.message))
|
|
bot.chat(err?.message.toString())
|
|
}
|
|
}
|
|
};
|
|
if(!config.blacklist.includes(uname)) {
|
|
if (cmds[cmd]) cmds[cmd](args);
|
|
else bot.cmdCore.run(`tellraw @a ${JSON.stringify(`Unknown command: ${cmd}`)}`);
|
|
} else {
|
|
bot.cmdCore.run(`tellraw @a "Sorry, you are blacklisted from using mBot's commands."`)
|
|
}
|
|
};
|
|
bot.on("chat", chatListener);
|
|
|
|
bot.on("end", () => {
|
|
bot.off("chat", chatListener);
|
|
});
|
|
|
|
function runBackgroundTask(ms, command, use_core) {
|
|
if (use_core) {
|
|
const mod_command = `${command.replace(`${ms} ${use_core} `, "")}`
|
|
bot.cmdCore.run(mod_command)
|
|
}
|
|
else {
|
|
const mod_command = `${command.replace(`${ms} ${use_core} `, "")}`
|
|
bot.chat(mod_command)
|
|
}
|
|
return;
|
|
}
|
|
linx-server |