Class: Slacks::Conversation
- Inherits:
-
Object
- Object
- Slacks::Conversation
- Defined in:
- lib/slacks/conversation.rb
Instance Method Summary collapse
- #ask(question, expect: nil) ⇒ Object
- #end! ⇒ Object
- #includes?(e) ⇒ Boolean
-
#initialize(session, channel, sender) ⇒ Conversation
constructor
A new instance of Conversation.
- #listen_for(*args, &block) ⇒ Object
- #reply(*messages) ⇒ Object (also: #say)
Constructor Details
#initialize(session, channel, sender) ⇒ Conversation
Returns a new instance of Conversation.
6 7 8 9 10 11 12 13 |
# File 'lib/slacks/conversation.rb', line 6 def initialize(session, channel, sender) @session = session raise NotInChannelError, channel if channel.guest? @channel = channel @sender = sender @listeners = ThreadSafe::Array.new end |
Instance Method Details
#ask(question, expect: nil) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/slacks/conversation.rb', line 31 def ask(question, expect: nil) listen_for(*Array(expect)) do |e| e.stop_listening! yield e end reply question end |
#end! ⇒ Object
40 41 42 |
# File 'lib/slacks/conversation.rb', line 40 def end! listeners.each(&:stop_listening!) end |
#includes?(e) ⇒ Boolean
22 23 24 |
# File 'lib/slacks/conversation.rb', line 22 def includes?(e) e.channel.id == channel.id && e.sender.id == sender.id end |
#listen_for(*args, &block) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/slacks/conversation.rb', line 15 def listen_for(*args, &block) session.listen_for(*args, &block).tap do |listener| listener.conversation = self listeners.push listener end end |
#reply(*messages) ⇒ Object Also known as: say
26 27 28 |
# File 'lib/slacks/conversation.rb', line 26 def reply(*) channel.reply(*) end |