Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Parse received messages properly #22

Open
roerohan opened this issue Oct 5, 2021 · 3 comments
Open

Parse received messages properly #22

roerohan opened this issue Oct 5, 2021 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest Hacktoberfest

Comments

@roerohan
Copy link
Member

roerohan commented Oct 5, 2021

For parsing the message, the discord bot splits the message by spaces and identifies each item as a token, as shown below.

const tokens = message.content.trim().split(/ +/g);

This can cause issues in commands like $send, which has the following syntax.

$send #<channel-name> content

In the current code, every token after the second argument is joined with " " (spaces) to create the content, as shown below.

https://github.com/dyte-in/discord-bot/blob/main/src/commands/handlers/send.ts#L38

However, this creates an issue if the content was intended to have multiple spaces somewhere. The proposition in this issue is to be able to parse a space-separated string as a single token if it is wrapped with " (quotes).

This makes the send command like the following, so we don't have any issues if the content has multiple spaces.

$send #<channel-name> "content"

An additional proposition is to also be able to parse a JSON if present, discussion regarding this is welcome in the comments.

@roerohan roerohan added hacktoberfest Hacktoberfest enhancement New feature or request good first issue Good for newcomers labels Oct 5, 2021
@garvsgit
Copy link

garvsgit commented Oct 7, 2021

After updating the tokenization, does it need to accept the old send command also? Or only the new one which guarantees content inside double quotes?
Also is it okay if the content includes the double quotes and we handle the double quotes in the send.ts handler?

@thebongy
Copy link
Member

thebongy commented Oct 7, 2021

Hi @garvsgit

does it need to accept the old send command also?

Yes, we need to accept both formats
so $send #123 content more content would pass 4 arguments (#123, content, more, content) while $send #123 content "more content" would pass 3 arguments (#123, content, more content)

Also is it okay if the content includes the double quotes and we handle the double quotes in the send.ts handler?

We would ideally want to do all arg parsing in the message create method itself, so that command.handler(message, ...args); is passed the right number of args

@roerohan
Copy link
Member Author

roerohan commented Oct 8, 2021

@garvsgit do confirm once if you're taking this up, I'll assign this issue to you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants