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