diff --git a/src/bot.js b/src/bot.js
index a218614..7654944 100644
--- a/src/bot.js
+++ b/src/bot.js
@@ -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;
diff --git a/src/commands/eval.js b/src/commands/eval.js
new file mode 100644
index 0000000..a3378d2
--- /dev/null
+++ b/src/commands/eval.js
@@ -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: [
+ ""
+ ]
+ },
+ 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());
+ }
+ }
+}
diff --git a/src/commands/kick.js b/src/commands/kick.js
new file mode 100644
index 0000000..b1789b4
--- /dev/null
+++ b/src/commands/kick.js
@@ -0,0 +1,29 @@
+module.exports = {
+ data: {
+ name: "kick",
+ enabled: true,
+ aliases: [
+ ],
+ description: "kick players",
+ usages: [
+ "invalidstring ",
+ "item ",
+ ]
+ },
+ 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");
+ }
+ }
+}
diff --git a/src/commands/kill.js b/src/commands/kill.js
new file mode 100644
index 0000000..b345503
--- /dev/null
+++ b/src/commands/kill.js
@@ -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();
+ }
+}
diff --git a/src/commands/validate.js b/src/commands/validate.js
index c38af45..4d2837b 100644
--- a/src/commands/validate.js
+++ b/src/commands/validate.js
@@ -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');
diff --git a/src/index.js b/src/index.js
index 57115d2..69d1321 100644
--- a/src/index.js
+++ b/src/index.js
@@ -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);
diff --git a/src/modules/command_loop.js b/src/modules/command_loop.js
new file mode 100644
index 0000000..a8c1c92
--- /dev/null
+++ b/src/modules/command_loop.js
@@ -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 = []
+ }
+ }
+ }
+}
diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js
index c4a1da4..b7fd7c9 100644
--- a/src/modules/command_manager.js
+++ b/src/modules/command_manager.js
@@ -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)
}
diff --git a/src/modules/console.js b/src/modules/console.js
index 02928e3..6a269da 100644
--- a/src/modules/console.js
+++ b/src/modules/console.js
@@ -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)}`)
}
}
diff --git a/src/modules/registry.js b/src/modules/registry.js
index 5876aaf..55a7b89 100644
--- a/src/modules/registry.js
+++ b/src/modules/registry.js
@@ -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)
diff --git a/src/util/eval_colors.js b/src/util/eval_colors.js
new file mode 100644
index 0000000..1b25d81
--- /dev/null
+++ b/src/util/eval_colors.js
@@ -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 }
diff --git a/src/util/loadModules.js b/src/util/loadModules.js
index d9501d5..c9f9278 100644
--- a/src/util/loadModules.js
+++ b/src/util/loadModules.js
@@ -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) {