matrix_qq 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a87444b9fff9f46cfe1d8dea2ffff5512ad4ee88
4
- data.tar.gz: 6d5287af230d319461f80320ef0414e08375bbba
3
+ metadata.gz: 565d456e004a986b188f1ce4844883786e30d307
4
+ data.tar.gz: bc9c7c39c4c8be44beaf834fc713d2b6bbb8f0d8
5
5
  SHA512:
6
- metadata.gz: 835685f46ee11bc834ca28f8ff3c73cec1d1aca9d39a794405f75ac5b2ab715683dfb1f5a8702d8484fb165f7db60a4edc737f2ae1fc0dcbb01d7513fceb6eaa
7
- data.tar.gz: 9c4db86f440af128ba0d3ba03eecd9905eb84967eeb7144415c5b5dfcf9e36110dd97261d237c74ac86d109755e2f81c479116b768f110cd0bdfafe16927ea5d
6
+ metadata.gz: c84807ae0c75593ca4266d15fc18e5e25d5d6d7dd254ee1214bb9a02bfbc41490b4d605d8709402e668fc8e1233699330233502a59b61d69cc138581caf3a005
7
+ data.tar.gz: 460f1877875aa6d31f766fcc88a38100d065e42277620307932aafc1437934247eec1d3fe762fedd40dc0ed78a5318dd0663cecfcad475d10562bfdf610de605
data/CHANGELOG.yaml CHANGED
@@ -1,7 +1,14 @@
1
1
  # Notice: Incompatible items start with `!`
2
2
  0.2.1:
3
- Fix:
4
- - Lock ignore list now
3
+ Feature:
4
+ - Matrix send message will add forword parm
5
+ - CQ code parse
6
+ - utils:
7
+ log
8
+ Change:
9
+ - Start/End with uuid
10
+ - One step json parse
11
+ - move log to utils
5
12
  0.2.0:
6
13
  Change:
7
14
  - ! config file add `.rb`
@@ -26,7 +26,7 @@ module MatrixQQ
26
26
  def each_event(events, tunnel)
27
27
  events.each do |event|
28
28
  next unless event['type'] == 'm.room.message'
29
- next if exist @info['event_id']
29
+ next if exist event['content']['forword']
30
30
  tunnel[:to].each_pair do |to_room, type|
31
31
  call_module(event, to_room, type)
32
32
  end
@@ -41,10 +41,9 @@ module MatrixQQ
41
41
  end
42
42
  end
43
43
 
44
- def exist(event_id)
45
- MatrixQQ::Matrix::Send.ignore_lock.synchronize do
46
- MatrixQQ::Matrix::Send.ignore.delete(event_id)
47
- end
44
+ def exist(forword)
45
+ return false if forword.nil?
46
+ !forword
48
47
  end
49
48
  end # Forward
50
49
 
@@ -30,21 +30,14 @@ module MatrixQQ
30
30
  def reg
31
31
  SIGN.each do |i|
32
32
  @dbus.obj.on_signal i.to_s do |json|
33
- parse json
34
- info = @info
33
+ info = JSON.parse json
35
34
  Matrix.send(i).each do |func|
36
- puts "Start #{func.name}" if $VERBOSE
37
- func.new(@dbus, @qq_dbus, info.dup).run
38
- puts "End #{func.name}" if $VERBOSE
35
+ MatrixQQ.log(func.name) do
36
+ func.new(@dbus, @qq_dbus, info.dup).run
37
+ end
39
38
  end
40
39
  end
41
40
  end
42
41
  end
43
-
44
- private
45
-
46
- def parse(json)
47
- @info = JSON.parse json
48
- end
49
42
  end
50
43
  end
@@ -1,19 +1,11 @@
1
1
  module MatrixQQ
2
2
  class Matrix
3
3
  module Send
4
- class << self
5
- attr_accessor :ignore, :ignore_lock
6
- end
7
- self.ignore = []
8
- self.ignore_lock = Mutex.new
9
-
10
4
  def self.raw(dbus, room_id, event_type, body)
11
- ignore_lock.synchronize do
12
- txn_id = SecureRandom.hex(32)
13
- puts "send #{body}" if $VERBOSE
14
- res = dbus.put "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body
15
- ignore << (res['event_id'])
16
- end
5
+ txn_id = SecureRandom.hex(32)
6
+ puts "send #{body}" if $VERBOSE
7
+ uri = "/rooms/#{room_id}/send/#{event_type}/#{txn_id}"
8
+ dbus.put uri, body.merge(forword: false)
17
9
  end
18
10
 
19
11
  def self.text(dbus, room_id, message)
@@ -18,14 +18,12 @@ module MatrixQQ
18
18
 
19
19
  def message(messages)
20
20
  messages.inject('') do |obj, msg|
21
- obj +
22
- case msg['type']
23
- when 'text' then msg['data']['text']
24
- when 'emoji' then [msg['data']['id'].to_i].pack 'U'
25
- when 'face' then "[QQ 表情:#{msg['data']['id']}]"
26
- when 'record' then '[语音]'
27
- when 'image' then msg['data']['url']
28
- end
21
+ obj + case msg['type']
22
+ when 'at' then
23
+ "@#{user msg['data']['qq'], @info['group_id']} "
24
+ when 'image' then msg['data']['url']
25
+ else QQ.cq_call msg
26
+ end
29
27
  end
