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

another opinion on Ignore_username middleware #70

Open
TwistingTwists opened this issue Sep 25, 2021 · 2 comments
Open

another opinion on Ignore_username middleware #70

TwistingTwists opened this issue Sep 25, 2021 · 2 comments

Comments

@TwistingTwists
Copy link

TwistingTwists commented Sep 25, 2021

https://github.com/rockneurotiko/ex_gram/blob/master/lib/ex_gram/middleware/ignore_username.ex#L28

Another way to write this is :

defp clean_command("/" <> text, username) do
  String.split(text, "@") |> List.first()
end

This handles both the cases of text being /command@username and "/command"
we are not even using username
Am I missing any case?

@rockneurotiko
Copy link
Owner

If you see the code it does different things:

  1. It forces the username to be the bot's username, so we don't clean other bot's commands or weird texts, this is done to avoid false positives with commands. You can see the username being used here on the match (^username)
  2. It just cleans the username from the command, the text received could be something like /test@bot with other @user, that would be transformed to /test with other @user, but the bot can receive /test with other @user directly, and just doing the split with @ would return weird things

@TwistingTwists
Copy link
Author

TwistingTwists commented Sep 27, 2021

true.

Thanks for headsup!

EDIT: in my case /test with other @user is interpreted as /test command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants