ruby-cqhttp 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +2 -2
- data/lib/Core/Http/API.rb +10 -10
- data/lib/Core/WebSocket/API.rb +72 -4
- data/lib/onebot-ruby.rb +5 -5
- data/ruby-cqhttp.gemspec +1 -1
- data/tests/client.rb +2 -2
- data/tests/server.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925802d93d0690ccc22b020a3236b52c837b3d0961d55a9962cd9bb4f6d55b69
|
4
|
+
data.tar.gz: ac87d2efe8fc65a2f8a3b6c5216306b69c7c59b25c68c3f1c9067b4b2138c87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1e82a77d99140324a348d12d5aac54a5dffa137c577ba9260773607849dfa596934cd79a86ad6f98d35f1ec4ad8b4020eac8049e1bf2b1a38908804d517fc07
|
7
|
+
data.tar.gz: 483be6c942157ed36fe9f206e2a6b14265dd563a6441e5effc36e9ffa9d18d03dbc3060932c17d2f5f7a34d2ca36936c4677619d9db2fb2395517b3330da2454
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -42,10 +42,10 @@ Onebot::Core.connect url: "ws://127.0.0.1:6700", logger: logger do |bot|
|
|
42
42
|
logger.log('我开了欸')
|
43
43
|
end
|
44
44
|
|
45
|
-
bot.on :message do |
|
45
|
+
bot.on :message do |data|
|
46
46
|
logger.log('我收到消息了欸')
|
47
47
|
# 复读
|
48
|
-
bot.sendMessage(
|
48
|
+
bot.sendMessage(data.message, data)
|
49
49
|
end
|
50
50
|
|
51
51
|
# 获取并发出好友撤回的消息
|
data/lib/Core/Http/API.rb
CHANGED
@@ -31,7 +31,7 @@ module Onebot
|
|
31
31
|
# @param url [URI]
|
32
32
|
# @return [Hash]
|
33
33
|
def setGroupName(group_id, group_name)
|
34
|
-
data =
|
34
|
+
data = sendReq('set_group_name', { group_id: group_id.to_i, group_name: })
|
35
35
|
if data['status'] == 'ok'
|
36
36
|
@logger.log '设置群头像成功'
|
37
37
|
else
|
@@ -46,7 +46,7 @@ module Onebot
|
|
46
46
|
# @param url [URI]
|
47
47
|
# @return [Hash]
|
48
48
|
def getImage(file)
|
49
|
-
data =
|
49
|
+
data = sendReq('get_image', { file: })
|
50
50
|
if data['status'] == 'ok'
|
51
51
|
@logger.log '下载图片成功'
|
52
52
|
else
|
@@ -61,7 +61,7 @@ module Onebot
|
|
61
61
|
# @param url [URI]
|
62
62
|
# @return [Hash]
|
63
63
|
def get_msg(message_id)
|
64
|
-
data =
|
64
|
+
data = sendReq('get_msg', { message_id: })
|
65
65
|
if data['status'] == 'ok'
|
66
66
|
@logger.log '消息获取成功'
|
67
67
|
else
|
@@ -77,7 +77,7 @@ module Onebot
|
|
77
77
|
# @param url [URI]
|
78
78
|
# @return [Hash]
|
79
79
|
def sendPrivateMessage(msg, user_id)
|
80
|
-
data =
|
80
|
+
data = sendReq('send_private_msg', { user_id:, message: msg })
|
81
81
|
if data['status'] == 'ok'
|
82
82
|
message_id = data['data']['message_id']
|
83
83
|
@logger.log "发送至私聊 #{user_id} 的消息: #{msg} (#{message_id})"
|
@@ -94,7 +94,7 @@ module Onebot
|
|
94
94
|
# @param url [URI]
|
95
95
|
# @return [Hash]
|
96
96
|
def sendGroupMessage(msg, group_id)
|
97
|
-
data =
|
97
|
+
data = sendReq('send_group_msg', { group_id:, message: msg })
|
98
98
|
if data['status'] == 'ok'
|
99
99
|
message_id = data['data']['message_id']
|
100
100
|
@logger.log "发送至群 #{group_id} 的消息: #{msg} (#{message_id})"
|
@@ -111,7 +111,7 @@ module Onebot
|
|
111
111
|
# @param url [URI]
|
112
112
|
# @return [Boolean]
|
113
113
|
def acceptFriendRequest(flag, reason = nil)
|
114
|
-
data =
|
114
|
+
data = sendReq('set_friend_add_request', { flag:, approve: true, remark: reason })
|
115
115
|
if data['status'] == 'ok'
|
116
116
|
@logger.log '已通过好友请求'
|
117
117
|
true
|
@@ -127,7 +127,7 @@ module Onebot
|
|
127
127
|
# @param url [URI]
|
128
128
|
# @return [Boolean]
|
129
129
|
def refuseFriendRequest(flag)
|
130
|
-
data =
|
130
|
+
data = sendReq('set_friend_add_request', { flag:, approve: false })
|
131
131
|
if data['status'] == 'ok'
|
132
132
|
@logger.log '已拒绝好友请求'
|
133
133
|
true
|
@@ -144,7 +144,7 @@ module Onebot
|
|
144
144
|
# @param url [URI]
|
145
145
|
# @return [Boolean]
|
146
146
|
def acceptGroupRequest(flag, sub_type)
|
147
|
-
data =
|
147
|
+
data = sendReq('set_group_add_request', { flag:, sub_type:, approve: true })
|
148
148
|
if data['status'] == 'ok'
|
149
149
|
@logger.log '已通过加群请求'
|
150
150
|
true
|
@@ -162,7 +162,7 @@ module Onebot
|
|
162
162
|
# @param url [URI]
|
163
163
|
# @return [Boolean]
|
164
164
|
def refuseGroupRequest(flag, sub_type, reason = nil)
|
165
|
-
data =
|
165
|
+
data = sendReq('set_group_add_request', { flag:, sub_type:, approve: false, reason: })
|
166
166
|
if data['status'] == 'ok'
|
167
167
|
@logger.log '已拒绝加群请求'
|
168
168
|
true
|
@@ -174,7 +174,7 @@ module Onebot
|
|
174
174
|
|
175
175
|
private
|
176
176
|
|
177
|
-
def
|
177
|
+
def sendReq(action, params, url = @url)
|
178
178
|
url.path = action
|
179
179
|
JSON.parse(Utils.httpPost(url, params.to_json))
|
180
180
|
end
|
data/lib/Core/WebSocket/API.rb
CHANGED
@@ -11,7 +11,7 @@ module Onebot
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def get_msg(message_id, _url = @apiUrl)
|
14
|
-
ret =
|
14
|
+
ret = sendReq('get_msg', { message_id: })
|
15
15
|
if parseRet(ret)
|
16
16
|
@eventLogger.log "获取消息成功 (#{message_id})"
|
17
17
|
else
|
@@ -26,7 +26,7 @@ module Onebot
|
|
26
26
|
# @param user_id [Number]
|
27
27
|
# @return [Hash]
|
28
28
|
def sendPrivateMessage(message, user_id)
|
29
|
-
ret =
|
29
|
+
ret = sendReq('send_private_msg', { user_id:, message: })
|
30
30
|
if parseRet(ret)
|
31
31
|
@eventLogger.log "发送至私聊 #{user_id} 的消息: #{message} (#{ret.data.message_id})"
|
32
32
|
else
|
@@ -41,7 +41,7 @@ module Onebot
|
|
41
41
|
# @param group_id [Number]
|
42
42
|
# @return [Hash]
|
43
43
|
def sendGroupMessage(message, group_id)
|
44
|
-
ret =
|
44
|
+
ret = sendReq('send_group_msg', { group_id:, message: })
|
45
45
|
if parseRet(ret)
|
46
46
|
@eventLogger.log "发送至群 #{group_id} 的消息: #{message} (#{ret.data.message_id})"
|
47
47
|
else
|
@@ -50,6 +50,74 @@ module Onebot
|
|
50
50
|
ret[:data]
|
51
51
|
end
|
52
52
|
|
53
|
+
# 接受好友邀请
|
54
|
+
#
|
55
|
+
# @param flag [String]
|
56
|
+
# @param reason [String]
|
57
|
+
# @param url [URI]
|
58
|
+
# @return [Boolean]
|
59
|
+
def acceptFriendRequest(flag, reason = nil)
|
60
|
+
data = sendReq('set_friend_add_request', { flag:, approve: true, remark: reason })
|
61
|
+
if parseRet(data)
|
62
|
+
@logger.log '已通过好友请求'
|
63
|
+
true
|
64
|
+
else
|
65
|
+
@logger.log '请求通过失败', Logger::WARN
|
66
|
+
false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 拒绝好友邀请
|
71
|
+
#
|
72
|
+
# @param flag [String]
|
73
|
+
# @param url [URI]
|
74
|
+
# @return [Boolean]
|
75
|
+
def refuseFriendRequest(flag)
|
76
|
+
data = sendReq('set_friend_add_request', { flag:, approve: false })
|
77
|
+
if parseRet(data)
|
78
|
+
@logger.log '已拒绝好友请求'
|
79
|
+
true
|
80
|
+
else
|
81
|
+
@logger.log '请求拒绝失败', Logger::WARN
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# 接受加群请求
|
87
|
+
#
|
88
|
+
# @param flag [String]
|
89
|
+
# @param sub_type [String]
|
90
|
+
# @param url [URI]
|
91
|
+
# @return [Boolean]
|
92
|
+
def acceptGroupRequest(flag, sub_type)
|
93
|
+
data = sendReq('set_group_add_request', { flag:, sub_type:, approve: true })
|
94
|
+
if parseRet(data)
|
95
|
+
@logger.log '已通过加群请求'
|
96
|
+
true
|
97
|
+
else
|
98
|
+
@logger.log '请求通过失败', Logger::WARN
|
99
|
+
false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# 拒绝加群请求
|
104
|
+
#
|
105
|
+
# @param flag [String]
|
106
|
+
# @param sub_type [String]
|
107
|
+
# @param reason [String]
|
108
|
+
# @param url [URI]
|
109
|
+
# @return [Boolean]
|
110
|
+
def refuseGroupRequest(flag, sub_type, reason = nil)
|
111
|
+
data = sendReq('set_group_add_request', { flag:, sub_type:, approve: false, reason: })
|
112
|
+
if parseRet(data)
|
113
|
+
@logger.log '已拒绝加群请求'
|
114
|
+
true
|
115
|
+
else
|
116
|
+
@logger.log '请求拒绝失败', Logger::WARN
|
117
|
+
false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
53
121
|
private
|
54
122
|
|
55
123
|
#
|
@@ -60,7 +128,7 @@ module Onebot
|
|
60
128
|
return false if ret.status == 'failed'
|
61
129
|
end
|
62
130
|
|
63
|
-
def
|
131
|
+
def sendReq(action, params)
|
64
132
|
echo = Time.now.to_i.to_s
|
65
133
|
@ws.send({ action:, params:, echo: }.to_json)
|
66
134
|
@queueList[echo] = Queue.new
|
data/lib/onebot-ruby.rb
CHANGED
@@ -28,11 +28,11 @@ module Onebot
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module WebSocket
|
31
|
-
autoload :Session, File.expand_path('Core/
|
32
|
-
autoload :API, File.expand_path('Core/
|
33
|
-
autoload :Bot, File.expand_path('Core/
|
34
|
-
autoload :Client, File.expand_path('Core/
|
35
|
-
autoload :Server, File.expand_path('Core/
|
31
|
+
autoload :Session, File.expand_path('Core/WebSocket/Session', __dir__)
|
32
|
+
autoload :API, File.expand_path('Core/WebSocket/API', __dir__)
|
33
|
+
autoload :Bot, File.expand_path('Core/WebSocket/Bot', __dir__)
|
34
|
+
autoload :Client, File.expand_path('Core/WebSocket/Client', __dir__)
|
35
|
+
autoload :Server, File.expand_path('Core/WebSocket/Server', __dir__)
|
36
36
|
end
|
37
37
|
|
38
38
|
module Http
|
data/ruby-cqhttp.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'ruby-cqhttp'
|
6
|
-
s.version = '0.1.
|
6
|
+
s.version = '0.1.2'
|
7
7
|
s.summary = '一个基于 OneBot 标准的 QQ 机器人框架'
|
8
8
|
s.description = '一个基于 OneBot 标准的 QQ 机器人框架'
|
9
9
|
s.authors = ['fantasyzhjk']
|
data/tests/client.rb
CHANGED
@@ -8,8 +8,8 @@ Onebot::Core.connect url: 'ws://localhost:7700', logger: logger, options: { head
|
|
8
8
|
logger.log('我开了欸')
|
9
9
|
end
|
10
10
|
|
11
|
-
bot.on :privateMessage do |
|
12
|
-
bot.sendMessage(session.message,
|
11
|
+
bot.on :privateMessage do |data|
|
12
|
+
bot.sendMessage(session.message, data)
|
13
13
|
end
|
14
14
|
|
15
15
|
bot.on :notice do |notice_type, data|
|
data/tests/server.rb
CHANGED
@@ -14,11 +14,11 @@ App = lambda do |env|
|
|
14
14
|
logger.log('我开了欸')
|
15
15
|
end
|
16
16
|
|
17
|
-
bot.on :privateMessage do |
|
18
|
-
# p
|
19
|
-
# p
|
20
|
-
p Onebot::Utils.cqParse(
|
21
|
-
bot.sendPrivateMessage(
|
17
|
+
bot.on :privateMessage do |data|
|
18
|
+
# p data.message
|
19
|
+
# p data
|
20
|
+
p Onebot::Utils.cqParse(data.message)
|
21
|
+
bot.sendPrivateMessage(data.message, data.userId)
|
22
22
|
end
|
23
23
|
|
24
24
|
bot.rack_response
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-cqhttp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fantasyzhjk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_emitter
|