matrix_qq 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.yaml +10 -2
- data/exe/matrix_qq +5 -0
- data/lib/matrix_qq/matrix/forward/group.rb +9 -7
- data/lib/matrix_qq/matrix/forward/main.rb +23 -5
- data/lib/matrix_qq/qq/forward_group/main.rb +20 -4
- data/lib/matrix_qq/qq/forward_group/matrix.rb +22 -4
- data/lib/matrix_qq/utils.rb +7 -0
- data/lib/matrix_qq/version.rb +1 -1
- data/lib/matrix_qq.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b10cb473c23ae57054f29f317828d51d3e0cc3a0
|
4
|
+
data.tar.gz: 84d52dfe120fd743b2bd54e12699ba07a478c97e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 364aae41c69bc800fff31dfe978b3fffaae1d4343b6a0370d4d494a50b1dcd85d428891dce95bd6fe7eb8af3e33fd6293d9c2d541c1a024e2f4a877f29820744
|
7
|
+
data.tar.gz: cad73b838a627235490481f37284c8cfa4440b8a1d640119576f9cbbd2073453e6987871698f9f9ca1a7941fc971db10321815eaa279020eb07d6fb93afff93a
|
data/CHANGELOG.yaml
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# Notice: Incompatible items start with `!`
|
2
2
|
|
3
|
-
0.
|
3
|
+
0.4.0:
|
4
4
|
Feature:
|
5
5
|
- msgtype rich
|
6
|
+
- matrix forword support all
|
7
|
+
- all matrix can formord to group
|
8
|
+
- group forword support all
|
9
|
+
- all group can formord to matrix
|
10
|
+
- utils:
|
11
|
+
- intercept?
|
12
|
+
Change:
|
13
|
+
- merge text if haven't emoji
|
6
14
|
0.3.2:
|
7
15
|
Feature:
|
8
16
|
- Emoji support
|
@@ -14,7 +22,7 @@
|
|
14
22
|
- Matrix send message will add forword parm
|
15
23
|
- CQ code parse
|
16
24
|
- utils:
|
17
|
-
log
|
25
|
+
- log
|
18
26
|
Change:
|
19
27
|
- Start/End with uuid
|
20
28
|
- One step json parse
|
data/exe/matrix_qq
CHANGED
@@ -18,8 +18,13 @@ unless File.size? config
|
|
18
18
|
# },
|
19
19
|
# '10000' => {
|
20
20
|
# type: 'friend',
|
21
|
+
# intercept: false,
|
21
22
|
# to: { '!abcdef:matrix.org' => 'matrix' }
|
22
23
|
# }
|
24
|
+
# 'friend' => {
|
25
|
+
# type: 'all',
|
26
|
+
# to: { '#friend:matrix.org' => 'matrix' }
|
27
|
+
# }
|
23
28
|
}
|
24
29
|
}
|
25
30
|
end)
|
@@ -50,6 +50,7 @@ module MatrixQQ
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def emoji(msg)
|
53
|
+
return { type: 'text', data: { text: msg } } if (msg & Emoji).empty?
|
53
54
|
msg.each_codepoint.inject([]) do |obj, code|
|
54
55
|
obj <<
|
55
56
|
if Emoji.include? code
|
@@ -61,23 +62,24 @@ module MatrixQQ
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def format_matrix_message(msg, name, type = 'm.text')
|
64
|
-
|
65
|
+
room = "{#{@info['send_room']}} " if @info['print_room']
|
66
|
+
return "#{room}#{name} 发送了一条消息" if msg =~ /^-msg /
|
65
67
|
return '有人发送了一条消息' if msg =~ /^-all /
|
66
68
|
return if msg =~ /^- /
|
67
69
|
|
68
70
|
info = type.match(/^m\./).post_match
|
69
71
|
info ||= 'text'
|
70
|
-
message msg, name, info
|
72
|
+
message msg, name, info, room
|
71
73
|
end
|
72
74
|
|
73
|
-
def message(msg, name, type)
|
75
|
+
def message(msg, name, type, room = '')
|
74
76
|
case type
|
75
77
|
when 'text'
|
76
78
|
m = msg.match(/^-name /)
|
77
|
-
m ? m.post_match : "[#{name}] #{msg}"
|
78
|
-
when 'notice' then "[#{name}] notice #{msg}"
|
79
|
-
when 'emote' then "#{name} #{msg}"
|
80
|
-
else "#{name} send a #{info}"
|
79
|
+
m ? m.post_match : "#{room}[#{name}] #{msg}"
|
80
|
+
when 'notice' then "#{room}[#{name}] notice #{msg}"
|
81
|
+
when 'emote' then "#{room}#{name} #{msg}"
|
82
|
+
else "#{room}#{name} send a #{info}"
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
@@ -16,17 +16,35 @@ module MatrixQQ
|
|
16
16
|
def run
|
17
17
|
return unless @info.is_a? Hash
|
18
18
|
@info.each_pair do |room, value|
|
19
|
-
|
20
|
-
|
21
|
-
next unless tunnel[:type] == 'matrix'
|
22
|
-
each_event value['timeline']['events'], tunnel
|
19
|
+
all = run_exact room, value
|
20
|
+
run_all room, value if all
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
24
|
+
def run_exact(room, value)
|
25
|
+
tunnel = Config[:tunnel][room]
|
26
|
+
return false if tunnel.nil?
|
27
|
+
return false unless tunnel[:type] == 'matrix'
|
28
|
+
each_event value['timeline']['events'], tunnel
|
29
|
+
MatrixQQ.intercept? tunnel
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_all(room, value)
|
33
|
+
tunnel = Config[:tunnel]['matrix']
|
34
|
+
return if tunnel.nil?
|
35
|
+
return unless tunnel[:type] == 'all'
|
36
|
+
each_event \
|
37
|
+
value['timeline']['events'],
|
38
|
+
tunnel,
|
39
|
+
print_room: true,
|
40
|
+
send_room: room
|
41
|
+
end
|
42
|
+
|
43
|
+
def each_event(events, tunnel, hackin = {})
|
27
44
|
events.each do |event|
|
28
45
|
next unless event['type'] == 'm.room.message'
|
29
46
|
next if exist event['content']['forword']
|
47
|
+
event.merge!(hackin)
|
30
48
|
tunnel[:to].each_pair do |to_room, type|
|
31
49
|
call_module(event, to_room, type)
|
32
50
|
end
|
@@ -15,18 +15,34 @@ module MatrixQQ
|
|
15
15
|
|
16
16
|
def run
|
17
17
|
return unless @info.is_a? Hash
|
18
|
+
all = run_exact room, value
|
19
|
+
run_all room, value if all
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_exact
|
18
23
|
tunnel = Config[:tunnel][@info['group_id'].to_s]
|
24
|
+
return false if tunnel.nil?
|
25
|
+
return false unless tunnel[:type] == 'group'
|
26
|
+
tunnel[:to].each_pair do |room, type|
|
27
|
+
call_module room, type
|
28
|
+
end
|
29
|
+
MatrixQQ.intercept? tunnel
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_all
|
33
|
+
tunnel = Config[:tunnel]['group']
|
19
34
|
return if tunnel.nil?
|
20
|
-
return unless tunnel[:type] == '
|
35
|
+
return unless tunnel[:type] == 'all'
|
21
36
|
tunnel[:to].each_pair do |room, type|
|
22
|
-
call_module
|
37
|
+
call_module room, type, print_room: true
|
23
38
|
end
|
24
39
|
end
|
25
40
|
|
26
|
-
def call_module(room, type)
|
41
|
+
def call_module(room, type, hackin = {})
|
42
|
+
info = @info.merge hackin
|
27
43
|
ForwardGroup.send_to[type.to_s].each do |func|
|
28
44
|
puts "Start #{func.name}" if $VERBOSE
|
29
|
-
func.new(@dbus, @matrix,
|
45
|
+
func.new(@dbus, @matrix, info, room).run
|
30
46
|
puts "End #{func.name}" if $VERBOSE
|
31
47
|
end
|
32
48
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module MatrixQQ
|
2
2
|
class QQ
|
3
3
|
class ForwardGroup
|
4
|
-
# send to matrix
|
5
4
|
class Matrix
|
6
5
|
def initialize(dbus, matrix, info, room)
|
7
6
|
@dbus = dbus
|
@@ -13,15 +12,17 @@ module MatrixQQ
|
|
13
12
|
def run
|
14
13
|
msg = message @info['message']
|
15
14
|
sender = user @info['user_id'], @info['group_id']
|
16
|
-
|
15
|
+
room = "{#{@info['group_id']}}" if @info['print_room']
|
16
|
+
MatrixQQ::Matrix::Send.text \
|
17
|
+
@matrix, @room,
|
18
|
+
"#{room}[#{sender}] #{msg}"
|
17
19
|
end
|
18
20
|
|
19
21
|
def message(messages)
|
20
22
|
messages.inject('') do |obj, msg|
|
21
23
|
obj + case msg['type']
|
22
|
-
when 'at'
|
24
|
+
when 'at'
|
23
25
|
"@#{user msg['data']['qq'], @info['group_id']} "
|
24
|
-
when 'image' then msg['data']['url']
|
25
26
|
else QQ.cq_call msg
|
26
27
|
end
|
27
28
|
end
|
@@ -36,6 +37,23 @@ module MatrixQQ
|
|
36
37
|
name = info['card']
|
37
38
|
name == '' ? info['nickname'] : name
|
38
39
|
end
|
40
|
+
|
41
|
+
def matrix_send_image(uri)
|
42
|
+
mxc = @matrix.upload_file uri
|
43
|
+
w, h = FastImage.size uri
|
44
|
+
open(uri) do |f|
|
45
|
+
gen_image_json(f.content_type, uri, mxc, w, h, f.size)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def gen_image_json(type, uri, w, h, size)
|
50
|
+
{
|
51
|
+
body: type,
|
52
|
+
msgtype: 'm.image',
|
53
|
+
url: uri,
|
54
|
+
info: { w: w, h: h, mimetype: type, size: size }
|
55
|
+
}.to_json
|
56
|
+
end
|
39
57
|
end # Matrix
|
40
58
|
|
41
59
|
ForwardGroup.send_to['matrix'] << Matrix
|
data/lib/matrix_qq/utils.rb
CHANGED
data/lib/matrix_qq/version.rb
CHANGED
data/lib/matrix_qq.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matrix_qq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 71e6fd52
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|