chip mc moment
(i forgor about these)
This commit is contained in:
parent
58ee5bd502
commit
a18c1c74db
9 changed files with 10957 additions and 0 deletions
139
bot.js
Normal file
139
bot.js
Normal file
|
@ -0,0 +1,139 @@
|
|||
const mc = require('minecraft-protocol')
|
||||
const { states } = mc
|
||||
const { EventEmitter } = require('events')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const randomUsername = require('./util/random-username.js')
|
||||
|
||||
function createBot (options = {}) {
|
||||
// defaults
|
||||
options.username ??= 'Bot'
|
||||
// options.password = options.password ?? null
|
||||
options.prefix ??= '!'
|
||||
options.isBukkit ??= false
|
||||
options.isKaboom ??= false
|
||||
options.isScissors ??= false
|
||||
|
||||
options.plugins ??= {}
|
||||
fs.readdirSync(
|
||||
'plugins'
|
||||
).forEach(filename => { // populate plugins array
|
||||
if (typeof require.extensions[path.extname(filename)] && options.plugins[filename] == null) {
|
||||
options.plugins[filename] = require(path.resolve('plugins', filename))
|
||||
}
|
||||
})
|
||||
const plugins = []
|
||||
Object.keys(options.plugins).forEach((key) => {
|
||||
const plugin = options.plugins[key]
|
||||
if (plugin) plugins.push(plugin)
|
||||
})
|
||||
|
||||
options.colors ??= {}
|
||||
options.colors.primary ??= 'white'
|
||||
options.colors.secondary ??= 'green'
|
||||
|
||||
options.autoReconnect ??= false
|
||||
options.autoReconnectDelay ??= 1000
|
||||
options.randomizeUsername ??= false
|
||||
|
||||
options['online-mode'] ??= {}
|
||||
options['online-mode'].enabled ??= false
|
||||
options['online-mode'].username ??= null
|
||||
options['online-mode'].password ??= null
|
||||
options['online-mode'].auth ??= 'mojang'
|
||||
|
||||
const clientOptions = { // TODO: More options
|
||||
connect: options.connect,
|
||||
host: options.server.host,
|
||||
port: options.server.port,
|
||||
version: options.version,
|
||||
username: options['online-mode'].enabled ? options['online-mode'].username : options.username,
|
||||
password: options['online-mode'].enabled ? options['online-mode'].username : null,
|
||||
auth: options['online-mode'].enabled ? options['online-mode'].auth : null
|
||||
}
|
||||
|
||||
if (options.randomizeUsername) {
|
||||
clientOptions.username += randomUsername()
|
||||
}
|
||||
|
||||
// actually create the bot
|
||||
const bot = new EventEmitter()
|
||||
bot.plugins = plugins
|
||||
bot.loadPlugin = loadPlugin
|
||||
|
||||
// add some properties to the bot
|
||||
bot.server = options.server
|
||||
/* bot._client.on('set_protocol', (packet) => {
|
||||
bot.host = packet.serverHost
|
||||
bot.port = packet.serverPort
|
||||
}) */
|
||||
bot.prefix = options.prefix
|
||||
bot.colors = options.colors
|
||||
bot.autoReconnect = options.autoReconnect
|
||||
bot.randomizeUsername = options.randomizeUsername
|
||||
bot['online-mode'] = options['online-mode']
|
||||
// set the client and add listeners
|
||||
bot.on('set_client', (client) => {
|
||||
client.on('connect', () => bot.emit('connect'))
|
||||
client.on('error', (err) => bot.emit('error', err))
|
||||
|
||||
bot.disconnect = reason => bot._client.end(reason)
|
||||
bot.end = reason => {
|
||||
bot.autoReconnect = false
|
||||
bot.disconnect()
|
||||
}
|
||||
client.on('end', (reason) => {
|
||||
bot.loggedIn = false
|
||||
bot.emit('disconnect', reason)
|
||||
// auto reconnect
|
||||
if (bot.autoReconnect) {
|
||||
setTimeout(() => {
|
||||
if (bot.randomizeUsername && !bot['online-mode'].enabled) clientOptions.username = randomUsername()
|
||||
|
||||
bot._client = mc.createClient(clientOptions)
|
||||
bot.emit('set_client', bot._client)
|
||||
}, options.autoReconnectDelay)
|
||||
} else {
|
||||
bot.emit('end', reason)
|
||||
}
|
||||
})
|
||||
|
||||
// more event listeners
|
||||
bot._client.on('state', state => {
|
||||
bot.state = state
|
||||
bot.emit('state', state)
|
||||
})
|
||||
bot._client.on('login', data => bot.emit('login', data))
|
||||
|
||||
// plugin injection
|
||||
bot.plugins.forEach(plugin => {
|
||||
if (typeof plugin.client === 'function') plugin.client(bot, options)
|
||||
})
|
||||
})
|
||||
bot._client = options.client ?? mc.createClient(clientOptions)
|
||||
bot.emit('set_client', bot._client)
|
||||
|
||||
bot.on('login', () => {
|
||||
bot.username = bot._client.username
|
||||
bot.uuid = bot._client.uuid
|
||||
})
|
||||
|
||||
bot.plugins.forEach(plugin => {
|
||||
if (typeof plugin.bot === 'function') plugin.bot(bot, options)
|
||||
})
|
||||
|
||||
function loadPlugin (plugin) {
|
||||
try {
|
||||
if (typeof plugin.bot === 'function') plugin.bot(bot, options)
|
||||
if (typeof plugin.client === 'function') plugin.client(bot, options)
|
||||
bot.plugins.push(plugin)
|
||||
} catch (err) {
|
||||
console.log(`Error loading ${plugin}:`)
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
|
||||
return bot
|
||||
}
|
||||
|
||||
module.exports = createBot
|
96
commands.js
Normal file
96
commands.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const cperms = require('./cperms2.js')
|
||||
|
||||
let commands = {}
|
||||
|
||||
function addCommand (command) {
|
||||
if (!isValid(command)) throw new Error(`Command ${command} is invalid.`)
|
||||
|
||||
if (commands[command] == null) { commands[command] = command }
|
||||
command.aliases.forEach((alias) => {
|
||||
alias = alias.toLowerCase()
|
||||
if (commands[alias] == null) commands[alias] = command
|
||||
})
|
||||
}
|
||||
|
||||
function load () {
|
||||
fs.readdirSync(
|
||||
path.join(__dirname, 'commands')
|
||||
).forEach((file) => {
|
||||
if (file.endsWith('.js')) {
|
||||
const command = path.join(__dirname, 'commands', file)
|
||||
try {
|
||||
const cmd = require(command)
|
||||
addCommand(cmd)
|
||||
} catch (e) {
|
||||
console.log(`Error loading command ${command}:`)
|
||||
console.log(require('util').inspect(e))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function reload () {
|
||||
try {
|
||||
Object.keys(commands).forEach(key => {
|
||||
const command = commands[key]
|
||||
delete require.cache[command.path]
|
||||
})
|
||||
} catch (err) { }
|
||||
commands = {}
|
||||
load()
|
||||
}
|
||||
|
||||
function execute (bot, command, player, args, ...custom) {
|
||||
const cmd = info(command)
|
||||
if (!cmd.enabled) { return bot.core.run(`/bcraw &cThe command ${bot.prefix}${command} is disabled.`) }
|
||||
|
||||
if (cmd.permLevel > 0) {
|
||||
if (args.length < 1) {
|
||||
bot.core.run('/bcraw &cYou must provide a code to run this command.')
|
||||
return
|
||||
}
|
||||
|
||||
const code = args.splice(-1, 1)[0].replace(/\u00a7.?/g, '')
|
||||
|
||||
if (!cperms.validate(cmd.permLevel, player.name, code)) {
|
||||
bot.core.run(`/tellraw @a ${JSON.stringify([
|
||||
{ text: `Invalid code: ${code}.`, color: bot.colors.error }
|
||||
])}`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return cmd.execute(bot, command, player, args, module.exports, ...custom)
|
||||
} catch (err) {
|
||||
console.log(`Error executing command ${command}:`)
|
||||
console.log(err)
|
||||
|
||||
bot.core.run(`/tellraw @a ${JSON.stringify({ text: err.message, color: bot.colors.error })}`)
|
||||
}
|
||||
}
|
||||
|
||||
function info (command) {
|
||||
return commands[command]
|
||||
}
|
||||
|
||||
function isCommand (command) {
|
||||
return commands[command] != null
|
||||
}
|
||||
|
||||
function isValid (command) {
|
||||
return command != null &&
|
||||
typeof command.execute === 'function' &&
|
||||
typeof command.name === 'string' &&
|
||||
typeof command.description === 'string' &&
|
||||
Array.isArray(command.usages) &&
|
||||
Array.isArray(command.aliases) &&
|
||||
typeof command.enabled === 'boolean' &&
|
||||
command.aliases.length > 0 &&
|
||||
typeof command.permLevel === 'number'
|
||||
}
|
||||
|
||||
module.exports = { addCommand, load, reload, execute, info, isCommand, isValid, commands }
|
20
config.js
Normal file
20
config.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
module.exports = [
|
||||
{
|
||||
username: 'ChipmunkBot',
|
||||
prefix: "'",
|
||||
colors: { primary: 'green', secondary: 'dark_green', error: 'red' },
|
||||
version: '1.18.2',
|
||||
randomizeUsername: true,
|
||||
autoReconnect: true,
|
||||
autoReconnectDelay: 6000,
|
||||
server: {
|
||||
host: 'kitsune.icu',
|
||||
port: 61530,
|
||||
isBukkit: true,
|
||||
isKaboom: true,
|
||||
isScissors: true,
|
||||
isAyunBoom: false
|
||||
},
|
||||
trustedKey: 'among us'
|
||||
}
|
||||
]
|
20
default.js
Normal file
20
default.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
module.exports = [
|
||||
{
|
||||
username: 'ChipmunkBot',
|
||||
prefix: "'",
|
||||
colors: { primary: 'green', secondary: 'dark_green', error: 'red' },
|
||||
version: '1.18.2',
|
||||
randomizeUsername: true,
|
||||
autoReconnect: true,
|
||||
autoReconnectDelay: 6000,
|
||||
server: {
|
||||
host: 'localhost',
|
||||
port: 25565,
|
||||
isBukkit: true,
|
||||
isKaboom: true,
|
||||
isScissors: true,
|
||||
isAyunBoom: false
|
||||
},
|
||||
trustedKey: 'among us'
|
||||
}
|
||||
]
|
62
index.js
Normal file
62
index.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
const readline = require('readline')
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
prefix: '> '
|
||||
})
|
||||
|
||||
const createBot = require('./bot.js')
|
||||
// const commandHandler = require('./commands.js')
|
||||
|
||||
const fs = require('fs/promises')
|
||||
const path = require('path')
|
||||
const moment = require('moment')
|
||||
|
||||
async function exists (filepath) {
|
||||
try {
|
||||
await fs.access(filepath)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async function main () {
|
||||
let logPath = path.join('logs', moment().format('YYYY-MM-DD'))
|
||||
if (await exists(logPath)) {
|
||||
const suffixed = logPath + '-'
|
||||
let i = 0
|
||||
while (await exists(logPath)) {
|
||||
logPath = suffixed + (i++)
|
||||
}
|
||||
}
|
||||
await fs.writeFile(logPath, '')
|
||||
|
||||
const absolutePath = path.resolve('config')
|
||||
let optionsArray
|
||||
|
||||
try {
|
||||
optionsArray = require(absolutePath)
|
||||
} catch {
|
||||
await fs.copyFile(path.join(__dirname, 'default.js'), 'config.js')
|
||||
console.info('No config file was found, so a default one was created.')
|
||||
|
||||
optionsArray = require(absolutePath)
|
||||
}
|
||||
|
||||
const bots = []
|
||||
|
||||
optionsArray.forEach((options, index) => {
|
||||
const bot = createBot(options)
|
||||
|
||||
bot.getBots = () => bots
|
||||
bot.on('error', console.error)
|
||||
bot.console.filepath = logPath
|
||||
bot.console.setRl(rl)
|
||||
bot.commands.loadFromDir('commands')
|
||||
|
||||
bots.push(bot)
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
10584
package-lock.json
generated
Normal file
10584
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
package.json
Normal file
28
package.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@mozilla/readability": "^0.4.1",
|
||||
"@skeldjs/client": "^2.15.17",
|
||||
"@tonejs/midi": "^2.0.27",
|
||||
"axios": "^0.27.2",
|
||||
"badwords": "^1.0.0",
|
||||
"canvas": "^2.9.1",
|
||||
"colorsys": "^1.0.22",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"fs": "^0.0.1-security",
|
||||
"kahoot.js-api": "^2.4.0",
|
||||
"minecraft-protocol": "^1.35.0",
|
||||
"mojangson": "^2.0.2",
|
||||
"moment": "^2.29.1",
|
||||
"namemc": "^1.8.16",
|
||||
"node-fetch": "^3.2.3",
|
||||
"path": "^0.12.7",
|
||||
"prismarine-nbt": "^2.2.0",
|
||||
"rfb2": "^0.2.2",
|
||||
"standard": "^16.0.4",
|
||||
"tmp": "^0.2.1",
|
||||
"translate": "^1.4.1",
|
||||
"urban-dictionary": "^3.0.2",
|
||||
"vm2": "^3.9.9",
|
||||
"wikipedia": "^1.1.9"
|
||||
}
|
||||
}
|
1
persistent.json
Normal file
1
persistent.json
Normal file
File diff suppressed because one or more lines are too long
7
start.sh
Normal file
7
start.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
while true
|
||||
do
|
||||
echo Starting Bot
|
||||
node .
|
||||
echo Restarting Bot in 6 Seconds...
|
||||
sleep 6
|
||||
done
|
Loading…
Reference in a new issue