rockneurotiko/ex_gram

another opinion on `Ignore_username` middleware

TwistingTwists opened this issue · 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?

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

true.

Thanks for headsup!

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