Compare commits
No commits in common. "72c4622091639edd84d2c0fae14a736ba17fb759" and "1597acca727192688dd6361461a81a8cb993f850" have entirely different histories.
72c4622091
...
1597acca72
|
@ -86,9 +86,7 @@ reloadplugin = (event, filename, pluginpath) => {
|
||||||
fs.watch('./lib/plugins', reloadplugin)
|
fs.watch('./lib/plugins', reloadplugin)
|
||||||
|
|
||||||
cfg.bot = bot
|
cfg.bot = bot
|
||||||
// TODO better name, or switch to array
|
cfg.botAddress = new RegExp(`^${bot.username} (!.+)`)
|
||||||
cfg.botAddressPrefix = '!'
|
|
||||||
cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`)
|
|
||||||
cfg.quiet = true
|
cfg.quiet = true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,6 @@ const events = {
|
||||||
const events_registered = []
|
const events_registered = []
|
||||||
|
|
||||||
function command(username, message) {
|
function command(username, message) {
|
||||||
// TODO better name, maybe an array?
|
|
||||||
cfg.botAddressPrefix = cfg.botAddressPrefix || "!"
|
|
||||||
|
|
||||||
function fuzzyRespond(responses, probability = 1, timeout = 1) {
|
function fuzzyRespond(responses, probability = 1, timeout = 1) {
|
||||||
if (Math.random() < probability) {
|
if (Math.random() < probability) {
|
||||||
const response = responses[Math.floor(Math.random() * responses.length)]
|
const response = responses[Math.floor(Math.random() * responses.length)]
|
||||||
|
@ -79,7 +76,7 @@ function command(username, message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username === bot.username && !message.startsWith(cfg.botAddressPrefix)) return
|
if (username === bot.username && !message.startsWith("!")) return
|
||||||
|
|
||||||
const player = bot.players[username] ? bot.players[username].entity : null
|
const player = bot.players[username] ? bot.players[username].entity : null
|
||||||
|
|
||||||
|
@ -91,12 +88,11 @@ function command(username, message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (message.startsWith(cfg.botAddressPrefix) || cfg.botAddressRegex.test(message)) {
|
if (message.startsWith("!") || cfg.botAddress.test(message)) {
|
||||||
message = cfg.botAddressRegex.test(message) ? cfg.botAddressRegex.exec(message)[1] : message
|
message = cfg.botAddress.test(message) ? cfg.botAddress.exec(message)[1] : message
|
||||||
console.log(message)
|
|
||||||
// remove `!`
|
|
||||||
message = message.startsWith(cfg.botAddressPrefix) ? message.slice(cfg.botAddressPrefix.length) : message
|
|
||||||
|
|
||||||
|
console.log(message)
|
||||||
|
message = message.slice(1) // remove `!`
|
||||||
// TODO command dispatchEvent, for aliases
|
// TODO command dispatchEvent, for aliases
|
||||||
function subcommand(message) {
|
function subcommand(message) {
|
||||||
const message_parts = message.split(/\s+/)
|
const message_parts = message.split(/\s+/)
|
||||||
|
@ -331,7 +327,7 @@ function command(username, message) {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "info":
|
case "info":
|
||||||
cfg.plugins.informer.command(message_parts.splice(1), player)
|
cfg.plugins.informer.command(message_parts.splice(1))
|
||||||
break
|
break
|
||||||
// case "use":
|
// case "use":
|
||||||
// bot.useOn(bot.nearestEntity())
|
// bot.useOn(bot.nearestEntity())
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
let cfg
|
let cfg
|
||||||
let bot
|
let bot
|
||||||
let mcData
|
let mcData
|
||||||
// import v from 'vec3'
|
|
||||||
const v = require('vec3')
|
const v = require('vec3')
|
||||||
|
|
||||||
function block(pos) {
|
function block(pos) {
|
||||||
|
@ -52,47 +51,34 @@ function item(
|
||||||
}
|
}
|
||||||
|
|
||||||
function entity(name) {
|
function entity(name) {
|
||||||
const entity = typeof name === "string" ? bot.nearestEntity((entity) => {
|
const entity = bot.nearestEntity((entity) => {
|
||||||
const ename = entity.name || entity.username
|
const ename = entity.name || entity.username
|
||||||
return name && ename ? ename == name : true
|
return name && ename ? ename == name : true
|
||||||
}) : entity
|
})
|
||||||
console.log(entity)
|
console.log(entity)
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
cfg.quiet || bot.chat("no entity")
|
cfg.quiet || bot.chat("no entity")
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
let info = [entity.type, entity.username || entity.name]
|
let info = [entity.type, entity.name || entity.username]
|
||||||
// TODO various info depending on the type of entity; player, villager, etc
|
|
||||||
if (entity.metadata) info.push("len: " + entity.metadata.length)
|
if (entity.metadata) info.push("len: " + entity.metadata.length)
|
||||||
cfg.quiet || bot.chat(info.join("; "))
|
cfg.quiet || bot.chat(info.join("; "))
|
||||||
return entity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function command(message_parts, player) {
|
function command(message_parts) {
|
||||||
if (message_parts.length > 0) {
|
|
||||||
cfg.info.recentCommand = message_parts
|
|
||||||
}
|
|
||||||
switch (message_parts.length) {
|
switch (message_parts.length) {
|
||||||
case 0:
|
case 0:
|
||||||
if (cfg.info.recentCommand) {
|
// TODO most recent command?
|
||||||
command(cfg.info.recentCommand, player)
|
block()
|
||||||
} else {
|
|
||||||
// TODO dispatch on instance of entity, block, etc..
|
|
||||||
// TODO have the logic inside the function or with a utility function
|
|
||||||
block(player.position || player?.entity.position || null)
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
switch (message_parts[0]) {
|
switch (message_parts[0]) {
|
||||||
case "i":
|
|
||||||
case "item":
|
case "item":
|
||||||
item()
|
item()
|
||||||
break
|
break
|
||||||
case "e":
|
|
||||||
case "entity":
|
case "entity":
|
||||||
entity()
|
entity()
|
||||||
break
|
break
|
||||||
case "b":
|
|
||||||
case "block":
|
case "block":
|
||||||
default:
|
default:
|
||||||
block()
|
block()
|
||||||
|
@ -103,11 +89,9 @@ function command(message_parts, player) {
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
switch (message_parts[0]) {
|
switch (message_parts[0]) {
|
||||||
case "i":
|
|
||||||
case "item":
|
case "item":
|
||||||
item(message_parts[1])
|
item(message_parts[1])
|
||||||
break
|
break
|
||||||
case "e":
|
|
||||||
case "entity":
|
case "entity":
|
||||||
default:
|
default:
|
||||||
entity(message_parts[1])
|
entity(message_parts[1])
|
||||||
|
@ -117,7 +101,6 @@ function command(message_parts, player) {
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
switch (message_parts[0]) {
|
switch (message_parts[0]) {
|
||||||
case "b":
|
|
||||||
case "block":
|
case "block":
|
||||||
default:
|
default:
|
||||||
block(message_parts.slice(1))
|
block(message_parts.slice(1))
|
||||||
|
@ -127,7 +110,6 @@ function command(message_parts, player) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cfg.quiet || bot.chat("info: unknown command")
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +119,6 @@ const load = (config) => {
|
||||||
bot = cfg.bot
|
bot = cfg.bot
|
||||||
cfg.info = {
|
cfg.info = {
|
||||||
quiet: cfg.quiet,
|
quiet: cfg.quiet,
|
||||||
recentCommand: null,
|
|
||||||
}
|
}
|
||||||
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
|
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/PrismarineJS/prismarine-template#readme",
|
"homepage": "https://github.com/PrismarineJS/prismarine-template#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^14.14.35",
|
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"require-self": "^0.2.3",
|
"require-self": "^0.2.3",
|
||||||
"typescript": "^4.2.3"
|
"typescript": "^4.2.3"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user