Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"chat" event is emitted when commands are run. #3464

Open
1 task done
BF5258 opened this issue Sep 26, 2024 · 2 comments
Open
1 task done

"chat" event is emitted when commands are run. #3464

BF5258 opened this issue Sep 26, 2024 · 2 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@BF5258
Copy link

BF5258 commented Sep 26, 2024

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.20.1
  • server: vanilla 1.20.4
  • node: 20.15.1

Steps to reproduce

bot.on('chat', (username, message) => { console.log(username); console.log(message) }
Connect to the same server as the bot.
Run any command. I ran /give andy stick 2. (andy was the name of the bot)

Observed behavior

The following was logged in console:

BF5258
Gave 2 [stick] to andy]

Expected behavior

Nothing should be logged in console. The 'chat' event should not be triggered. No one has chatted.
If this is intended behavior, why don't command blocks emit the same message?

Additional context

When the command is run the following system message is sent:
[BF5258: Gave 2 [stick] to andy]
The regular expression used to detect chat catches this despite it being in square brackets.
The expression used: /^(?:\(.{1,15}\)|\[.{1,15}\]|.){0,5}?(\w+)\s?[>:\-»\]\)~]+\s(.*)$

mineflayer\lib\plugins\chat.js line 3,4:

const USERNAME_REGEX = '(?:\\(.{1,15}\\)|\\[.{1,15}\\]|.){0,5}?(\\w+)'
const LEGACY_VANILLA_CHAT_REGEX = new RegExp(`^${USERNAME_REGEX}\\s?[>:\\-»\\]\\)~]+\\s(.*)$`)

Solutions include changing USERNAME_REGEX to not match the square brackets or ignoring 'chat.type.admin' messages.
Why does the username regex have wildcards on the start and end?

@BF5258 BF5258 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Sep 26, 2024
@MightyPiggie
Copy link

A command starts with / so yeah when using a \ instead like you did it would produce a chat event.

@BF5258
Copy link
Author

BF5258 commented Oct 5, 2024

A command starts with /

Thank you for correcting my mistake. I have updated the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

2 participants