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

#gen_quoteQuoteMessage

Generates a quote message from this event

Returns:



136
137
138
139
140
141
142
143
144
145
# File 'lib/rubirai/message.rb', line 136

def gen_quote
  QuoteMessage.from(
    id: @message_chain.id,
    group_id: @sender.is_a?(GroupUser) ? @sender.group.id : 0,
    sender_id: @sender.id,
    target_id: @sender.is_a?(GroupUser) ? @sender.group.id : @bot.qq,
    origin: @message_chain.raw,
    bot: @bot
  )
end

#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



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/rubirai/message.rb', line 118

def respond(*msgs, quote: false)
  check_bot
  msgs.prepend(gen_quote) if quote
  case self
  when FriendMessageEvent
    @bot.send_friend_msg(@sender.id, *msgs)
  when GroupMessageEvent
    @bot.send_group_msg(@sender.group.id, *msgs)
  when TempMessageEvent
    @bot.send_temp_msg(@sender.id, @sender.group.id, *msgs)
  else
    raise 'undefined error'
  end
end