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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b423809199376adf6d399e697c3e1e9129453815a92aa5308df2b05e49844c63
4
- data.tar.gz: 1f979eac7d6f35a094b7ca2e966b30e95583b953c0154d96a93d9f0af5e6721e
3
+ metadata.gz: 925802d93d0690ccc22b020a3236b52c837b3d0961d55a9962cd9bb4f6d55b69
4
+ data.tar.gz: ac87d2efe8fc65a2f8a3b6c5216306b69c7c59b25c68c3f1c9067b4b2138c87a
5
5
  SHA512:
6
- metadata.gz: 7f0ed93f862d094a9dc0240e02ae1409f60c63a00edd1670ae2b89deaae8165b7591b6861f50e370ed6e21d38f734f3e4a86b476ccc6516622aca55e1e8ee81f
7
- data.tar.gz: 1caf072fa4d44e77c6a41e6b1bf3ed102687074f5a07ad14317986109b0a337fcc89fc0ab5ac0158dcddee67c27e2c8526f709994a1660c1fc86ff86974e7af0
6
+ metadata.gz: c1e82a77d99140324a348d12d5aac54a5dffa137c577ba9260773607849dfa596934cd79a86ad6f98d35f1ec4ad8b4020eac8049e1bf2b1a38908804d517fc07
7
+ data.tar.gz: 483be6c942157ed36fe9f206e2a6b14265dd563a6441e5effc36e9ffa9d18d03dbc3060932c17d2f5f7a34d2ca36936c4677619d9db2fb2395517b3330da2454
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ go-cqhttp*
9
9
  session.token
10
10
  device.json
11
11
  config.yml
12
+ .yardoc
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 |session|
45
+ bot.on :message do |data|
46
46
  logger.log('我收到消息了欸')
47
47
  # 复读
48
- bot.sendMessage(session.message, session)
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 = send('set_group_name', { group_id: group_id.to_i, group_name: })
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 = send('get_image', { file: })
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 = send('get_msg', { message_id: })
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 = send('send_private_msg', { user_id:, message: msg })
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 = send('send_group_msg', { group_id:, message: msg })
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 = send('set_friend_add_request', { flag:, approve: true, remark: reason })
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 = send('set_friend_add_request', { flag:, approve: false })
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 = send('set_group_add_request', { flag:, sub_type:, approve: true })
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 = send('set_group_add_request', { flag:, sub_type:, approve: false, reason: })
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 send(action, params, url = @url)
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
@@ -11,7 +11,7 @@ module Onebot
11
11
  end
12
12
 
13
13
  def get_msg(message_id, _url = @apiUrl)
14
- ret = send('get_msg', { message_id: })
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 = send('send_private_msg', { user_id:, message: })
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 = send('send_group_msg', { group_id:, message: })
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 send(action, params)
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/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__)
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.0'
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 |session|
12
- bot.sendMessage(session.message, session)
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 |session|
18
- # p session.message
19
- # p session
20
- p Onebot::Utils.cqParse(session.message)
21
- bot.sendPrivateMessage(session.message, session.userId)
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_emitter