slack-ruby-bot-server icon indicating copy to clipboard operation
slack-ruby-bot-server copied to clipboard

Don't monkey-patch SlackRubyBot::Client

Open dblock opened this issue 9 years ago • 4 comments

https://github.com/dblock/slack-ruby-bot-server/blob/master/lib/slack-ruby-bot-server/ext/slack-ruby-bot/client.rb contains a monkey patch that adds a client field to SlackRubyBot::Client. That shouldn't be necessary, the client instantiated should be a child of SlackRubyBot::Client.

dblock avatar Jun 02 '16 19:06 dblock

It seems that SlackRubyBot::Client#owner is used inside the sample_app to log team info (team_id, name and domain), but this info is already present in SlackRubyBot::Client#team. I think we can safely remove the monkey patch and modify the sample_app to pull this info from SlackRubyBot::Client#team. What do you think?

tmsrjs avatar Jun 02 '16 19:06 tmsrjs

Possibly, but in most projects you need the actual stored team record with the token (the owner), not info about it after the client boots (which is what is stored as team), or some way to retrieve it, especially on restart. Check out how it's used in say https://github.com/dblock/slack-market.

dblock avatar Jun 02 '16 19:06 dblock

Maybe I'm missing something, but couldn't we just Team.find_by(team_id: client.team.id) lazily when needed? The only scenario I think this could be a problem is if the same mongodb is used to store info for more than one slack-ruby-bot-server and more than one of those bots is added to the same team, but that sounds like bad design anyway.

tmsrjs avatar Jun 02 '16 20:06 tmsrjs

Isn't there a chicken-and-egg problem of knowing client.team.id? I am probably wrong, so as long as we can make it work, amen :)

dblock avatar Jun 02 '16 20:06 dblock