CQHTTP 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 +4 -4
- data/CQHTTP.gemspec +2 -0
- data/exe/cqhttp-dbus +53 -0
- data/lib/CQHTTP/service.rb +42 -0
- data/lib/CQHTTP/version.rb +1 -1
- data/lib/CQHTTP.rb +3 -2
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1af39bae6b5ce49f4525cb37041f90a35f685833
|
4
|
+
data.tar.gz: b4c17f35245594f7c576a79710c14495af48df95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66b73f44ef7f147a2811bb324cfa427e5f9ac941337c3ed705e97b5e8612ce3a36198060f6db4c76efa0297e3d349642636aeb3fb7f4132c6b0ce8cc650b6ceb
|
7
|
+
data.tar.gz: fb11483346c7dff8a5b2fc0170d4e33bd2c336ec87c9b3f2957376d960acdf47e27993ce59105e2a8bbfccff54c38c32c4c29b140156659e76e2c42daa066aeb
|
data/CQHTTP.gemspec
CHANGED
data/exe/cqhttp-dbus
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'CQHTTP'
|
4
|
+
require 'dbus'
|
5
|
+
Thread.abort_on_exception = true
|
6
|
+
|
7
|
+
# DBus
|
8
|
+
class CQHTTP2DBus < DBus::Object
|
9
|
+
dbus_interface 'org.dastudio.cqhttp' do
|
10
|
+
dbus_signal :message, 'message_type:s, json:s'
|
11
|
+
dbus_signal :event, 'event:s, json:s'
|
12
|
+
dbus_signal :friend_request, 'json:s'
|
13
|
+
dbus_signal :join_request, 'json:s'
|
14
|
+
dbus_signal :invite_request, 'json:s'
|
15
|
+
dbus_signal :all, 'json:s'
|
16
|
+
dbus_signal :unknow, 'json:s'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def cqhttp2dbus(c, obj)
|
21
|
+
j = c.json
|
22
|
+
obj.all j.to_json
|
23
|
+
case j['post_type']
|
24
|
+
when 'message' then obj.message j['message_type'], j.to_json
|
25
|
+
when 'event' then obj.event j['event'], j.to_json
|
26
|
+
when 'request'
|
27
|
+
case j['request_type']
|
28
|
+
when 'friend' then obj.friend_request j.to_json
|
29
|
+
when 'group'
|
30
|
+
case j['sub_type']
|
31
|
+
when 'add' then obj.join_request j.to_json
|
32
|
+
when 'invite' then obj.invite_request j.to_json
|
33
|
+
else obj.unknow j.to_json
|
34
|
+
end
|
35
|
+
else obj.unknow j.to_json
|
36
|
+
end
|
37
|
+
else obj.unknow j.to_json
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
bus = DBus::SessionBus.instance
|
42
|
+
service = bus.request_service 'org.dastudio.qq'
|
43
|
+
obj = CQHTTP2DBus.new '/org/dastudio/qq'
|
44
|
+
service.export obj
|
45
|
+
|
46
|
+
cqhttp = CQHTTP::Service.new
|
47
|
+
cqhttp.bind ->(c) { cqhttp2dbus c, obj }
|
48
|
+
|
49
|
+
Thread.new { cqhttp.run }
|
50
|
+
|
51
|
+
main = DBus::Main.new
|
52
|
+
main << bus
|
53
|
+
main.run
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module CQHTTP
|
2
|
+
# TODO
|
3
|
+
class Service
|
4
|
+
attr_reader :json
|
5
|
+
|
6
|
+
def initialize(hostname: '0.0.0.0', port: 9455)
|
7
|
+
@server = TCPServer.new(hostname, port)
|
8
|
+
@event_method = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def bind(func)
|
12
|
+
@event_method << func
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
loop do
|
17
|
+
socket = @server.accept
|
18
|
+
|
19
|
+
head socket if $VERBOSE
|
20
|
+
|
21
|
+
socket.print "HTTP/1.1 204\r\nContent-Type: application/json\r\n\r\n"
|
22
|
+
data = socket.gets
|
23
|
+
@json = JSON.parse data
|
24
|
+
|
25
|
+
@event_method.each { |func| func.call self }
|
26
|
+
|
27
|
+
socket.close
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def head(socket)
|
34
|
+
puts 'head'
|
35
|
+
while (line = socket.gets) != "\r\n"
|
36
|
+
print ' '
|
37
|
+
puts line
|
38
|
+
end
|
39
|
+
puts 'end'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/CQHTTP/version.rb
CHANGED
data/lib/CQHTTP.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CQHTTP
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
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-
|
11
|
+
date: 2017-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,10 +52,25 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-dbus
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.13.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.13.0
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- DAStudio.71e6fd52@gmail.com
|
58
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- cqhttp-dbus
|
59
74
|
extensions: []
|
60
75
|
extra_rdoc_files: []
|
61
76
|
files:
|
@@ -69,10 +84,12 @@ files:
|
|
69
84
|
- bin/console
|
70
85
|
- bin/gen_api_list
|
71
86
|
- bin/setup
|
87
|
+
- exe/cqhttp-dbus
|
72
88
|
- lib/CQHTTP.rb
|
73
89
|
- lib/CQHTTP/API.md
|
74
90
|
- lib/CQHTTP/api.rb
|
75
91
|
- lib/CQHTTP/network.rb
|
92
|
+
- lib/CQHTTP/service.rb
|
76
93
|
- lib/CQHTTP/version.rb
|
77
94
|
homepage: https://github.com/71e6fd52/cqhttp-ruby
|
78
95
|
licenses: []
|