Last active
May 25, 2019 10:15
-
-
Save MaksimAbramchuk/da84477311279a9fa97cf0e6cda651bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BotMessageDispatcher | |
| attr_reader :message, :user | |
| def initialize(message, user) | |
| @message = message | |
| @user = user | |
| end | |
| def process | |
| if user.get_next_bot_command | |
| bot_command = user.get_next_bot_command.safe_constantize.new(user, message) | |
| if bot_command.should_start? | |
| bot_command.start | |
| else | |
| unknown_command | |
| end | |
| else | |
| start_command = BotCommand::Start.new(user, message) | |
| if start_command.should_start? | |
| start_command.start | |
| else | |
| unknown_command | |
| end | |
| end | |
| end | |
| private | |
| def unknown_command | |
| BotCommand::Undefined.new(user, message).start | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment