clone from github

This commit is contained in:
Boris
2024-01-15 09:30:27 +00:00
parent cb714d9889
commit 2a47c91dbf
37 changed files with 7581 additions and 0 deletions

546
BorisBotV1/index.js Normal file
View File

@@ -0,0 +1,546 @@
//Load required classes.
const { WebsocketBot } = require('att-bot-core');
const { BasicWrapper } = require('att-websockets');
const alta_jsapi = require("alta-jsapi");
const moment = require('moment');
const fs = require('fs');
const sha512 = require('crypto-js/sha512');
//Local classes
const Player = require('./src/player.js');
const Subscriptions = require('./src/subscriptions.js');
const commands = require('./src/discordcmds.js');
const managers = require('./src/managers.js');
//Load information from credentials and config
const { username, password, botToken } = require("./credentials");
//readline stuffs
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
//functions
//NeDB
var Datastore = require('nedb');
var players = new Datastore({ filename : 'data/players.db', autoload: true });
var kills = new Datastore({ filename : 'data/playerkills.db', autoload: true });
var chunkHistory = new Datastore({ filename : 'data/chunkhistory.db', autoload: true });
var spawnables = new Datastore({ filename : 'data/spawnables.db', autoload: true });
players.ensureIndex({ fieldName: 'id', unique: 'true' });
players.persistence.setAutocompactionInterval( 129600 );
spawnables.ensureIndex({ fieldName: 'hash', unique: 'true' });
//Some utility helper functions and prototypes
function ts()
{
return "["+ moment().format("h:mm:ss A") +"] "
}
function strrep( str, n )
{
if ( n < 1 ) return '';
var result = str;
while( n-- > 0 )
{
result += str;
}
return result;
}
// Database helpers
function insertHandler( err, doc )
{
if ( err ) { console.log( err ); }
}
function updateHandler( err, rows )
{
if ( err ) { console.log( err ); }
}
//general functions
//ring of (item)
async function ro(rad, amnt, item, up) {
while (i<amnt) {
wrapper.send(`spawn ${playername} ${item}`)
x=Math.cos(i) * rad
y=Math.sin(i) * rad
smfx = smf.concat(x);
smly = sml.concat(y);
wrapper.send(smfx)
wrapper.send(smly)
wrapper.send(`select move up ${up}`)
i++
};
i=0
}
function namemanager(name) {
if(name == undefined) {
name = playername
}
if(name == "") {
name = playername
}
if(name == "poi") {
name = "poiuytrewq4645"
}
if(name == "mansnac") {
name = "mantax"
}
if(name == "ursa") {
name = "Ursidious"
}
/*if(name == "") {
name = ""
}
return name*/
}
//Vars
var playername = username;
var botConnection;
var pendingCommandList = [];
//Run the program
main();
async function main()
{
var mpassword = convertPassToHash( username, password, botToken );
console.log(ts() + 'Bot Starting');
//Login. Use "loginWithHash" if you're storing a hashed version of the password
const bot = new WebsocketBot();
await bot.loginWithHash(username, mpassword);
//Run the bot.
//When any of the 'targetServers' are available, a connection is automatically created.
alta_jsapi.Sessions.loginWithUsername(username, mpassword);
var targetServers = []
serverquery()
function serverquery() {
rl.question('Server? > ', (serverans) => //Outputs 'Server? > ' to allow the user to input one of the below results
{
(async () => {
servers = await alta_jsapi.Servers.getConsoleServers()
for(i=0; i<servers.length; i++) {
if(servers[i].name.match(serverans)) {
serverans = servers[i].name
targetServers[0] = servers[i].id
console.log(servers[i].name)
console.log(servers[i].id)
break;
}
else if(i == (servers.length - 1)) {
console.log("Selected server offline / Spelt something wrong you pleb")
serverquery()
return;
}
}
await bot.run(test => targetServers.includes(test.id), async (server, connection) =>
{
var wrapper = new BasicWrapper(connection);
command()
function command()
{
rl.question('> ', (answer) =>
{
/*//
//help
//
if (answer.startsWith("help ")) {
answer = answer.split(" ");;
if(answerARR[1] == undefined) {
//const placeholder = ["{Command}: ``", "{Syntax}: ``", "{Description}: ``"]
const cmd = ["{Command}: `cmd`","{Syntax}: `cmd [command]`","{Description}: `Runs a command from the existing modules built into the ATT Dashboard.`"]
const blendcmd = ["{Command}: `blend`","{Syntax}: `blend`","{Description}: `Spins the currently selected object as fast as the dash will let me.`"]
const stringcmd = ["{Command}: `string`","{Syntax}: `string`","{Description}: `Outputs the currently selected object to `Items.json`.`"]
const tp = ["{Command}: `teleport`","{Syntax}: `teleport [player] [location]`","{Description}: `Teleports specified player to predefined location.`"]
const clone = ["{Command}: `clone`","{Syntax}: `clone`","{Description}: `Clones currently selected item from a string.`"]
const roft = ["{Command}: `rot`","{Syntax}: `rot [radius(m)] [count] [itemname] [up ammount]`","{Description}: `Spawns a ring of things.`"]
const rofd = ["{Command}: `rod`","{Syntax}: `rod`","{Description}: `Spawns a ring of Explosive Spikes to decimate everyone in the surrounding area.`"]
const quitcmd = ["{Command}: `quit`","{Syntax}: `quit`","{Description}: `Just crashes the bot lmao.`"]
const speed = ["{Command}: `speed`","{Syntax}: `speed [(optional)playerTarget] [(optional)multiplier]`","{Description}: `Sets the target player's speed. (Default Value: 5)`"]
const heal = ["{Command}: `heal`","{Syntax}: `heal [(optional)playerTarget] [(optional)amount]`","{Description}: `Sets the target player's health. (Default Value: 100000)`"]
const strong = ["{Command}: `strong`","{Syntax}: `strong [(optional)playerTarget] [(optional)amount]`","{Description}: `Sets the target players strength. (Default Value: 15)`"]
const godon = ["{Command}: `godon`","{Syntax}: `godon [(optional)playerTarget]`","{Description}: `Turns on godmode for target player.`"]
const godoff = ["{Command}: `godoff`","{Syntax}: `godoff [(optional)playerTarget]`","{Description}: `Turns off godmode for target player.`"]
const op = ["{Command}: `op`","{Syntax}: `op [(optional)playerTarget]`","{Description}: `Boosts resistance(100000), damage(100000) and speed(2) for the target player. Lasts for 300 seconds.`"]
const spawn = ["{Command}: `spawn`","{Syntax}: `spawn [playerTarget] [ItemID] [args]`","{Description}: `Simple spawn command that integrates with managers.namemanager.`"]
const selectget = ["{Command}: `select get`","{Syntax}: `select get`","{Description}: `More detailed version of `select get` from the dashboard.`"]
const message = ["{Command}: `message`","{Syntax}: `message`; `playerTarget`; `message`","{Description}: `If both rl.questions are undefined, it will go back to original rl.question and ask for a new command. Sends a command so targetPlayer and doesnt lose focus until rl.questions are undefined.`"]
const tsd = ["{Command}: `day`", "{Syntax}: `day`", "{Description}: `Sets time to 7am`"]
const tsn = ["{Command}: `night`", "{Syntax}: `night`", "{Description}: `Sets time to 8pm`"]
const scale = ["{Command}: `scale`", "{Syntax}: `scale`", "{Description}: `WIP`"]
const SkillsAll = ["{Command}: `skillsall`", "{Syntax}: `skillsall [(optional)playerTarget]`", "{Description}: `Sets target players skills to all skills.`"]
console.log(cmd[0],cmd[1],cmd[2]),
console.log(blendcmd[0],blendcmd[1],blendcmd[2]),
console.log(stringcmd[0],stringcmd[1],stringcmd[2]),
console.log(tp[0],tp[1],tp[2]),
console.log(clone[0],clone[1],clone[2]),
console.log(rofd[0],rofd[1],rofd[2]),
console.log(roft[0],roft[1],roft[2]),
console.log(quitcmd[0],quitcmd[1],quitcmd[2]),
console.log(speed[0],speed[1],speed[2]),
console.log(heal[0],heal[1],heal[2]),
console.log(strong[0],strong[1],strong[2]),
console.log(godon[0],godon[1],godon[2]),
console.log(godoff[0],godoff[1],godoff[2]),
console.log(op[0],op[1],op[2]),
console.log(spawn[0],spawn[1],spawn[2]),
console.log(selectget[0],selectget[1],selectget[2]),
console.log(message[0],message[1],message[2]),
console.log(tsd[0],tsd[1],tsd[2]),
console.log(tsn[0],tsn[1],tsn[2]),
console.log(scale[0],scale[1],scale[2]),
console.log(SkillsAll[0],SkillsAll[1],SkillsAll[2])
}
};*/
//
//COMMAND COMMAND
//
if (answer.startsWith("cmd ")) {
answer = answer.slice(4);; //y dis work lol
(async () => {
var result = await wrapper.send(answer)
console.log(result.Result)
command()
}) ()
};
//
//SPEEN
//
if (answer.startsWith("blend")) {
(async () => {
answer = answer.slice(6);
let {xe, ye, ze} = 0
switch(answer) {
case "x":
xe = 15
break
case "y":
ye = 15
break
case "z":
ze = 15
break
default:
ze = 15
break
}
let locat = await wrapper.send("select get")
let x = locat.Result.Position[0]
let z = locat.Result.Position[1]
let y = locat.Result.Position[2]
let xr = locat.Result.Rotation[0]
let zr = locat.Result.Rotation[1]
let yr = locat.Result.Rotation[2]
while(i < 1800) {
await new Promise(r => setTimeout(r, 5));
wrapper.send(`select rotate exact ${xr+xe},${zr+ze},${yr+ye}`)
wrapper.send(`select move exact ${x},${z},${y}`)
i++
}
i=0
})()
command()
};
//
//TOSTRING WRITETO COMMAND
//
if (answer.startsWith("string")) {
(async () => {
let streeng = await wrapper.send(`select tostring`)
console.log(streeng)
let out = streeng.ResultString.split(`|`);
fs.writeFile("items.json", out[0],'utf8', function (err) {
if (err) {
console.log("An error occured while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
})
})()
command()
};
//
//TELEPORT EXACT COMMAND
//
if (answer.startsWith("teleport ")) {
//probs not possible but worth poking
(async () => {
answerARR = answer.split(" ");
wrapper.send(`select 4`);
var location = await wrapper.send(`select get`);
let [x, z, y] = location.Result.Position;
let [bla, name, x2, z2, y2] = answerARR
playername = managers.namemanager(name)
let dest = managers.teleportmanager(x2)
if (dest != null) {
[x2, z2, y2] = dest
}
wrapper.send(`select move exact ${x2},${z2},${y2}`)
if(z2 == 1000.69) {
wrapper.send(`select snap-ground`)
wrapper.send(`select move up 2`)
}
wrapper.send(`player teleport ${playername} testingarea`)
wrapper.send(`select move exact ${x},${z},${y}`)
command()
})();
}
//
//CLONE COMMAND
//
if (answer.startsWith("clone")) {
(async () => {
const string = await wrapper.send("select tostring")
wrapper.send(`spawn string ${playername} ${string.ResultString}`)
})()
command()
};
//
//RING OF THING
//
//rot syntax: rot (radius(m)) (count) (itemname) (up ammount)
if (answer.startsWith("rot ")) {
answerARR = answer.split(" ");
if(answerARR[4] == undefined) {
answerARR[4] = 0
}
ro(answerARR[1], answerARR[2], answerARR[3], answerARR[4])
command()
};
//
//RING OF DEATH
//
if (answer.startsWith("rod")) {
ro(5, 40, "explosivespike", 10)
command()
};
//
//quit command (literally just crashes the bot lmao)
//
if (answer.startsWith("quit")) {
quit
command()
};
//
//set player's speed
//
if (answer.startsWith("speed ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if ((answerARR[1].contains() && isnumeric(answerARR[2]))) {
wrapper.send(`player setstat ${answerARR[1]} speed ${answerARR[2]}`)
}
else if ((answerARR[1] == undefined) && (answerARR[2] == undefined)) {
wrapper.send(`player setstat ${playername} speed 5`)
}
else if ((answerARR[1].contains(name)) && (answerARR[2] == undefined)){
wrapper.send(`player setstat ${answerARR[1]} speed 5`)
}
else {
console.log("Blame Boris lmao")
}
command()
};
//
//set a player's health
//
if (answer.startsWith("heal ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if ((answerARR[1].contains(name) && isnumeric(answerARR[2]))) {
wrapper.send(`player setstat ${answerARR[1]} health ${answerARR[2]}`)
}
else if ((answerARR[1] == undefined) && (answerARR[2] == undefined)) {
wrapper.send(`player setstat ${playername} health 100000`)
}
else if ((answerARR[1].contains(name)) && (answerARR[2] == undefined)){
wrapper.send(`player setstat ${answerARR[1]} health 100000`)
}
else {
console.log("Blame Boris lmao")
}
command()
};
//
//set a player's damage
//
if (answer.startsWith("strong ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if ((answerARR[1].contains(name) && isnumeric(answerARR[2]))) {
wrapper.send(`player setstat ${answerARR[1]} damage ${answerARR[2]}`)
}
else if ((answerARR[1] == undefined) && (answerARR[2] == undefined)) {
wrapper.send(`player setstat ${playername} damage 15`)
}
else if ((answerARR[1].contains(name)) && (answerARR[2] == undefined)){
wrapper.send(`player setstat ${answerARR[1]} damage 15`)
}
else {
console.log("Blame Boris lmao")
}
command()
};
if (answer.startsWith("godon ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if (answerARR[1].contains(name)) {
wrapper.send(`player godmodeon ${answerARR[1]}`)
}
else {
wrapper.send(`player godmodeon ${playername}`)
}
command()
};
if (answer.startsWith("godoff ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if (answerARR[1].contains(name)) {
wrapper.send(`player godmodeoff ${answerARR[1]}`)
}
else {
wrapper.send(`player godmodeoff ${playername}`)
}
command()
};
if (answer.startsWith("op ")) {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
if (answerARR[1].contains(name)) {
wrapper.send(`player modifystat ${answerARR[1]} damage 100000 300`)
wrapper.send(`player modifystat ${answerARR[1]} damageprotection 100000 300`)
wrapper.send(`player modifystat ${answerARR[1]} speed 2 300`)
}
else if (answerARR[1] == undefined) {
wrapper.send(`player modifystat ${playername} damage 100000 300`)
wrapper.send(`player modifystat ${playername} damageprotection 100000 300`)
wrapper.send(`player modifystat ${playername} speed 2 300`)
}
else {
console.log("Blame Boris lmao")
}
};
//spawn command
//super lazy code
if (answer.startsWith("spawn ")) {
(async () => {
answerARR = answer.split(" ");
answerARR[1] = managers.namemanager(answerARR[1])
//this V is SUPER lazy please dont ever code like me
let item
if(answerARR[5] != undefined) {
item = answerARR[2] + answerARR[3] + answerARR[4] + answerARR[5]
} else if(answerARR[4] != undefined) {
item = answerARR[2] + answerARR[3] + answerARR[4]
} else if(answerARR[3] != undefined) {
item = answerARR[2] + answerARR[3]
} else {
item = answerARR[2]
}
await wrapper.send(`spawn ${answerARR[1]} ${item}`)
//catch(error) {console.log("poi cant code for shit lmao")}
//console.log(result.Result)
command()
}) ()
};
//select get that outputs to console commands
if (answer.startsWith("select get")) {
(async () => {
let locat = await wrapper.send("select get");
let { x, z, y } = locat.Result.Position
let { xr, zr, yr } = locat.Result.Rotation
console.log(`select move exact ${x},${z},${y}`)
console.log(`select rotate exact ${xr},${zr},${yr}`)
console.log(`name: ${locat.Result.Name}`)
command()
}) ()
};
//
//daytime
//
if (answer.startsWith("day")) {
wrapper.send("time set 7")
command()
};
//
//nighttime
//
if (answer.startsWith("night")) {
wrapper.send("time set 20")
command()
};
//
//Buys all skills
//
if (answer.startsWith("SkillsAll ")) {
(async () => {
answerARR = answer.split(" ");
answerARR[1] = namemanager(answerARR[1])
while(i<answerARR[2]) {
wrapper.send(`player progression allxp ${answerARR[1]} 999999`)
wrapper.send(`player progression showskills ${answerARR[1]}`)
wrapper.send(`player progression buyskill 0`)
i++
}
})()
command()
};
if (answer.startsWith("scale")) {
(async ()=>{
let selection = await wrapper.send(`select get`)
if(selection.Result) {
let response = await wrapper.send(`select tostring`)
var location = await wrapper.send(`select get`)
let string = response.ResultString.split(",")
await wrapper.send(`select destroy`)
//11 but js from 0
string[10] = 1036831949
string = string.toString()
//console.log(response, location, string, location.Result.Position.toString())
wrapper.send(`spawn string ${playername} ${string}`)
wrapper.send(`select move exact ${location.Result.Position.toString()}`)
wrapper.send(`select rotate exact ${location.Result.Rotation.toString()}`)
}
})()
command()
}
if (answer.startsWith("")) {
command()
};
})}
})
})()
})
}
//Hash Password
function convertPassToHash( username, password, botToken )
{
// The SHA512 hash generated by crypto-js/sha512 will be 128 characters
if ( password.length !== 128 )
{
console.log( "Plaintext password encountered, converting to SHA512 hash for permanent storage" );
newPass = alta_jsapi.Sessions.hashPassword(password)
newFile = { "username" : username, "password" : newPass, "botToken": botToken };
fs.writeFile('./credentials.json', JSON.stringify( newFile, null, 4 ), function( err ) {
if ( err )
{
console.log( err );
} else {
console.log( "New credentials.json saved" );
}
});
password = newPass;
}
return password;
}
}