mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-01 14:45:43 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c21780272b | ||
|
|
9417a785de | ||
|
|
3c8a226970 |
@@ -1,75 +0,0 @@
|
||||
const mc = require('minecraft-protocol')
|
||||
const { EventEmitter } = require('node:events')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('node:util')
|
||||
|
||||
function createBot(options = {}) {
|
||||
const bot = new EventEmitter()
|
||||
const rs = require('randomstring')
|
||||
// Set some default values in options
|
||||
let r = Math.floor(Math.random() * 255) + 1;
|
||||
options.host ??= 'localhost'
|
||||
options.username ??= 'Player' + Math.floor(Math.random() * 1000)
|
||||
options.hideErrors ??= false // HACK: Hide errors by default as a lazy fix to console being spammed with them
|
||||
|
||||
bot.options = options
|
||||
|
||||
// Create our client object, put it on the bot, and register some events
|
||||
bot.on('init_client', client => {
|
||||
client.on('packet', (data, meta) => {
|
||||
bot.emit('packet', data, meta)
|
||||
bot.emit('packet.' + meta.name, data)
|
||||
})
|
||||
|
||||
client.on('login', async function (data) {
|
||||
|
||||
bot.uuid = client.uuid
|
||||
bot.username = client.username
|
||||
bot.entityId = data.entityId
|
||||
bot.host = bot.options.host
|
||||
bot.port = bot.options.port
|
||||
bot.buildstring = process.env['buildstring']
|
||||
bot.fbs = process.env['FoundationBuildString']
|
||||
})
|
||||
|
||||
client.on('end', reason => { bot.emit('end', reason)
|
||||
try {
|
||||
if (reason.text) {
|
||||
if
|
||||
}
|
||||
}
|
||||
})if
|
||||
|
||||
client.on('error', error => bot.emit('error', error), )
|
||||
|
||||
})
|
||||
|
||||
const buildstring = process.env['buildstring']
|
||||
|
||||
const client = options.client ?? mc.createClient(options)
|
||||
bot._client = client
|
||||
bot.emit('init_client', client)
|
||||
|
||||
bot.bots = options.bots ?? [bot]
|
||||
|
||||
// Modules
|
||||
bot.loadModule = module => module(bot, options)
|
||||
|
||||
for (const filename of fs.readdirSync(path.join(__dirname, 'modules'))) {
|
||||
try {
|
||||
const module = require(path.join(__dirname, 'modules', filename))
|
||||
bot.loadModule(module)
|
||||
} catch (error) {
|
||||
|
||||
console.error('\x1b[0m\x1b[91m[ERROR]: \x1b[0m\x1b[90mFailed to load module', filename, ':', error)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return bot
|
||||
}
|
||||
|
||||
// ABot username function mabe mabe
|
||||
|
||||
module.exports = createBot
|
||||
@@ -1,147 +0,0 @@
|
||||
const mc = require("minecraft-protocol");
|
||||
const { EventEmitter } = require("node:events");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const util = require("node:util");
|
||||
console.log(`Starting ${process.env["buildstring"]} .......`);
|
||||
console.log(`Foundation: ${process.env["FoundationBuildString"]}`);
|
||||
console.log("this may take a few moments....");
|
||||
require("events").EventEmitter.defaultMaxListeners = 30;
|
||||
function createBot(options = {}) {
|
||||
const bot = new EventEmitter();
|
||||
const rs = require("randomstring");
|
||||
// Set some default values in options
|
||||
let r = Math.floor(Math.random() * 255) + 1;
|
||||
options.host ??= "localhost";
|
||||
options.username ??= "FNFBoyfriendBot";
|
||||
options.hideErrors ??= false; // HACK: Hide errors by default as a lazy fix to console being spammed with them
|
||||
options.console ??= true;
|
||||
options.input ??= true;
|
||||
|
||||
options.commands.MainPrefix ??= "~";
|
||||
options.commands.SecondaryPrefix ??= "%";
|
||||
options.commands.TertiaryPrefix ??= "&";
|
||||
options.selfcare.unmuted ??= true;
|
||||
|
||||
options.selfcare.vanished ??= true;
|
||||
|
||||
options.selfcare.prefix ??= true;
|
||||
|
||||
options.selfcare.skin ??= true;
|
||||
|
||||
options.selfcare.cspy ??= true;
|
||||
|
||||
options.selfcare.op ??= true;
|
||||
|
||||
options.selfcare.gmc ??= true;
|
||||
|
||||
options.selfcare.interval ??= 500;
|
||||
|
||||
options.selfcare.username ??= true;
|
||||
|
||||
options.selfcare.nickname ??= true;
|
||||
|
||||
options.selfcare.god ??= true;
|
||||
|
||||
options.selfcare.tptoggle ??= true;
|
||||
|
||||
options.discord.commandPrefix ??= "~";
|
||||
|
||||
options.reconnectDelay ??= 1000;
|
||||
|
||||
bot.options = options;
|
||||
|
||||
// Create our client object, put it on the bot, and register some events
|
||||
bot.on("init_client", (client) => {
|
||||
client.on("packet", (data, meta) => {
|
||||
bot.emit("packet", data, meta);
|
||||
bot.emit("packet." + meta.name, data);
|
||||
});
|
||||
|
||||
client.on("login", async function (data) {
|
||||
bot.uuid = client.uuid;
|
||||
bot.username = client.username;
|
||||
bot.entityId = data.entityId;
|
||||
bot.host = bot.options.host;
|
||||
bot.port = bot.options.port;
|
||||
bot.buildstring = process.env["buildstring"];
|
||||
bot.fbs = process.env["FoundationBuildString"];
|
||||
bot.version = bot.options.version;
|
||||
console.log(`Username: ${bot.options.username}`);
|
||||
console.log(`Host: ${bot.options.host}:${bot.options.port}`);
|
||||
console.log(`Minecraft java version: ${bot.options.version}`);
|
||||
/* console.log(`Username: ${bot.username}`)
|
||||
console.log(`Host: ${bot.host}:${bot.port}`)
|
||||
console.log(`Minecraft java version: ${bot.version}`)*/
|
||||
});
|
||||
//reason, fullReason
|
||||
client.on("end", (reason) => {
|
||||
bot.emit("end", reason);
|
||||
console.log(reason);
|
||||
});
|
||||
client.on("disconnect", (reason) => {
|
||||
bot.emit("disconnect", reason);
|
||||
console.log(reason);
|
||||
});
|
||||
|
||||
client.on("kick_disconnect", (reason) => {
|
||||
bot.emit("kick_disconnect", reason);
|
||||
console.log(reason);
|
||||
});
|
||||
client.on("keep_alive", ({ keepAliveId }) => {
|
||||
bot.emit("keep_alive", { keepAliveId });
|
||||
// console.log(keepAliveId)
|
||||
});
|
||||
|
||||
client.on("error", (error) => bot.emit("error", error));
|
||||
|
||||
//client.end(reason, fullReason)
|
||||
});
|
||||
/*
|
||||
bot._client.on('kick_disconnect', (data) => {
|
||||
const parsed = JSON.parse(data.reason)
|
||||
bot.end(parsed, 'kick_disconnect')
|
||||
})
|
||||
|
||||
*/
|
||||
const buildstring = process.env["buildstring"];
|
||||
|
||||
const client = options.client ?? mc.createClient(options);
|
||||
bot._client = client;
|
||||
bot.emit("init_client", client);
|
||||
|
||||
bot.bots = options.bots ?? [bot];
|
||||
//bot.setMaxListeners(Infinity)
|
||||
//bot._client.setMaxListeners(Infinity)
|
||||
|
||||
// Modules
|
||||
bot.loadModule = (module) => module(bot, options);
|
||||
|
||||
for (const filename of fs.readdirSync(path.join(__dirname, "modules"))) {
|
||||
try {
|
||||
const module = require(path.join(__dirname, "modules", filename));
|
||||
bot.loadModule(module);
|
||||
//console.log(filename.length);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"\x1b[0m\x1b[91m[ERROR]: \x1b[0m\x1b[90mFailed to load module",
|
||||
filename,
|
||||
":",
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return bot;
|
||||
} //path.join(__dirname, 'modules', filename)
|
||||
//path.join(amonger + 'FridayNightFunkinBoyfriendBot') !== path.join(amonger)
|
||||
//fs.stat
|
||||
const amonger = "../";
|
||||
if (fs.existsSync("../FridayNightFunkinBoyfriendBot") == false) {
|
||||
process.exit(1);
|
||||
}
|
||||
//path.join('') != fs. existsSync('~/FridayNightFunkinBoyfriendBot/index.js')
|
||||
|
||||
// ABot username function mabe mabe
|
||||
|
||||
module.exports = createBot;
|
||||
@@ -1,74 +0,0 @@
|
||||
const util = require('util')
|
||||
const createBot = require('./bot.js')
|
||||
//const chomensjs = require('./ChomensJS')
|
||||
// TODO: Load a default config
|
||||
const fs = require('fs/promises')
|
||||
const fileExist = require('./util/file-exists')
|
||||
const path = require('path')
|
||||
|
||||
function load () {
|
||||
//const config = require('./config.js')
|
||||
const readline = require('readline')
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
})
|
||||
require('dotenv').config()
|
||||
const bots = []
|
||||
for (const options of config.bots) {
|
||||
const bot = createBot(options)
|
||||
bots.push(bot)
|
||||
bot.bots = bots
|
||||
bot.options.username
|
||||
bot.console.useReadlineInterface(rl)
|
||||
|
||||
// bot.on('error', (error), util.inspect(error))
|
||||
|
||||
try{
|
||||
bot.on('error', console.error)
|
||||
}catch(error){
|
||||
|
||||
console.log(error.stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
async function checkConfig () {
|
||||
if (!await fileExist(path.join(__dirname, 'config.js'))) {
|
||||
console.error('Config not found! Creating a new Config from ')
|
||||
await fs.copyFile(path.join(__dirname, 'default.js'), path.join(__dirname, 'config.js'))
|
||||
} if (await fileExist(path.join(__dirname, 'config.js'))){
|
||||
console.log('Config found! loading config please wait,......')
|
||||
}
|
||||
|
||||
config = require('./config.js')
|
||||
load()
|
||||
}
|
||||
|
||||
checkConfig()
|
||||
|
||||
const modules = "./modules";
|
||||
const util = "./util";
|
||||
const CommandModules = "./CommandModules";
|
||||
const commands = "./commands";
|
||||
const chat = "./chat";
|
||||
fs.readdir(util, (err, files) => {
|
||||
console.log("Successfully loaded: " + files.length + " util files");
|
||||
});
|
||||
fs.readdir(modules, (err, files) => {
|
||||
console.log("Successfully loaded: " + files.length + " module files");
|
||||
});
|
||||
fs.readdir(commands, (err, files) => {
|
||||
console.log("Successfully loaded: " + files.length + " command files");
|
||||
});
|
||||
fs.readdir(CommandModules, (err, files) => {
|
||||
console.log("Successfully loaded: " + files.length + " CommandModule files");
|
||||
});
|
||||
fs.readdir(chat, (err, files) => {
|
||||
console.log("Successfully loaded: " + files.length + " chat files");
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (e) => {
|
||||
console.log('uncaught ' + e.stack)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user