Multiprefix support
This commit is contained in:
parent
b5b803e1e8
commit
3887bbe2ce
4 changed files with 7 additions and 7 deletions
2
bot.js
2
bot.js
|
@ -13,7 +13,6 @@ function createBot (options = {}) {
|
|||
// defaults
|
||||
options.username ??= 'Bot'
|
||||
// options.password = options.password ?? null
|
||||
options.prefix ??= '!'
|
||||
options.brand ??= 'vanilla' // found that mineflayer has this so i added it here lol
|
||||
|
||||
options.styles ??= {}
|
||||
|
@ -51,7 +50,6 @@ function createBot (options = {}) {
|
|||
bot.host = options.host
|
||||
bot.port = options.port
|
||||
|
||||
bot.prefix = options.prefix
|
||||
bot.brand = options.brand
|
||||
bot.styles = options.styles
|
||||
bot.paths = options.paths
|
||||
|
|
|
@ -33,7 +33,7 @@ module.exports = {
|
|||
|
||||
const msg = {
|
||||
color: 'dark_aqua',
|
||||
text: bot.prefix + node.name + ' ',
|
||||
text: node.name + ' ',
|
||||
clickEvent: { action: 'suggest_command', value: bot.prefix + 'help ' + node.name },
|
||||
hoverEvent: { action: 'show_text', value: 'Click to see info about the command' }
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
all: {
|
||||
username: 'chipmunkbot',
|
||||
prefix: "default.",
|
||||
prefixes: ['default.'],
|
||||
colors: { primary: 'green', secondary: 'dark_green', error: 'red' },
|
||||
version: '1.20.4',
|
||||
randomizeUsername: true,
|
||||
|
|
|
@ -28,17 +28,19 @@ const patchedExecuteSource = CommandDispatcher.prototype.execute
|
|||
.replace('context.command(', 'await context.command(')
|
||||
const patchedExecute = eval(`const { ParseResults, StringReader } = require('brigadier-commands'); ({ async ${patchedExecuteSource} })`).execute
|
||||
|
||||
function inject (bot) {
|
||||
function inject (bot, options) {
|
||||
bot.commands = {
|
||||
dispatcher: null,
|
||||
execute,
|
||||
reload,
|
||||
prefixes: options.prefixes ?? ['default.']
|
||||
}
|
||||
|
||||
let cleanups = []
|
||||
|
||||
bot.on('message', ({ sender, plain }) => {
|
||||
if (!plain.startsWith(bot.prefix)) return
|
||||
const prefix = bot.commands.prefixes.find(prefix => plain.startsWith(prefix))
|
||||
if (!prefix) return
|
||||
|
||||
function sendFeedback (message) {
|
||||
bot.tellraw(message, '@a')
|
||||
|
@ -58,7 +60,7 @@ function inject (bot) {
|
|||
text: sender.username
|
||||
}
|
||||
|
||||
bot.commands.execute(plain.substring(bot.prefix.length), new CommandSource({ bot, player: sender, sendFeedback, displayName }))
|
||||
bot.commands.execute(plain.substring(prefix.length), new CommandSource({ bot, player: sender, sendFeedback, displayName }))
|
||||
})
|
||||
|
||||
async function execute (command, source) {
|
||||
|
|
Loading…
Reference in a new issue