2020-12-21 16:08:38 +00:00
|
|
|
const v = require('vec3')
|
2020-12-24 12:51:44 +00:00
|
|
|
let mcData
|
2020-12-21 16:08:38 +00:00
|
|
|
|
|
|
|
let cfg = {}
|
|
|
|
let bot = {}
|
|
|
|
// bot.chatAddPattern(new RegExp(`^hi|hello ${bot.username}`, "i"), 'greet', "General greeting")
|
|
|
|
|
|
|
|
function todo() {
|
2020-12-22 06:31:46 +00:00
|
|
|
cfg.quiet && console.warn("not implemented") || bot.chat("not implemented yet")
|
2020-12-21 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkBlockExists(name) {
|
|
|
|
if (mcData.blocksByName[name] === undefined) {
|
|
|
|
bot.chat(`${name} is not a block name`)
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function checkItemExists(name) {
|
|
|
|
if (mcData.itemsByName[name] === undefined) {
|
|
|
|
bot.chat(`${name} is not an item name`)
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const events = {
|
2021-05-03 02:14:45 +00:00
|
|
|
whisper: function command_whisper(username, _botusername, message, ...history) {
|
|
|
|
if ([bot.username, "me"].includes(username)) return // whisper back from server (afk msges, etc)
|
2020-12-21 16:08:38 +00:00
|
|
|
if (/^gossip/.test(message)) return
|
|
|
|
if (username === cfg.admin) {
|
2021-05-03 02:14:45 +00:00
|
|
|
console.info("whispered command", _botusername, message)
|
2020-12-21 16:08:38 +00:00
|
|
|
message = message.replace("\\", "@")
|
2021-03-23 18:10:58 +00:00
|
|
|
if (message.startsWith(cfg.botAddressPrefix)) {
|
2020-12-22 06:31:46 +00:00
|
|
|
command(username, message)
|
|
|
|
} else {
|
|
|
|
bot.chat(message)
|
|
|
|
// bot.chat("/" + message)
|
|
|
|
}
|
2020-12-21 16:08:38 +00:00
|
|
|
} else {
|
|
|
|
bot.whisper(cfg.admin, `gossip ${username}: ${message}`)
|
2021-05-03 02:14:45 +00:00
|
|
|
console.info(username, "whispered", _botusername, message)
|
2020-12-21 16:08:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
, chat: command
|
2020-12-24 08:38:16 +00:00
|
|
|
, kicked: function rejoin(reason, loggedIn) {
|
|
|
|
console.warn(reason, loggedIn && "logged_in")
|
|
|
|
if (reason.extra && reason.extra[0].text === "Server closed") {
|
|
|
|
bot.quit()
|
|
|
|
bot.end()
|
|
|
|
// TODO implement all startup features (maybe refactor all into a single function / module?)
|
|
|
|
setTimeout((bot, cfg) => {
|
|
|
|
bot = mineflayer.createBot(cfg.botOptions)
|
|
|
|
}, 15 * 60 * 1000, bot, cfg);
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 08:11:31 +00:00
|
|
|
// , message: systemMessage
|
|
|
|
, messagestr: function systemMessageStr(...args) { console.log("cmd msgstr:", ...args) }
|
2021-04-29 03:37:46 +00:00
|
|
|
, "chat:web": commandWeb
|
2021-04-29 03:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function systemMessage(...args) {
|
|
|
|
if (args[0]?.text) return
|
|
|
|
const metadata = (args[0]?.extra || args[0]?.with)?.map(v => v.text)
|
|
|
|
console.log(
|
|
|
|
"cmd msg:",
|
|
|
|
args[0]?.text || args[0]?.translate,
|
|
|
|
args[0]?.extra?.length || args[0]?.with?.length || Object.keys(args[0]?.json).length - 1,
|
|
|
|
metadata.length > 0 && metadata || args[0],
|
|
|
|
args.slice(1)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-29 03:37:46 +00:00
|
|
|
function commandWeb([[mode, username, message]]) {
|
2021-05-06 08:11:31 +00:00
|
|
|
// console.log("web msg:", mode, username, message)
|
2021-04-29 03:37:46 +00:00
|
|
|
message && command(username, message)
|
|
|
|
}
|
|
|
|
|
2021-04-29 03:24:51 +00:00
|
|
|
function _clientSystemMessage(...args) {
|
2021-05-06 08:15:38 +00:00
|
|
|
console.log("cmd chat:", args[0]?.message, args[0]?.extra?.length, args[0]?.extra, args[0], args.slice(1))
|
2020-12-21 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const events_registered = []
|
|
|
|
|
|
|
|
function command(username, message) {
|
2021-03-23 09:39:07 +00:00
|
|
|
// TODO better name, maybe an array?
|
|
|
|
cfg.botAddressPrefix = cfg.botAddressPrefix || "!"
|
|
|
|
|
2020-12-22 06:31:46 +00:00
|
|
|
function fuzzyRespond(responses, probability = 1, timeout = 1) {
|
|
|
|
if (Math.random() < probability) {
|
|
|
|
const response = responses[Math.floor(Math.random() * responses.length)]
|
|
|
|
return setTimeout(() => bot.chat(response), timeout * Math.random() * 1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function swingArm(swung = 3) {
|
|
|
|
if (swung > 0) {
|
|
|
|
setTimeout(swingArm, 500 * Math.random(), --swung)
|
|
|
|
bot.swingArm()
|
|
|
|
}
|
|
|
|
}
|
2020-12-21 16:08:38 +00:00
|
|
|
|
2021-03-23 09:39:07 +00:00
|
|
|
if (username === bot.username && !message.startsWith(cfg.botAddressPrefix)) return
|
2020-12-21 16:08:38 +00:00
|
|
|
|
|
|
|
const player = bot.players[username] ? bot.players[username].entity : null
|
|
|
|
|
|
|
|
if (message.startsWith("zzz")) {
|
|
|
|
bot.chat("/afk")
|
|
|
|
cfg.plugins.sleeper.sleep()
|
|
|
|
// if(cfg)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 09:39:07 +00:00
|
|
|
if (message.startsWith(cfg.botAddressPrefix) || cfg.botAddressRegex.test(message)) {
|
|
|
|
message = cfg.botAddressRegex.test(message) ? cfg.botAddressRegex.exec(message)[1] : message
|
2020-12-21 16:08:38 +00:00
|
|
|
console.log(message)
|
2021-03-23 09:39:07 +00:00
|
|
|
// remove `!`
|
|
|
|
message = message.startsWith(cfg.botAddressPrefix) ? message.slice(cfg.botAddressPrefix.length) : message
|
|
|
|
|
2020-12-22 06:31:46 +00:00
|
|
|
// TODO command dispatchEvent, for aliases
|
|
|
|
function subcommand(message) {
|
|
|
|
const message_parts = message.split(/\s+/)
|
|
|
|
|
|
|
|
switch (message_parts[0]) {
|
|
|
|
case "stop":
|
|
|
|
bot.pathfinder && bot.pathfinder.setGoal(null)
|
|
|
|
bot.stopDigging()
|
|
|
|
bot.chat("ok")
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "mute":
|
|
|
|
case "quiet":
|
|
|
|
case "silent":
|
|
|
|
cfg.quiet = !cfg.quiet
|
|
|
|
cfg.quiet || bot.chat(`ok, ${cfg.quiet ? "" : "not "}being ${message_parts[0]}`)
|
|
|
|
break;
|
|
|
|
// case "follow":
|
|
|
|
// // if(username === cfg.admin)
|
|
|
|
// cfg.stateMachines.follow.transitions[4].trigger()
|
|
|
|
// // cfg.stateMachines.follow.transitions[1].trigger()
|
|
|
|
// break;
|
|
|
|
// case "stay":
|
|
|
|
// // if(username === cfg.admin)
|
|
|
|
// cfg.stateMachines.follow.transitions[3].trigger()
|
|
|
|
// break;
|
|
|
|
case "echo":
|
|
|
|
// bot.chat(message_parts[1])
|
|
|
|
// bot.chat(message.slice(1))
|
|
|
|
cfg.quiet && bot.whisper(username, message) || bot.chat(message)
|
|
|
|
break;
|
|
|
|
case "autosleep":
|
|
|
|
case "sleep":
|
|
|
|
message_parts[1] = message_parts[0] == "autosleep" ? "auto" : message_parts[1]
|
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "auto":
|
|
|
|
cfg.sleep.auto = !cfg.sleep.auto
|
|
|
|
bot.chat(`ok, ${cfg.sleep.auto ? "" : "not "}auto sleeping`)
|
|
|
|
bot.chat("/afk")
|
2020-12-21 16:08:38 +00:00
|
|
|
break;
|
2020-12-22 06:31:46 +00:00
|
|
|
case "silent":
|
|
|
|
case "quiet":
|
|
|
|
cfg.sleep.quiet = !cfg.sleep.quiet
|
|
|
|
bot.chat(`ok, ${cfg.sleep.quiet ? "" : "not "}sleeping quietly`)
|
|
|
|
break;
|
|
|
|
case "timeout":
|
|
|
|
if (!message_parts[2]) {
|
|
|
|
bot.chat(`sleeping every ${Math.round(cfg.sleep.timeout / 60 / 1000)}mins`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const timeout = parseFloat(message_parts[2], 10)
|
|
|
|
if (timeout) {
|
|
|
|
cfg.sleep.timeout = timeout * 60 * 1000
|
|
|
|
cfg.sleep.timeoutFn = null
|
|
|
|
cfg.plugins.sleeper.sleep(true) //reset timer
|
|
|
|
bot.chat(`ok, next sleep attempt in ${timeout}mins`)
|
2020-12-21 16:08:38 +00:00
|
|
|
break;
|
2020-12-22 06:31:46 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
bot.chat(`usage: !sleep [auto | quiet | timeout <mins>], or zzz for manual sleep`)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break; //todo; needed?
|
|
|
|
case "zzz":
|
|
|
|
cfg.plugins.sleeper.sleep()
|
|
|
|
case "afk":
|
|
|
|
bot.chat("/afk")
|
|
|
|
break;
|
|
|
|
case "awaken":
|
|
|
|
case "wake":
|
|
|
|
case "wakeup":
|
|
|
|
cfg.plugins.sleeper.wake()
|
|
|
|
break;
|
|
|
|
case "autoeat":
|
|
|
|
case "eat":
|
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "auto":
|
|
|
|
cfg.eat.auto = !cfg.eat.auto
|
|
|
|
bot.chat(`ok, ${cfg.eat.auto ? "" : "not "}auto eating `)
|
|
|
|
break;
|
|
|
|
case "at":
|
|
|
|
case "set":
|
|
|
|
const amount = parseInt(message_parts[2], 10)
|
|
|
|
if (amount < 20 && amount > 0) {
|
|
|
|
cfg.eat.startAt = amount
|
|
|
|
cfg.eat.quiet || bot.chat(`ok, eating when hunger at ${amount}`)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case "silent":
|
|
|
|
case "quiet":
|
|
|
|
cfg.eat.quiet = !!!cfg.eat.quiet
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cfg.plugins.eater.eat((err) => { if (err) { bot.chat(err.message) } })
|
|
|
|
// bot.chat(`usage: !sleep [auto | quiet | timeout <mins>], or zzz for manual sleep`)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "follow":
|
2021-01-16 08:50:35 +00:00
|
|
|
switch (message_parts.length) {
|
|
|
|
case 1:
|
|
|
|
subcommand("go follow me")
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
subcommand("go " + message)
|
|
|
|
break;
|
|
|
|
}
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
|
|
|
case "come":
|
2021-01-05 03:11:11 +00:00
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "close":
|
|
|
|
case "closer":
|
|
|
|
subcommand("go follow close")
|
|
|
|
break
|
2021-01-17 08:56:18 +00:00
|
|
|
case "up":
|
|
|
|
case "down":
|
|
|
|
cfg.plugins.mover.moveY(player.position)
|
|
|
|
break
|
2021-01-05 03:11:11 +00:00
|
|
|
default:
|
|
|
|
subcommand("go follow once")
|
|
|
|
}
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
2021-01-26 17:49:23 +00:00
|
|
|
case "ride":
|
|
|
|
case "mount":
|
|
|
|
cfg.plugins.mover.command(message_parts)
|
|
|
|
break
|
|
|
|
case "unride":
|
|
|
|
case "getoff":
|
|
|
|
case "unmount":
|
|
|
|
case "dismount":
|
|
|
|
bot.dismount()
|
2021-01-27 21:24:59 +00:00
|
|
|
bot.vehicle = void 0
|
2021-01-26 17:49:23 +00:00
|
|
|
break
|
2020-12-22 06:31:46 +00:00
|
|
|
case "move":
|
|
|
|
case "go":
|
2021-01-17 18:59:39 +00:00
|
|
|
cfg.plugins.mover.command(message_parts.slice(1), player)
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "attack":
|
|
|
|
case "rage":
|
|
|
|
case "ragemode":
|
|
|
|
case "guard":
|
|
|
|
switch (message_parts.length) {
|
|
|
|
case 1:
|
|
|
|
if (!player) {
|
|
|
|
bot.chat("can't see you.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
bot.chat('for glory!')
|
|
|
|
cfg.plugins.guard.guardArea(player.position)
|
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "self":
|
|
|
|
cfg.guard.self = !cfg.guard.self
|
|
|
|
bot.chat(`ok, ${cfg.guard.self ? "no longer being altruistic" : "self sacrifice!"}`)
|
|
|
|
return;
|
|
|
|
case "stop":
|
|
|
|
cfg.plugins.guard.stopGuarding()
|
|
|
|
bot.chat('no longer guarding this area.')
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
bot.chat("don't know wym")
|
|
|
|
}
|
|
|
|
// entity = new BehaviorGetClosestEntity(bot, bot.nearestEntity(), a => EntityFilters().MobsOnly(a))
|
|
|
|
// if (entity) {
|
|
|
|
// bot.attack(entity, true)
|
|
|
|
// } else {
|
|
|
|
// bot.chat('no nearby entities')
|
|
|
|
// }
|
|
|
|
// // bot.attack(new BehaviorGetClosestEntity(bot, {}, EntityFilters().MobsOnly()))
|
|
|
|
break;
|
|
|
|
case "find":
|
|
|
|
switch (message_parts.length) {
|
|
|
|
case 2:
|
|
|
|
cfg.plugins.finder.findBlocks(message_parts[1])
|
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break
|
2021-01-05 04:30:14 +00:00
|
|
|
// TODO move look (and maybe find) to informer plugin?
|
|
|
|
case "look":
|
2020-12-22 06:31:46 +00:00
|
|
|
case "lookat":
|
|
|
|
// const coords = v(message_parts.splice(1))
|
|
|
|
switch (message_parts.length) {
|
|
|
|
case 1:
|
|
|
|
bot.lookAt(bot.nearestEntity().position)
|
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "me":
|
|
|
|
if (player) {
|
2021-03-23 19:40:54 +00:00
|
|
|
bot.lookAt(player.position.offset(0, 1, 0))
|
2020-12-22 06:31:46 +00:00
|
|
|
} else {
|
|
|
|
cfg.quiet || bot.chat("can't see you")
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "this":
|
|
|
|
// TODO lookat the block the user is looking at
|
2021-01-05 04:30:14 +00:00
|
|
|
// Currently looks player position
|
2020-12-22 06:31:46 +00:00
|
|
|
if (player) {
|
2021-01-05 04:30:14 +00:00
|
|
|
bot.lookAt(player.position)
|
2020-12-22 06:31:46 +00:00
|
|
|
} else {
|
|
|
|
cfg.quiet || bot.chat("can't see you")
|
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
|
2021-03-23 19:40:54 +00:00
|
|
|
if (aPlayer) bot.lookAt(aPlayer.position.offset(0, 1, 0))
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case 3:
|
|
|
|
todo()
|
|
|
|
// bot.lookAt({})
|
|
|
|
break
|
|
|
|
case 4:
|
|
|
|
//TODO more checks
|
|
|
|
bot.lookAt(v(message_parts.splice(1)))
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
break
|
2021-01-05 06:32:33 +00:00
|
|
|
case "info":
|
2021-03-23 10:14:13 +00:00
|
|
|
cfg.plugins.informer.command(message_parts.splice(1), player)
|
2021-01-05 06:32:33 +00:00
|
|
|
break
|
2020-12-22 06:31:46 +00:00
|
|
|
// case "use":
|
|
|
|
// bot.useOn(bot.nearestEntity())
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// // TODO move all inventory related tasks into inventory.js
|
|
|
|
case "craft":
|
|
|
|
cfg.plugins.inventory.craftItem(message_parts[1])
|
|
|
|
break
|
|
|
|
// case "give":
|
|
|
|
// // switch (message_parts[1]) {
|
|
|
|
// // case "hand":
|
|
|
|
// // case "right":
|
|
|
|
// // break;
|
|
|
|
// // case "left":
|
|
|
|
// // break;
|
|
|
|
// // // case "slot":
|
|
|
|
// // default:
|
|
|
|
// // let slot = parseInt(message_parts[1])
|
|
|
|
// // if (!isNaN(slot)) {
|
|
|
|
|
|
|
|
// // } else {
|
|
|
|
|
|
|
|
// // }
|
|
|
|
// // break;
|
|
|
|
// // }
|
|
|
|
// // break;
|
|
|
|
// case "take":
|
|
|
|
// // TODO take only what's requested, then throw all the rest
|
|
|
|
// // TODO take all
|
2020-12-24 14:41:52 +00:00
|
|
|
|
|
|
|
// TODO move subcommands to cfg.plugins.inventory.itemByName
|
|
|
|
case "toss":
|
|
|
|
case "drop":
|
|
|
|
if (!message_parts[1]) { return false } // FIXME, works but ugly
|
|
|
|
if (!mcData.findItemOrBlockByName(message_parts[1])) {
|
|
|
|
console.log("doesn't exist:", message_parts[1])
|
|
|
|
cfg.quiet || bot.chat(`item doesn't exist: ${message_parts[1]}`)
|
|
|
|
return false
|
2020-12-26 19:30:46 +00:00
|
|
|
}
|
|
|
|
const item = cfg.plugins.inventory.itemByName(message_parts[1])
|
|
|
|
if (!item) {
|
2020-12-24 14:41:52 +00:00
|
|
|
console.log("don't have:", message_parts[1])
|
|
|
|
cfg.quiet || bot.chat(`don't have item: ${message_parts[1]}`)
|
2020-12-25 02:29:06 +00:00
|
|
|
return false
|
2020-12-24 14:41:52 +00:00
|
|
|
}
|
|
|
|
switch (message_parts.length) {
|
|
|
|
case 2:
|
|
|
|
bot.tossStack(
|
|
|
|
item,
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
cfg.quiet || bot.chat(err.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
break
|
|
|
|
case 3:
|
|
|
|
const amount = parseInt(message_parts[2])
|
|
|
|
bot.toss(
|
|
|
|
item.type,
|
|
|
|
null, //metadata
|
|
|
|
amount,
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
cfg.quiet || bot.chat(err.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
break;
|
2021-03-22 09:32:08 +00:00
|
|
|
case "sm":
|
|
|
|
case "step":
|
|
|
|
cfg.plugins.statemachine?.command?.(
|
|
|
|
message_parts[0] == "sm" ? message_parts.slice(1) : message_parts, player
|
|
|
|
)
|
|
|
|
// TODO refactor into plugin detection and command exec function
|
|
|
|
// safecommand(plugin_name, message_parts, player)
|
|
|
|
// message_parts includes command?
|
|
|
|
|| bot.chat("statemachine plugin not loaded")
|
|
|
|
break
|
2020-12-22 06:31:46 +00:00
|
|
|
case "location":
|
|
|
|
// TODO put in /lib/location
|
|
|
|
switch (message_parts[1]) {
|
|
|
|
case "add":
|
|
|
|
case "record":
|
2020-12-21 16:08:38 +00:00
|
|
|
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "where":
|
|
|
|
case "where?":
|
|
|
|
// TODO put in /lib/location
|
|
|
|
console.log(bot.entity.position)
|
|
|
|
if (cfg.mods.includes(username)) //anarchy
|
|
|
|
bot.chat(
|
|
|
|
bot.game.dimension.split(":", 2)[1].replace("_", " ")
|
|
|
|
+ " " + bot.entity.position.floored().toString()
|
|
|
|
)
|
|
|
|
break;
|
|
|
|
case "warp":
|
|
|
|
// if (message_parts[1] == "spawn")
|
|
|
|
// if (cfg.mods.includes(username)) //anarchy
|
2020-12-21 16:08:38 +00:00
|
|
|
bot.chat("/" + message)
|
2020-12-22 06:31:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (cfg.mods.includes(username))
|
|
|
|
bot.chat("/" + message)
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
subcommand(message)
|
|
|
|
} else {
|
|
|
|
// TODO, maybe extract to a new function `fuzzychat`?, so can address direct messages
|
|
|
|
switch (message) {
|
|
|
|
case "wassup":
|
|
|
|
case "what's cooking":
|
|
|
|
case "what's new":
|
|
|
|
case "what's up":
|
|
|
|
case "whats cooking":
|
|
|
|
case "whats new":
|
|
|
|
case "whats up":
|
|
|
|
case "sup":
|
|
|
|
case "suh":
|
|
|
|
fuzzyRespond([
|
|
|
|
"jus chilin", "nothin", "random stuff"
|
|
|
|
], 0.3, 3)
|
|
|
|
case "hi":
|
|
|
|
case "hey":
|
|
|
|
case "hello":
|
|
|
|
case "ola":
|
|
|
|
case "howdy":
|
|
|
|
case "heyo":
|
|
|
|
case "yo":
|
2021-03-23 19:40:54 +00:00
|
|
|
if (player) bot.lookAt(player.position.offset(0, 1, 0))
|
2020-12-22 06:31:46 +00:00
|
|
|
|
|
|
|
// TODO sneak
|
|
|
|
// function swingArm() {
|
|
|
|
// if (swung > 0) {
|
|
|
|
// setTimeout(swing, 500 * Math.random())
|
|
|
|
// bot.p()
|
|
|
|
// swung--
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
setTimeout(swingArm, 1000, 4) // or sneak greating
|
|
|
|
return
|
|
|
|
case "F":
|
|
|
|
return fuzzyRespond(["F"], 0.9, 1)
|
|
|
|
case "RIP":
|
|
|
|
return fuzzyRespond(["F", "oh no"], 0.3, 2)
|
|
|
|
case "69":
|
|
|
|
case "cool":
|
|
|
|
Math.random() < 0.5 && bot.chat("nice!")
|
|
|
|
return
|
|
|
|
case "awesome":
|
|
|
|
case "superb":
|
|
|
|
case "nice":
|
|
|
|
case "nice!":
|
|
|
|
return fuzzyRespond(["cool", "very nice!"], 0.3, 5)
|
|
|
|
case "good bot":
|
|
|
|
return fuzzyRespond(["thanks", "why, thank you!", ":)", "(:", "you're too kind!"], 1, 5)
|
|
|
|
case "bad bot":
|
|
|
|
case "not nice":
|
|
|
|
return fuzzyRespond([":(", "):", "sorry"], 0.1, 10)
|
|
|
|
default:
|
2020-12-21 16:08:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const load = (config) => {
|
|
|
|
cfg = config
|
|
|
|
bot = cfg.bot
|
|
|
|
|
2020-12-24 12:51:44 +00:00
|
|
|
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
|
2020-12-21 16:08:38 +00:00
|
|
|
for (const [key, fn] of Object.entries(events)) {
|
|
|
|
events_registered.push(
|
|
|
|
bot.on(key, fn)
|
|
|
|
)
|
|
|
|
}
|
2021-05-06 08:15:38 +00:00
|
|
|
|
|
|
|
// bot._client.on("chat", _clientSystemMessage)
|
2020-12-21 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const unload = () => {
|
|
|
|
console.log("events_registered:", events_registered.length, "of", bot._eventsCount)
|
|
|
|
for (const [key, fn] of Object.entries(events)) {
|
|
|
|
bot.off(key, fn)
|
|
|
|
events_registered.shift()
|
|
|
|
}
|
|
|
|
console.log("events_registered:", bot._eventsCount)
|
2021-05-06 08:15:38 +00:00
|
|
|
|
|
|
|
// bot._client.off("chat", _clientSystemMessage)
|
2020-12-21 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { load, unload, events_registered, command }
|