Class: MatrixQQ::Matrix::Forward::Group
- Inherits:
-
Object
- Object
- MatrixQQ::Matrix::Forward::Group
- Defined in:
- lib/matrix_qq/matrix/forward/group.rb
Overview
send to qq group
Instance Method Summary collapse
- #format_matrix_message(msg, name, type = 'm.text') ⇒ Object
-
#initialize(dbus, matrix, info, room) ⇒ Group
constructor
A new instance of Group.
- #match_bot(message) ⇒ Object
- #message(msg, name, type) ⇒ Object
- #run ⇒ Object
- #user(user) ⇒ Object
- #user_bot(message) ⇒ Object
- #user_bot?(message) ⇒ Boolean
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 (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' msg, name, info end |
#match_bot(message) ⇒ Object
48 49 50 |
# File 'lib/matrix_qq/matrix/forward/group.rb', line 48 def match_bot() .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 (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 |
#run ⇒ Object
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, (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() m = match_bot return unless m [m[2], m.post_match] end |
#user_bot?(message) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/matrix_qq/matrix/forward/group.rb', line 52 def user_bot?() m = match_bot return true if m false end |