Class: MatrixQQ::Matrix::Forward::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/matrix_qq/matrix/forward/group.rb

Overview

send to qq group

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Group.



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

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

Instance Method Details

#format_matrix_message(msg, name, type = 'm.text') ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/matrix_qq/matrix/forward/group.rb', line 22

def format_matrix_message(msg, name, type = 'm.text')
  room = "{#{@info['send_room']}} " if @info['print_room']
  return "#{room}#{name} 发送了一条消息" if msg =~ /^-msg /
  return '有人发送了一条消息' if msg =~ /^-all /
  return if msg =~ /^- /

  info = type.match(/^m\./).post_match
  info ||= 'text'
  message msg, name, info, room
end

#message(msg, name, type, room = '') ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/matrix_qq/matrix/forward/group.rb', line 33

def message(msg, name, type, room = '')
  case type
  when 'text'
    m = msg.match(/^-name /)
    m ? m.post_match : "#{room}[#{name}] #{msg}"
  when 'notice' then "#{room}[#{name}] notice #{msg}"
  when 'emote' then "#{room}#{name} #{msg}"
  else "#{room}#{name} send a #{type}"
  end
end

#runObject



13
14
15
16
17
18
19
20
# File 'lib/matrix_qq/matrix/forward/group.rb', line 13

def run
  msg = @info['content']
  body = msg['body']
  type = msg['msgtype']
  sender = @info['sender_name']
  message = format_matrix_message(body, sender, type)
  MatrixQQ::QQ::SendGroup.text @matrix, @room, message
end