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

Simple way to handle any bot mentions #128

Open
gsmetal opened this issue Apr 12, 2017 · 4 comments
Open

Simple way to handle any bot mentions #128

gsmetal opened this issue Apr 12, 2017 · 4 comments
Labels

Comments

@gsmetal
Copy link

gsmetal commented Apr 12, 2017

I needed to handle any message that mentions bot. I didn't find how to do this simply and came to a little dirty scan:

  scan(/\<@([[:alnum:][:punct:]]*)\>/) do |client, data, user_ids|
    next unless user_ids.flatten.any? { |u_id| client.users[u_id].name == client.name }
    # ...
  end

Is there better way to achieve this? If not, I think it should be.

@dblock
Copy link
Collaborator

dblock commented Apr 13, 2017

I think this is about right, but since you know the name upfront you could put it inside the scan with /bot|mybot|whateverbot/ if you want to optimize.

I'd love this documented in README, please?

@dblock
Copy link
Collaborator

dblock commented Apr 13, 2017

Actually even better, maybe we should add a supported handler like mention do |client, data, ...| that wraps this up with tests & al? That'd be a great PR.

@gsmetal
Copy link
Author

gsmetal commented Apr 13, 2017

Actually even better, maybe we should add a supported handler like mention do |client, data, ...| that wraps this up with tests & al?

Yes, that's what I was talking about 👍 I'll try to make PR when I have time.

but since you know the name upfront you could put it inside the scan with /bot|mybot|whateverbot/ if you want to optimize

The problem is that as far as I undestand name is known only on after-connect time in client as I didn't configure it anywhere. That's why I came to this and asked better solution.

@dblock
Copy link
Collaborator

dblock commented Apr 14, 2017

You're right @gsmetal. I also think whatever you come up with could work for any mention, so it could support mention do ... which would be a bot mention and mention do "dblock" that would be mentioning anyone else or even mentions do |array_of_people|, etc.

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

No branches or pull requests

2 participants