added validation and alot more shit

This commit is contained in:
Parker2991
2024-12-19 08:29:31 -05:00
parent a3b4963307
commit 80482759e6
12 changed files with 174 additions and 19 deletions
+13 -6
View File
@@ -27,20 +27,20 @@ function createBot(context) {
bot.username = client.username
})
client.on('disconnect', data => {
client.on('disconnect', data => {
bot.emit("disconnect", data);
console.warn(data);
bot?.console?.disconnect(data.reason);
})
client.on('end', reason => {
bot.emit('end', reason);
if (reason === "socketClosed") return;
console.warn(reason);
bot?.console?.disconnect(reason);
})
client.on('error', error => {
bot.emit('error', error);
console.warn(error.toString());
bot?.console?.disconnect(error.toString());
})
client.on("keep_alive", ({ keepAliveId }) => {
@@ -49,9 +49,17 @@ function createBot(context) {
client.on('kick_disconnect', (data) => {
bot.emit("kick_disconnect", data);
console.warn(fromNotch(data.reason)?.toAnsi());
bot?.console?.disconnect(data.reason);
})
client.on('success', (data) => {
bot?.console?.log(`Successfully logged into ${bot.server.host}:${bot.server.port}`)
});
client.on('server_data', (data) => {
bot?.console?.log(data.motd)
});
process.on("uncaughtException", (e) => {
// console?.warn(e.stack)
});
@@ -60,7 +68,6 @@ function createBot(context) {
const client = mc.createClient(bot.server)
bot._client = client
bot.emit('init_client', client)
// bot.bots = options.bots ?? [bot]
return bot;
}
module.exports = createBot;
+24
View File
@@ -0,0 +1,24 @@
const { stylize } = require('../util/eval_colors');
const util = require('util');
module.exports = {
data: {
name: "eval",
enabled: true,
aliases: [
],
description: "self explanatory",
usages: [
"<input>"
]
},
execute (context) {
const bot = context.bot;
const args = context.arguments;
try {
bot.console.command({ text: util.inspect(eval(args.join(' ')), { stylize })});
} catch (e) {
bot.console.command(e.toString());
}
}
}
+29
View File
@@ -0,0 +1,29 @@
module.exports = {
data: {
name: "kick",
enabled: true,
aliases: [
],
description: "kick players",
usages: [
"invalidstring <player>",
"item <player>",
]
},
execute (context) {
const bot = context.bot;
const args = context.arguments;
switch (args[0]?.toLowerCase()) {
case "invalidstring":
bot.exploits.crashes.invalidString(args.slice(1).join(' '));
bot.console.command(`Crashing ${args.slice(1).join(' ')}`);
break;
case "item":
bot.exploits.kicks.item(args.slice(1).join(' '));
bot.console.command(`Kicking ${args.slice(1).join(' ')}`);
break;
default:
bot.console.command("invalid argument");
}
}
}
+16
View File
@@ -0,0 +1,16 @@
module.exports = {
data: {
name: "kill",
enabled: true,
aliases: [
],
description: "kills the process",
usages: [
]
},
execute (context) {
const bot = context.bot;
const args = context.arguments;
process.exit();
}
}
+14 -1
View File
@@ -50,10 +50,23 @@ module.exports = {
}
break;
case "sbot":
const md = crypto.createHash('MD5');
const command = args.slice(1).join(' ');
const timee = Math.floor(+new Date() / 20000);
const raw = config.bots.sbot.prefix+`${command.replace(/&[0-9a-fklmnor]/g, '')};${bot.server.username};${timee};${config.bots.sbot.key}`;
md.update(raw);
hash = md.digest();
const big_int = hash.slice(0, 4).readUInt32BE();
bot.chat(`${config.bots.sbot.prefix}${command} ${big_int.toString(36)}`);
break;
case "testbot":
context.webhook.send(`${bot.server.username}`);
if (bot.customChat.enabled) {
bot.customChat.chat(`${config.bots.testbot.prefix}${args.slice(1).join(' ')}`);
} else {
bot.chat(`${config.bots.testbot.prefix}${args.slice(1).join(' ')}`);
}
break;
default:
console.warn('unknown argument');
+6 -1
View File
@@ -1,6 +1,8 @@
const fs = require('fs');
const { load } = require('js-yaml');
const path = require('path');
const { WebhookClient } = require('discord.js');
if (!fs.existsSync(path.join(__dirname, "../config.yml"))) {
console.warn("Config not found creating config from the default config");
@@ -33,6 +35,9 @@ try {
console.error(e.stack);
}
const webhook = new WebhookClient({ id: config.bots.testbot.id, token: config.bots.testbot.token });
webhook.send({ content: "amogus" });
let bot = require('./bot.js')({ config });
require('./util/loadModules')(bot, config);
require('./util/loadModules')(bot, config, webhook);
+39
View File
@@ -0,0 +1,39 @@
module.exports = {
data: {
description: "loops commands",
enabled: true,
name: "command loop",
type: "extras"
},
inject (context) {
const bot = context.bot;
bot.cloop = {
list: [],
add (command, interval) {
let timer;
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
this.list.push(timer)
bot.on('end', () => {
this.clear()
})
bot.on('packet.login', () => {
if (this.list.length === 0) return
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
this.list.push(timer);
})
},
remove (index) {
clearInterval(this.list[index].timer)
bot.cloop.list.splice(index, 1)
},
clear () {
for (const cloop of this.list) clearInterval(cloop.timer)
this.list = []
}
}
}
}
+2 -1
View File
@@ -11,6 +11,7 @@ module.exports = {
inject (context) {
const bot = context.bot;
const config = context.config;
const webhook = context.webhook;
const { MessageBuilder } = require('prismarine-chat')(bot.server.version);
bot.commandManager = {
commands: {},
@@ -20,7 +21,7 @@ module.exports = {
try {
if (!command || !command.execute) bot.console.command('unknown command');
return command?.execute({ bot, config, arguments: args, MessageBuilder })
return command?.execute({ bot, config, arguments: args, MessageBuilder, webhook })
} catch (error) {
console.error(error)
}
+5 -6
View File
@@ -15,7 +15,6 @@ module.exports = {
inject (context) {
const bot = context.bot;
const config = context.config;
rl.on('line', (args) => {
if (args.startsWith(config.console.prefix)) {
return bot.commandManager.executeString(args.substring(config.console.prefix.length));
@@ -40,19 +39,19 @@ module.exports = {
bot.console = {
log (message) {
refreshLine(`${fromNotch("§8[§6logs§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(require('../data/language.json'))}`)
refreshLine(`${fromNotch("§8[§6logs§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(bot.registry?.language)}`)
},
command (message) {
refreshLine(`${fromNotch("§8[§ecommand§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(require('../data/language.json'))}`)
refreshLine(`${fromNotch("§8[§ecommand§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(bot.registry?.language)}`)
},
disconnect (reason) {
refreshLine(`${fromNotch("§8[§bdisconnect§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(require('../data/language.json'))}`)
refreshLine(`${fromNotch("§8[§bdisconnect§8]§r")?.toAnsi()} ${fromNotch(reason)?.toAnsi(bot.registry?.language)}`)
},
warn (error) {
refreshLine(`${fromNotch("§8[§cwarn§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(require('../data/language.json'))}`)
refreshLine(`${fromNotch("§8[§cwarn§8]§r")?.toAnsi()} ${fromNotch(error)?.toAnsi(bot.registry?.language)}`)
},
error (error) {
refreshLine(`${fromNotch("§8[§4error§8]§r")?.toAnsi()} ${fromNotch(message)?.toAnsi(require('../data/language.json'))}`)
refreshLine(`${fromNotch("§8[§4error§8]§r")?.toAnsi()} ${fromNotch(error)?.toAnsi(bot.registry?.language)}`)
}
}
+2 -2
View File
@@ -3,13 +3,13 @@ const registry = require('prismarine-registry');
module.exports = {
data: {
description: "registers the client data",
enabled: true,
name: 'registry',
type: 'client',
enabled: true
},
inject (context) {
const bot = context.bot;
bot.on('login', packet => {
bot.on('packet.login', packet => {
bot.registry = registry(bot._client.version)
bot.registry.language = require('../data/language.json');
bot.emit('registry_ready', bot.registry)
+22
View File
@@ -0,0 +1,22 @@
const styles = {
bigint: '\xa76', // gold
boolean: '\xa76', // gold
date: '\xa75', // dark_purple
module: '\xa7n', // underline
name: undefined, //undefined
null: '\xa73', // bold
number: '\xa76', // gold
regexp: '\xa74', // dark_red
special: '\xa73', // blue
string: '\xa72', // green
symbol: '\xa72', // green
undefined: '\xa78' // dark_gray
}
function stylize (str, styleType) {
const style = styles[styleType]
if (style !== undefined) return `${style}${str}\xa7r`
return str
}
module.exports = { stylize, styles }
+2 -2
View File
@@ -1,12 +1,12 @@
const fs = require("fs");
const path = require("path");
async function loadModules (bot, config) {
async function loadModules (bot, config, webhook) {
for (const filename of fs.readdirSync(path.join(__dirname, '../', 'modules'))) {
try {
if (filename.endsWith(".js")) {
const module = require(path.join(__dirname, '../modules', filename));
if (module.data.enabled === false) return;
module.inject({ bot, config });
module.inject({ bot, config, webhook });
bot.emit('modules', module.data);
}
} catch (error) {