lib/matrix_qq/matrix/forward/group.rb in matrix_qq-0.3.3 vs lib/matrix_qq/matrix/forward/group.rb in matrix_qq-0.4.0
- old
+ new
@@ -48,10 +48,11 @@
message = format_matrix_message(body, sender, type)
MatrixQQ::QQ::SendGroup.array @matrix, @room, emoji(message)
end
def emoji(msg)
+ return { type: 'text', data: { text: msg } } if (msg & Emoji).empty?
msg.each_codepoint.inject([]) do |obj, code|
obj <<
if Emoji.include? code
{ type: 'emoji', data: { id: code.to_s } }
else
@@ -59,26 +60,27 @@
end
end
end
def format_matrix_message(msg, name, type = 'm.text')
- return "#{name} 发送了一条消息" if msg =~ /^-msg /
+ 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
+ message msg, name, info, room
end
- def message(msg, name, type)
+ def message(msg, name, type, room = '')
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}"
+ 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 #{info}"
end
end
def user(user)
@dbus.get("/profile/#{user}/displayname")['displayname']