Class: Schatter::Command::ReplyToMessage

Inherits:
Object
  • Object
show all
Includes:
Index
Defined in:
lib/schatter/command/reply_to_message.rb

Constant Summary

Constants included from Index

Index::LETTERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#from_index, #to_index

Constructor Details

#initialize(conversation, context) ⇒ ReplyToMessage

Returns a new instance of ReplyToMessage.



8
9
10
11
12
13
# File 'lib/schatter/command/reply_to_message.rb', line 8

def initialize conversation, context
  @conversation = conversation
  @context = context
  @usage = '<index> <content>'
  @help = 'Replies to the specified message'
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/schatter/command/reply_to_message.rb', line 6

def context
  @context
end

#conversationObject (readonly)

Returns the value of attribute conversation.



6
7
8
# File 'lib/schatter/command/reply_to_message.rb', line 6

def conversation
  @conversation
end

#helpObject (readonly)

Returns the value of attribute help.



6
7
8
# File 'lib/schatter/command/reply_to_message.rb', line 6

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



6
7
8
# File 'lib/schatter/command/reply_to_message.rb', line 6

def usage
  @usage
end

Instance Method Details

#execute(text) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/schatter/command/reply_to_message.rb', line 15

def execute text
  index, content = context.head_tail text
  message = conversation.messages.values[from_index(index)]
  unless message
    puts "invalid index #{index}"
    return
  end
  conversation.create_message content: content, parent_id: message.uuid
end