Class: MatrixQQ::QQ::ForwardGroup::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix_qq/qq/forward_group/matrix.rb

Overview

send to matrix

Instance Method Summary collapse

Constructor Details

#initialize(dbus, matrix, info, room) ⇒ Matrix

Returns a new instance of Matrix.



6
7
8
9
10
11
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 6

def initialize(dbus, matrix, info, room)
  @dbus = dbus
  @info = info
  @matrix = matrix
  @room = room
end

Instance Method Details

#message(messages) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 19

def message(messages)
  messages.inject('') do |obj, msg|
    obj +
      case msg['type']
      when 'text' then msg['data']['text']
      when 'emoji' then [msg['data']['id'].to_i].pack 'U'
      when 'face' then "[QQ 表情:#{msg['data']['id']}]"
      when 'record' then '[语音]'
      when 'image' then msg['data']['url']
      end
  end
end

#runObject



13
14
15
16
17
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 13

def run
  msg = message @info['message']
  sender = user @info['user_id'], @info['group_id']
  MatrixQQ::Matrix::Send.text @matrix, @room, "[#{sender}] #{msg}"
end

#user(user, group_id = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 32

def user(user, group_id = nil)
  if group_id.nil?
    return @dbus.get_stranger_info(user_id: user)['nickname']
  end
  info = @dbus.get_group_member_info(user_id: user, group_id: group_id)
  info = info['data']
  name = info['card']
  name == '' ? info['nickname'] : name
end