mogus
This commit is contained in:
parent
5a69865919
commit
9c23572db3
7 changed files with 75 additions and 55 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -108,8 +108,10 @@ config.js
|
|||
config.json
|
||||
|
||||
# Other
|
||||
config.json5
|
||||
logs
|
||||
music
|
||||
images
|
||||
videos
|
||||
functions
|
||||
persistent
|
||||
|
|
52
index.js
52
index.js
|
@ -1,36 +1,36 @@
|
|||
const readline = require('readline')
|
||||
const { createBots } = require('./bot.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const moment = require('moment')
|
||||
const json5 = require('json5')
|
||||
|
||||
if (!fs.existsSync('config.json5')) {
|
||||
fs.copyFileSync(path.join(__dirname, 'default.json5'), 'config.json')
|
||||
console.info('No config file was found, so a default one was created.')
|
||||
}
|
||||
const config = json5.parse(fs.readFileSync('config.json5', 'utf-8'))
|
||||
|
||||
const logdir = 'logs'
|
||||
if (!fs.existsSync(logdir)) fs.mkdirSync(logdir)
|
||||
|
||||
let logfile = path.join(logDir, moment().format('YYYY-MM-DD'))
|
||||
if (fs.existsSync(logfile)) {
|
||||
const pathWithSeparator = logfile + '-'
|
||||
let i = 0
|
||||
while (fs.existsSync(logfile)) {
|
||||
logfile = pathWithSeparator + (i++)
|
||||
}
|
||||
}
|
||||
filepath += '.log'
|
||||
fs.writeFileSync(logfile, '')
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
prefix: '> '
|
||||
})
|
||||
|
||||
const { createBots } = require('./bot.js')
|
||||
// const commandHandler = require('./commands.js')
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const moment = require('moment')
|
||||
|
||||
const logDir = 'logs'
|
||||
if (!fs.existsSync(logDir)) fs.mkdirSync(logDir)
|
||||
|
||||
let filepath = path.join(logDir, moment().format('YYYY-MM-DD'))
|
||||
if (fs.existsSync(filepath)) {
|
||||
const pathWithSeparator = filepath + '-'
|
||||
let i = 0
|
||||
while (fs.existsSync(filepath)) {
|
||||
filepath = pathWithSeparator + (i++)
|
||||
}
|
||||
}
|
||||
filepath += '.log'
|
||||
fs.writeFileSync(filepath, '')
|
||||
|
||||
const servers = [
|
||||
'play.kaboom.pw:25565:kaboom',
|
||||
'chipmunk.land:25565:kaboom'
|
||||
]
|
||||
|
||||
const bots = createBots(servers, {
|
||||
username: ' ',
|
||||
prefix: "'",
|
||||
|
|
43
package-lock.json
generated
43
package-lock.json
generated
|
@ -11,6 +11,7 @@
|
|||
"brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git",
|
||||
"colorsys": "^1.0.22",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"json5": "^2.2.3",
|
||||
"kahoot.js-api": "^2.4.0",
|
||||
"minecraft-protocol": "^1.26.5",
|
||||
"moment": "^2.29.1",
|
||||
|
@ -1991,14 +1992,14 @@
|
|||
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
|
||||
},
|
||||
"node_modules/json5": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz",
|
||||
"integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0"
|
||||
},
|
||||
"version": "2.2.3",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||
"bin": {
|
||||
"json5": "lib/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/jsonwebtoken": {
|
||||
|
@ -3360,6 +3361,17 @@
|
|||
"strip-bom": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tsconfig-paths/node_modules/json5": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz",
|
||||
"integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.0"
|
||||
},
|
||||
"bin": {
|
||||
"json5": "lib/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
|
@ -4985,12 +4997,9 @@
|
|||
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
|
||||
},
|
||||
"json5": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz",
|
||||
"integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
"version": "2.2.3",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg=="
|
||||
},
|
||||
"jsonwebtoken": {
|
||||
"version": "9.0.2",
|
||||
|
@ -6000,6 +6009,16 @@
|
|||
"json5": "^1.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
"strip-bom": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"json5": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz",
|
||||
"integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==",
|
||||
"requires": {
|
||||
"minimist": "^1.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tweetnacl": {
|
||||
|
|
|
@ -3,15 +3,16 @@
|
|||
"@mozilla/readability": "^0.4.1",
|
||||
"@skeldjs/client": "^2.15.17",
|
||||
"@tonejs/midi": "^2.0.27",
|
||||
"brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git",
|
||||
"colorsys": "^1.0.22",
|
||||
"fluent-ffmpeg": "^2.1.2",
|
||||
"json5": "^2.2.3",
|
||||
"kahoot.js-api": "^2.4.0",
|
||||
"minecraft-protocol": "^1.26.5",
|
||||
"moment": "^2.29.1",
|
||||
"prismarine-nbt": "^2.2.0",
|
||||
"rfb2": "^0.2.2",
|
||||
"standard": "^16.0.4",
|
||||
"urban-dictionary": "git+https://code.chipmunk.land/ChipmunkMC/urban-dictionary.git",
|
||||
"brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git"
|
||||
"urban-dictionary": "git+https://code.chipmunk.land/ChipmunkMC/urban-dictionary.git"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ function inject (bot) {
|
|||
bot.on('message', (player, message) => {
|
||||
if (!message.startsWith(bot.prefix)) return
|
||||
|
||||
const sendFeedback = message => bot.core.run('minecraft:tellraw @a ' + JSON.stringify(message))
|
||||
function sendFeedback (message) {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify(message))
|
||||
}
|
||||
bot.commands.execute(message.substring(bot.prefix.length), new CommandSource({ bot, sendFeedback }))
|
||||
})
|
||||
|
||||
|
@ -32,7 +34,13 @@ function inject (bot) {
|
|||
if (isValid(command)) {
|
||||
bot.console.warn(`Command '${command.aliases[0]}' is using the legacy command system!`)
|
||||
|
||||
const _execute = args => command.execute(bot, command.aliases[0], {}, args)
|
||||
const _execute = args => {
|
||||
try {
|
||||
command.execute(bot, command.aliases[0], {}, args)
|
||||
} catch (error) {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({ text: error.toString(), color: 'red' }))
|
||||
}
|
||||
}
|
||||
|
||||
const node = bot.commands.dispatcher.register(
|
||||
literal(command.aliases[0])
|
||||
|
|
|
@ -82,8 +82,8 @@ function inject (bot) {
|
|||
}
|
||||
}
|
||||
|
||||
function sendFeedback (message) {console.log(message)
|
||||
const { raw } = parseText(message);console.log(raw)
|
||||
function sendFeedback (message) {
|
||||
const { raw } = parseText(message)
|
||||
bot.console.log(raw)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
function inject (bot, client) {
|
||||
bot.players ??= {}
|
||||
|
||||
client.on('player_info', (packet) => {
|
||||
if (packet.action === 0) {
|
||||
packet.data.forEach((player) => {
|
||||
bot.players[player.name] = player
|
||||
bot.players[player.UUID] = player
|
||||
if (player.UUID === bot._client.uuid) { bot.player = player }
|
||||
})
|
||||
}
|
||||
})
|
||||
bot
|
||||
}
|
||||
|
||||
module.exports.client = inject
|
||||
|
|
Loading…
Reference in a new issue