Class: MatrixQQ::QQ::ForwardGroup::Matrix
- Inherits:
-
Object
- Object
- MatrixQQ::QQ::ForwardGroup::Matrix
- Defined in:
- lib/matrix_qq/qq/forward_group/matrix.rb
Instance Method Summary collapse
- #gen_image_json(type, uri, w, h, size) ⇒ Object
-
#initialize(dbus, matrix, info, room) ⇒ Matrix
constructor
A new instance of Matrix.
- #matrix_send_image(uri) ⇒ Object
- #message(messages) ⇒ Object
- #run ⇒ Object
- #user(user, group_id = nil) ⇒ Object
Constructor Details
#initialize(dbus, matrix, info, room) ⇒ Matrix
Returns a new instance of Matrix.
5 6 7 8 9 10 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 5 def initialize(dbus, matrix, info, room) @dbus = dbus @info = info @matrix = matrix @room = room end |
Instance Method Details
#gen_image_json(type, uri, w, h, size) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 49 def gen_image_json(type, uri, w, h, size) { body: type, msgtype: 'm.image', url: uri, info: { w: w, h: h, mimetype: type, size: size } }.to_json end |
#matrix_send_image(uri) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 41 def matrix_send_image(uri) mxc = @matrix.upload_file uri w, h = FastImage.size uri open(uri) do |f| gen_image_json(f.content_type, uri, mxc, w, h, f.size) end end |
#message(messages) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 21 def () .inject('') do |obj, msg| obj + case msg['type'] when 'at' "@#{user msg['data']['qq'], @info['group_id']} " else QQ.cq_call msg end end end |
#run ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 12 def run msg = @info['message'] sender = user @info['user_id'], @info['group_id'] room = "{#{@info['group_id']}}" if @info['print_room'] MatrixQQ::Matrix::Send.text \ @matrix, @room, "#{room}[#{sender}] #{msg}" end |
#user(user, group_id = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/matrix_qq/qq/forward_group/matrix.rb', line 31 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 |