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



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

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

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

#match_bot(message) ⇒ Object



48
49
50
# File 'lib/matrix_qq/matrix/forward/group.rb', line 48

def match_bot(message)
  message.match(/^(\(.*?\))?\[(.*?)\]\s*/)
end

#message(msg, name, type) ⇒ 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)
  case type
  when 'text'
    m = msg.match(/^-name /)
    m ? m.post_match : "[#{name}] #{msg}"
  when 'notice' then "[#{name}] notice #{msg}"
  when 'emote' then "#{name} #{msg}"
  else "#{name} send a #{info}"
  end
end

#runObject



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

def run
  msg = @info['content']
  body = msg['body']
  type = msg['msgtype']
  sender = user @info['sender']
  sender, body = user_bot body if user_bot? body
  MatrixQQ::QQ::SendGroup.text \
    @matrix, @room, format_matrix_message(body, sender, type)
end

#user(user) ⇒ Object



44
45
46
# File 'lib/matrix_qq/matrix/forward/group.rb', line 44

def user(user)
  @dbus.get("/profile/#{user}/displayname")['displayname']
end

#user_bot(message) ⇒ Object



58
59
60
61
62
# File 'lib/matrix_qq/matrix/forward/group.rb', line 58

def user_bot(message)
  m = match_bot message
  return unless m
  [m[2], m.post_match]
end

#user_bot?(message) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/matrix_qq/matrix/forward/group.rb', line 52

def user_bot?(message)
  m = match_bot message
  return true if m
  false
end