ruby-cqhttp 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Bot/Api.rb +53 -10
- data/lib/Bot/Bot.rb +6 -0
- data/lib/ruby-cqhttp.rb +2 -1
- data/ruby-cqhttp.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87e4e75d7c60595d1c8b7819e463ef23f400300735a747e6176e12ea6e7d3591
|
4
|
+
data.tar.gz: 88a63f60407888c0ba0a258ccbca71253e84492268bfd87dc193e319554c40dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad14175baf0305ba55f86f33446772336939fa89f3163b274906100c8d520bb9e8a51174b6e92793e4d4dc375df092bf35fa4ad27f6e9dd28f18da06c9f3249
|
7
|
+
data.tar.gz: 31f469412b075c00bb95f6ec3acb1190a20647391fba290cb06f8449669eddb570612de507a689fe1c5993f7695c8d12af5ff3771265543387ca8e5f0a5e1b8d
|
data/lib/Bot/Api.rb
CHANGED
@@ -4,18 +4,61 @@ module CQHttp
|
|
4
4
|
|
5
5
|
@apiUrl = 'http://127.0.0.1:5700'
|
6
6
|
class << self
|
7
|
+
def setGroupName(group_id, group_name, url=@apiUrl)
|
8
|
+
ret = { group_id: group_id.to_i, group_name: group_name }.to_json
|
9
|
+
data = JSON.parse(Utils.httpPost("#{url}/set_group_name", ret))
|
10
|
+
if data['status'] == 'ok'
|
11
|
+
Utils.log Time.new, '√', '设置群头像成功'
|
12
|
+
else
|
13
|
+
Utils.log Time.new, '×', '设置群头像失败'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def getImage(file, url=@apiUrl) # UNFINSHED
|
18
|
+
ret = { file: file }.to_json
|
19
|
+
data = JSON.parse(Utils.httpPost("#{url}/get_image", ret))
|
20
|
+
if data['status'] == 'ok'
|
21
|
+
Utils.log Time.new, '√', '下载图片成功'
|
22
|
+
return data['data']
|
23
|
+
else
|
24
|
+
Utils.log Time.new, '×', '下载图片失败'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_msg(message_id, url=@apiUrl) # UNFINSHED
|
29
|
+
ret = { message_id: message_id }.to_json
|
30
|
+
data = JSON.parse(Utils.httpPost("#{url}/get_msg", ret))
|
31
|
+
if data['status'] == 'ok'
|
32
|
+
Utils.log Time.new, '√', '消息获取成功'
|
33
|
+
return data['data']
|
34
|
+
else
|
35
|
+
Utils.log Time.new, '×', '消息获取失败'
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
7
40
|
def sendPrivateMessage(msg, user_id, url=@apiUrl)
|
8
41
|
ret = { user_id: user_id, message: msg }.to_json
|
9
|
-
|
10
|
-
|
11
|
-
|
42
|
+
data = JSON.parse(Utils.httpPost("#{url}/send_private_msg", ret))
|
43
|
+
if data['status'] == 'ok'
|
44
|
+
message_id = data['data']['message_id']
|
45
|
+
Utils.log Time.new, '↑', "发送至私聊 #{user_id} 的消息: #{msg} (#{message_id})"
|
46
|
+
return message_id
|
47
|
+
else
|
48
|
+
Utils.log Time.new, '×', '发送消息失败'
|
49
|
+
end
|
12
50
|
end
|
13
51
|
|
14
52
|
def sendGroupMessage(msg, group_id, url=@apiUrl)
|
15
53
|
ret = { group_id: group_id, message: msg }.to_json
|
16
|
-
|
17
|
-
|
18
|
-
|
54
|
+
data = JSON.parse(Utils.httpPost("#{url}/send_group_msg", ret))
|
55
|
+
if data['status'] == 'ok'
|
56
|
+
message_id = data['data']['group_id']
|
57
|
+
Utils.log Time.new, '↑', "发送至群 #{user_id} 的消息: #{msg} (#{message_id})"
|
58
|
+
return message_id
|
59
|
+
else
|
60
|
+
Utils.log Time.new, '×', '发送消息失败'
|
61
|
+
end
|
19
62
|
end
|
20
63
|
|
21
64
|
def acceptFriendRequest(flag, url=@apiUrl)
|
@@ -24,7 +67,7 @@ module CQHttp
|
|
24
67
|
if data['status'] == 'ok'
|
25
68
|
Utils.log Time.new, '√', '已通过好友请求'
|
26
69
|
else
|
27
|
-
Utils.log Time.new, '
|
70
|
+
Utils.log Time.new, '×', '请求通过失败'
|
28
71
|
end
|
29
72
|
end
|
30
73
|
|
@@ -34,7 +77,7 @@ module CQHttp
|
|
34
77
|
if data['status'] == 'ok'
|
35
78
|
Utils.log Time.new, '√', '已拒绝好友请求'
|
36
79
|
else
|
37
|
-
Utils.log Time.new, '
|
80
|
+
Utils.log Time.new, '×', '请求拒绝失败'
|
38
81
|
end
|
39
82
|
end
|
40
83
|
|
@@ -44,7 +87,7 @@ module CQHttp
|
|
44
87
|
if data['status'] == 'ok'
|
45
88
|
Utils.log Time.new, '√', '已通过加群请求'
|
46
89
|
else
|
47
|
-
Utils.log Time.new, '
|
90
|
+
Utils.log Time.new, '×', '请求通过失败'
|
48
91
|
end
|
49
92
|
end
|
50
93
|
|
@@ -54,7 +97,7 @@ module CQHttp
|
|
54
97
|
if data['status'] == 'ok'
|
55
98
|
Utils.log Time.new, '√', '已拒绝加群请求'
|
56
99
|
else
|
57
|
-
Utils.log Time.new, '
|
100
|
+
Utils.log Time.new, '×', '请求拒绝失败'
|
58
101
|
end
|
59
102
|
end
|
60
103
|
end
|
data/lib/Bot/Bot.rb
CHANGED
@@ -98,7 +98,13 @@ module CQHttp
|
|
98
98
|
if msg['sub_type'] == 'kick_me' # 被踢出
|
99
99
|
Utils.log Time.at(tar.time), '!', "被 #{msg['operator_id']} 踢出群 #{msg['group_id']}"
|
100
100
|
end
|
101
|
+
when 'group_recall'
|
102
|
+
Utils.log Time.at(tar.time), '!', "群 #{msg['group_id']} 中 #{msg['user_id']} 撤回了一条消息 (#{msg['message_id']})"
|
103
|
+
when 'friend_recall'
|
104
|
+
Utils.log Time.at(tar.time), '!', "好友 #{msg['user_id']} 撤回了一条消息 (#{msg['message_id']})"
|
101
105
|
end
|
106
|
+
emit :notice, msg['notice_type'], msg
|
107
|
+
|
102
108
|
#
|
103
109
|
# 消息事件
|
104
110
|
#
|
data/lib/ruby-cqhttp.rb
CHANGED
@@ -5,7 +5,8 @@ require 'event_emitter'
|
|
5
5
|
require 'net/http'
|
6
6
|
|
7
7
|
module CQHttp
|
8
|
-
autoload :Api, File.expand_path('Bot/Api', __dir__)
|
9
8
|
autoload :Bot, File.expand_path('Bot/Bot', __dir__)
|
9
|
+
autoload :Api, File.expand_path('Bot/Api', __dir__)
|
10
10
|
autoload :Utils, File.expand_path('Bot/Utils', __dir__)
|
11
11
|
end
|
12
|
+
|
data/ruby-cqhttp.gemspec
CHANGED