Class: Rubirai::MessageEvent Abstract

Inherits:
Event
  • Object
show all
Defined in:
lib/rubirai/events/message_events.rb,
lib/rubirai/message.rb

Overview

This class is abstract.

The base class for message events

Instance Attribute Summary collapse

Attributes inherited from Event

#bot, #raw

Instance Method Summary collapse

Methods inherited from Event

parse, #parse_val_from_key, set_event, type_to_klass, valid_type?

Instance Attribute Details

#message_chainMessageChain (readonly)

Returns the message chain.

Returns:



13
# File 'lib/rubirai/events/message_events.rb', line 13

set_event nil, :message_chain, :sender

#senderUser (readonly)

Returns the sender.

Returns:

  • (User)

    the sender



13
# File 'lib/rubirai/events/message_events.rb', line 13

set_event nil, :message_chain, :sender

Instance Method Details

#respond(*msgs, quote: false) ⇒ Integer

Respond to a message event

Parameters:

  • msgs (Array<Rubirai::Message, Hash, String, Object>)

    messages to form a chain

  • quote (Boolean) (defaults to: false)

    if to quote the original message

Returns:

  • (Integer)

    message id



125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/rubirai/message.rb', line 125

def respond(*msgs, quote: false)
  check_bot
  quote_id = quote ? (@message_chain.id || nil) : nil
  case self
  when FriendMessageEvent
    @bot.send_friend_msg(@sender.id, *msgs, quote: quote_id)
  when GroupMessageEvent
    @bot.send_group_msg(@sender.group.id, *msgs, quote: quote_id)
  when TempMessageEvent
    @bot.send_temp_msg(@sender.id, @sender.group.id, *msgs, quote: quote_id)
  else
    raise 'undefined error'
  end
end