ex_gram icon indicating copy to clipboard operation
ex_gram copied to clipboard

another opinion on `Ignore_username` middleware

Open TwistingTwists opened this issue 3 years ago • 2 comments

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?

TwistingTwists avatar Sep 25 '21 06:09 TwistingTwists

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

rockneurotiko avatar Sep 27 '21 09:09 rockneurotiko

true.

Thanks for headsup!

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

TwistingTwists avatar Sep 27 '21 14:09 TwistingTwists