30
28
  end
31
29
 
@@ -17,14 +17,10 @@ module MatrixQQ
17
17
 
18
18
  def message(messages)
19
19
  messages.inject('') do |obj, msg|
20
- obj +
21
- case msg['type']
22
- when 'text' then msg['data']['text']
23
- when 'emoji' then [msg['data']['id'].to_i].pack 'U'
24
- when 'face' then "[QQ 表情:#{msg['data']['id']}]"
25
- when 'record' then '[语音]'
26
- when 'image' then msg['data']['url']
27
- end
20
+ obj + case msg['type']
21
+ when 'at' then "@#{user msg['data']['qq'], @info['group_id']} "
22
+ else QQ.cq_call msg
23
+ end
28
24
  end
29
25
  end
30
26
 
@@ -23,6 +23,23 @@ module MatrixQQ
23
23
  end
24
24
  SIGN.each { |i| QQ.send (i.to_s + '='), [] }
25
25
 
26
+ CQ = {
27
+ 'text' => ->(msg) { msg['data']['text'] },
28
+ 'face' => ->(msg) { "[QQ 表情:#{msg['data']['id']}]" },
29
+ 'bface' => ->(msg) { "[QQ 原创表情:#{msg['data']['id']}]" },
30
+ 'sface' => ->(msg) { "[QQ 小表情:#{msg['data']['id']}]" },
31
+ 'emoji' => ->(msg) { [msg['data']['id'].to_i].pack 'U' },
32
+ 'record' => ->(___) { '[语音]' },
33
+ 'image' => ->(msg) { msg['data']['url'] },
34
+ 'at' => ->(msg) { "@#{msg['data']['qq']} " },
35
+ 'rps' => ->(msg) { "[#{%w[石头 剪刀 布][msg['data']['type'] - 1]}]" },
36
+ 'dice' => ->(msg) { "[掷得 #{msg['data']['type']} 点]" },
37
+ 'shake' => ->(___) { '[窗口抖动]' },
38
+ 'music' => ->(msg) { "[音乐 #{msg['data'].to_json}]" },
39
+ 'share' => ->(msg) { "[分享 #{msg['data'].to_json}]" },
40
+ 'anonymous' => ->(___) { '[匿名消息:]' }
41
+ }.freeze
42
+
26
43
  attr_reader :dbus, :info
27
44
  attr_accessor :matrix_dbus
28
45
 
@@ -34,21 +51,22 @@ module MatrixQQ
34
51
  def reg
35
52
  SIGN.each do |i|
36
53
  @dbus.obj.on_signal i.to_s do |json|
37
- parse json
38
- info = @info
54
+ info = JSON.parse json
39
55
  QQ.send(i).each do |func|
40
- puts "Start #{func.name}" if $VERBOSE
41
- func.new(@dbus, @matrix_dbus, info.dup).run
42
- puts "End #{func.name}" if $VERBOSE
56
+ MatrixQQ.log(func.name) do
57
+ func.new(@dbus, @matrix_dbus, info.dup).run
58
+ end
43
59
  end
44
60
  end
45
61
  end
46
62
  end
47
63
 
48
- private
49
-
50
- def parse(json)
51
- @info = JSON.parse json
64
+ def self.cq_call(msg)
65
+ m = QQ::CQ[msg['type']]
66
+ raise "Unknow type #{msg['type']}" if m.nil?
67
+ m = m.call(msg)
68
+ return '' if m.nil?
69
+ m
52
70
  end
53
71
  end
54
72
  end
@@ -0,0 +1,14 @@
1
+ module MatrixQQ
2
+ class << self
3
+ def log(name, call = nil)
4
+ uuid = SecureRandom.uuid
5
+ puts "Start #{name} -- #{uuid}" if $VERBOSE
6
+ if call.nil?
7
+ yield
8
+ else
9
+ call.call
10
+ end
11
+ puts "End #{name} -- #{uuid}" if $VERBOSE
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module MatrixQQ
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/matrix_qq.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'dbus'
2
2
  require 'json'
3
3
  require 'securerandom'
4
+ require 'concurrent'
4
5
 
5
6
  require 'matrix_qq/version'
6
7
 
data/matrix_qq.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'ruby-dbus', '~> 0.14.0'
26
26
  spec.add_dependency 'matrix_dbus', '~> 1.0'
27
27
  spec.add_dependency 'CQHTTP', '~> 2.2'
28
+ spec.add_dependency 'concurrent-ruby'
28
29
  end
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.2.1
4
+ version: 0.3.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-10-29 00:00:00.000000000 Z
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: concurrent-ruby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description:
98
112
  email:
99
113
  - DAStudio.71e6fd52@gmail.com
@@ -129,6 +143,7 @@ files:
129
143
  - lib/matrix_qq/qq/qq.rb
130
144
  - lib/matrix_qq/qq/require.rb
131
145
  - lib/matrix_qq/qq/send.rb
146
+ - lib/matrix_qq/utils.rb
132
147
  - lib/matrix_qq/version.rb
133
148
  - matrix_qq.gemspec
134
149
  homepage: https://github.com/71e6fd52/matrix_qq