khl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +53 -0
- data/lib/khl/http/asset.rb +19 -0
- data/lib/khl/http/badge.rb +20 -0
- data/lib/khl/http/base.rb +101 -0
- data/lib/khl/http/blacklist.rb +41 -0
- data/lib/khl/http/channel.rb +58 -0
- data/lib/khl/http/channel_role.rb +50 -0
- data/lib/khl/http/channel_user.rb +22 -0
- data/lib/khl/http/client.rb +78 -0
- data/lib/khl/http/direct_message.rb +85 -0
- data/lib/khl/http/game.rb +59 -0
- data/lib/khl/http/gateway.rb +19 -0
- data/lib/khl/http/guild.rb +70 -0
- data/lib/khl/http/guild_emoji.rb +46 -0
- data/lib/khl/http/guild_mute.rb +38 -0
- data/lib/khl/http/guild_role.rb +70 -0
- data/lib/khl/http/intimacy.rb +29 -0
- data/lib/khl/http/invite.rb +43 -0
- data/lib/khl/http/message.rb +92 -0
- data/lib/khl/http/response.rb +69 -0
- data/lib/khl/http/user.rb +32 -0
- data/lib/khl/http/user_chat.rb +42 -0
- data/lib/khl/version.rb +5 -0
- data/lib/khl/web_socket/client.rb +151 -0
- data/lib/khl/web_socket/message.rb +54 -0
- data/lib/khl.rb +6 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed901cab84178a2961285b975bf703bb034b998e0d70e7e8c8e06c5f27187137
|
4
|
+
data.tar.gz: 0447d12135db7697c59aadfd7f358e64982db782af00c2fdb90c4ea1bb2123a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b71ec8d6a9f2e46c412a0552f2f6484d37a273ce141386ea9b94c8756ab54d15774d857cc42a25f1b4ea6be32b1a5e03d4544d04b1911dfc121778bed1ef4c5
|
7
|
+
data.tar.gz: 97ee22265dd77c70c3d432418e2a89410b2eb14984a81df83a08206fe1344f6c3479090afcb488e8f43bf9ba363ffaa8c33ff8dbe8804b3ec6932fdd4bb0e05e
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# KHL
|
2
|
+
|
3
|
+
开黑啦 Ruby SDK
|
4
|
+
|
5
|
+
[官方开发者文档](https://developer.kaiheila.cn/doc)
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
* ruby >= 2.7
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'khl'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install khl
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```
|
30
|
+
require "khl"
|
31
|
+
|
32
|
+
token = "your_bot_token"
|
33
|
+
|
34
|
+
# Call HTTP API
|
35
|
+
http_client = KHL::HTTP::Client.new(token)
|
36
|
+
http_client.guild.list # Call guild/list API
|
37
|
+
|
38
|
+
# Connect to WebSocket API
|
39
|
+
ws_client = KHL::WebSocket::Client.new(token)
|
40
|
+
Thread.new { ws_client.run } # Run WebSocket client
|
41
|
+
ws_clinet.state # Get current state
|
42
|
+
ws_client.messages.pop # Get message from queue
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DessertShop/KHL.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 媒体相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/asset
|
9
|
+
class Asset < Base
|
10
|
+
# 上传媒体文件
|
11
|
+
# @param [Hash] options 可选参数
|
12
|
+
# @option options [IO] :file 目前支持 图片,视频(.mp4 .mov),文件
|
13
|
+
# @return [KHL::HTTP::Response]
|
14
|
+
def create(options = {})
|
15
|
+
post_file(options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 徽章相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/badge
|
9
|
+
class Badge < Base
|
10
|
+
# 获取服务器徽章
|
11
|
+
# @param [String] guild_id 服务器 ID
|
12
|
+
# @param [Hash] options 可选参数
|
13
|
+
# @option options [Integer] :style 样式类型,默认为 0
|
14
|
+
# @return [KHL::HTTP::Response]
|
15
|
+
def guild(guild_id, options = {})
|
16
|
+
get(options.merge(guild_id: guild_id))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
require "json"
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
|
8
|
+
require_relative "response"
|
9
|
+
|
10
|
+
module KHL
|
11
|
+
module HTTP
|
12
|
+
# 接口基类
|
13
|
+
class Base
|
14
|
+
BASE_URL = "https://www.kaiheila.cn/api"
|
15
|
+
API_VERSION = "v3"
|
16
|
+
END_POINT = "#{BASE_URL}/#{API_VERSION}"
|
17
|
+
|
18
|
+
attr_reader :config
|
19
|
+
|
20
|
+
# @param config [Hash] Config
|
21
|
+
# @option config [String] :token Bot token (required)
|
22
|
+
# @option config [String] :token_type Token type
|
23
|
+
# @option config [String] :language Language
|
24
|
+
def initialize(config)
|
25
|
+
raise ArgumentError, "missing token" unless config[:token]
|
26
|
+
config[:token_type] ||= "Bot"
|
27
|
+
config[:language] ||= "zh-cn"
|
28
|
+
|
29
|
+
@config = config
|
30
|
+
end
|
31
|
+
|
32
|
+
# GET 请求
|
33
|
+
def get(params = {})
|
34
|
+
action = params.key?(:action) ? params.delete(:action) : action_name # 可在 params 中手动配置 action
|
35
|
+
uri = URI("#{END_POINT}/#{resource_name}/#{action}")
|
36
|
+
params = filter_params(params)
|
37
|
+
uri.query = URI.encode_www_form(params)
|
38
|
+
request = Net::HTTP::Get.new(uri)
|
39
|
+
request["Authorization"] = "#{config[:token_type]} #{config[:token]}"
|
40
|
+
raw_response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
41
|
+
http.request(request)
|
42
|
+
end
|
43
|
+
|
44
|
+
Response.new(raw_response)
|
45
|
+
end
|
46
|
+
|
47
|
+
# POST 请求
|
48
|
+
def post(params = {})
|
49
|
+
action = params.key?(:action) ? params.delete(:action) : action_name
|
50
|
+
uri = URI("#{END_POINT}/#{resource_name}/#{action}")
|
51
|
+
request = Net::HTTP::Post.new(uri)
|
52
|
+
request["Authorization"] = "#{config[:token_type]} #{config[:token]}"
|
53
|
+
request["Content-type"] = "application/json"
|
54
|
+
params = filter_params(params)
|
55
|
+
request.body = JSON.generate(params)
|
56
|
+
raw_response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
57
|
+
http.request(request)
|
58
|
+
end
|
59
|
+
|
60
|
+
Response.new(raw_response)
|
61
|
+
end
|
62
|
+
|
63
|
+
# POST 文件请求
|
64
|
+
def post_file(params = {})
|
65
|
+
action = params.key?(:action) ? params.delete(:action) : action_name
|
66
|
+
uri = URI("#{END_POINT}/#{resource_name}/#{action}")
|
67
|
+
request = Net::HTTP::Post.new(uri)
|
68
|
+
request["Authorization"] = "#{config[:token_type]} #{config[:token]}"
|
69
|
+
request["Content-type"] = params.delete(:content_type) || "form-data" # 可在 params 中手动配置 content_type
|
70
|
+
params = filter_params(params)
|
71
|
+
request.set_form(params, "multipart/form-data")
|
72
|
+
raw_response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
73
|
+
http.request(request)
|
74
|
+
end
|
75
|
+
|
76
|
+
Response.new(raw_response)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# 过滤掉值为 nil 的参数,并将键全部转化为 String
|
82
|
+
def filter_params(params)
|
83
|
+
return {} unless params&.is_a?(Hash)
|
84
|
+
|
85
|
+
params = params.reject { |_, v| v.nil? }
|
86
|
+
params.transform_keys(&:to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
# 根据类名获取资源名
|
90
|
+
def resource_name
|
91
|
+
self.class.name.demodulize.underscore.dasherize
|
92
|
+
end
|
93
|
+
|
94
|
+
# 根据调用此方法的方法名,获取对应的接口名
|
95
|
+
def action_name
|
96
|
+
call_stack = caller(2..2)&.first
|
97
|
+
call_stack[/`.*'/][1..-2]&.dasherize
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 黑名单相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/blacklist
|
9
|
+
class Blacklist < Base
|
10
|
+
# 获取黑名单列表
|
11
|
+
# @param [String] guild_id 服务器 ID
|
12
|
+
# @param [Hash] options 可选参数
|
13
|
+
# @option options [Integer] :page 页数
|
14
|
+
# @option options [Integer] :page_size 每页数据数量
|
15
|
+
# @option options [String] :sort 代表排序的字段,比如 -id 代表 id 按 DESC 排序,id 代表 id 按 ASC 排序
|
16
|
+
# @return [KHL::HTTP::Response]
|
17
|
+
def list(guild_id, options = {})
|
18
|
+
get(options.merge(guild_id: guild_id))
|
19
|
+
end
|
20
|
+
|
21
|
+
# 加入黑名单
|
22
|
+
# @param [String] guild_id 服务器 ID
|
23
|
+
# @param [String] target_id 用户 ID
|
24
|
+
# @param [Hash] options 可选参数
|
25
|
+
# @option options [String] :remark 加入黑名单的原因
|
26
|
+
# @option options [Integer] :del_msg_days 删除最近几天的消息,最大 7 天,默认 0
|
27
|
+
# @return [KHL::HTTP::Response]
|
28
|
+
def create(guild_id, target_id, options = {})
|
29
|
+
post(options.merge(guild_id: guild_id, target_id: target_id))
|
30
|
+
end
|
31
|
+
|
32
|
+
# 移除黑名单
|
33
|
+
# @param [String] guild_id 服务器 ID
|
34
|
+
# @param [String] target_id 用户 ID
|
35
|
+
# @return [KHL::HTTP::Response]
|
36
|
+
def delete(guild_id, target_id)
|
37
|
+
post(guild_id: guild_id, target_id: target_id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 频道相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/channel
|
9
|
+
class Channel < Base
|
10
|
+
# 获取频道列表
|
11
|
+
# @param [String] guild_id 服务器 ID
|
12
|
+
# @param [Hash] options 可选参数
|
13
|
+
# @option options [Integer] :page 页数
|
14
|
+
# @option options [Integer] :page_size 每页数据数量
|
15
|
+
# @option options [Integer] :type 频道类型,1 为文字,2 为语音,默认为 1
|
16
|
+
# @return [KHL::HTTP::Response]
|
17
|
+
def list(guild_id, options = {})
|
18
|
+
get(options.merge(guild_id: guild_id))
|
19
|
+
end
|
20
|
+
|
21
|
+
# 获取频道详情
|
22
|
+
# @param [String] target_id 频道 ID
|
23
|
+
# @return [KHL::HTTP::Response]
|
24
|
+
def view(target_id)
|
25
|
+
get(target_id: target_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
# 创建频道
|
29
|
+
# @param [String] guild_id 服务器 ID
|
30
|
+
# @param [String] name 频道名称
|
31
|
+
# @param [Hash] options 可选参数
|
32
|
+
# @option options [String] :parent_id 父分组 ID
|
33
|
+
# @option options [Integer] :type 频道类型,1 文字,2 语音,默认为 1
|
34
|
+
# @option options [Integer] :limit_amount 语音频道人数限制,最大 99
|
35
|
+
# @option options [Integer] :voice_quality 语音音质,默认为 2。1 流畅,2 正常,3 高质量
|
36
|
+
# @return [KHL::HTTP::Response]
|
37
|
+
def create(guild_id, name, options = {})
|
38
|
+
post(options.merge(guild_id: guild_id, name: name))
|
39
|
+
end
|
40
|
+
|
41
|
+
# 删除频道
|
42
|
+
# @param [String] channel_id 频道 ID
|
43
|
+
# @return [KHL::HTTP::Response]
|
44
|
+
def delete(channel_id)
|
45
|
+
post(channel_id: channel_id)
|
46
|
+
end
|
47
|
+
|
48
|
+
# 语音频道之间移动用户
|
49
|
+
# @note 只能在语音频道之间移动,用户也必须在其他语音频道在线才能够移动到目标频道
|
50
|
+
# @param [String] target_id 频道 ID,需要是语音频道
|
51
|
+
# @param [Array] user_ids 用户 ID 数组
|
52
|
+
# @return [KHL::HTTP::Response]
|
53
|
+
def move_user(target_id, user_ids)
|
54
|
+
post(target_id: target_id, user_ids: user_ids)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 频道角色权限相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/channel
|
9
|
+
class ChannelRole < Base
|
10
|
+
# 频道角色权限详情
|
11
|
+
# @param [String] channel_id 频道 ID
|
12
|
+
# @return [KHL::HTTP::Response]
|
13
|
+
def index(channel_id)
|
14
|
+
get(channel_id: channel_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
# 创建频道角色权限
|
18
|
+
# @param [String] channel_id 频道 ID,如果频道是分组的 ID,会同步给所有 sync=1 的子频道
|
19
|
+
# @param [Hash] options
|
20
|
+
# @option options [String] :type value 的类型,只能为 "role_id","user_id",不传则默认为 "user_id"
|
21
|
+
# @option options [String] :value 根据 type 的值,为 用户 ID 或 频道 ID
|
22
|
+
# @return [KHL::HTTP::Response]
|
23
|
+
def create(channel_id, options = {})
|
24
|
+
post(options.merge(channel_id: channel_id))
|
25
|
+
end
|
26
|
+
|
27
|
+
# 更新频道角色权限
|
28
|
+
# @param [String] channel_id 频道 ID,如果频道是分组的 ID,会同步给所有 sync=1 的子频道
|
29
|
+
# @param [Hash] options
|
30
|
+
# @option options [String] :type value 的类型,只能为 "role_id","user_id",不传则默认为 "user_id"
|
31
|
+
# @option options [String] :value 根据 type 的值,为 用户 ID 或 频道 ID
|
32
|
+
# @option options [Integer] :allow 默认为 0,想要设置的允许的权限值
|
33
|
+
# @option options [Integer] :deny 默认为 0,想要设置的拒绝的权限值
|
34
|
+
# @return [KHL::HTTP::Response]
|
35
|
+
def update(channel_id, options = {})
|
36
|
+
post(options.merge(channel_id: channel_id))
|
37
|
+
end
|
38
|
+
|
39
|
+
# 删除频道角色权限
|
40
|
+
# @param [String] channel_id 频道 ID,如果频道是分组的 ID,会同步给所有 sync=1 的子频道
|
41
|
+
# @param [Hash] options
|
42
|
+
# @option options [String] :type value 的类型,只能为 "role_id","user_id",不传则默认为 "user_id"
|
43
|
+
# @option options [String] :value 根据 type 的值,为用户 ID 或频道 ID
|
44
|
+
# @return [KHL::HTTP::Response]
|
45
|
+
def delete(channel_id, options = {})
|
46
|
+
post(options.merge(channel_id: channel_id))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 频道用户相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/channel-user
|
9
|
+
class ChannelUser < Base
|
10
|
+
# 根据用户 ID 和服务器 ID 获取用户所在语音频道
|
11
|
+
# @param [String] guild_id 服务器 ID
|
12
|
+
# @param [String] user_id 用户 ID
|
13
|
+
# @param [Hash] options 可选参数
|
14
|
+
# @option options [Integer] :page 页数
|
15
|
+
# @option options [Integer] :page_size 每页数据数量
|
16
|
+
# @return [KHL::HTTP::Response]
|
17
|
+
def get_joined_channel(guild_id, user_id, options = {})
|
18
|
+
get(options.merge(guild_id: guild_id, user_id: user_id))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "asset"
|
4
|
+
require_relative "badge"
|
5
|
+
require_relative "blacklist"
|
6
|
+
require_relative "channel"
|
7
|
+
require_relative "channel_role"
|
8
|
+
require_relative "channel_user"
|
9
|
+
require_relative "direct_message"
|
10
|
+
require_relative "game"
|
11
|
+
require_relative "gateway"
|
12
|
+
require_relative "guild"
|
13
|
+
require_relative "guild_emoji"
|
14
|
+
require_relative "guild_mute"
|
15
|
+
require_relative "guild_role"
|
16
|
+
require_relative "intimacy"
|
17
|
+
require_relative "invite"
|
18
|
+
require_relative "message"
|
19
|
+
require_relative "user"
|
20
|
+
require_relative "user_chat"
|
21
|
+
|
22
|
+
module KHL
|
23
|
+
module HTTP
|
24
|
+
# Client for the KHL HTTP API
|
25
|
+
# @example
|
26
|
+
# client = KHL::HTTP::Client.new(token: "bot_token")
|
27
|
+
# client.guild.list # Call guild/list API
|
28
|
+
class Client
|
29
|
+
attr_reader :asset,
|
30
|
+
:badge,
|
31
|
+
:blacklist,
|
32
|
+
:channel,
|
33
|
+
:channel_role,
|
34
|
+
:channel_user,
|
35
|
+
:direct_message,
|
36
|
+
:game,
|
37
|
+
:gateway,
|
38
|
+
:guild,
|
39
|
+
:guild_emoji,
|
40
|
+
:guild_mute,
|
41
|
+
:guild_role,
|
42
|
+
:intimacy,
|
43
|
+
:invite,
|
44
|
+
:message,
|
45
|
+
:user,
|
46
|
+
:user_chat
|
47
|
+
|
48
|
+
# @param config [Hash] Config
|
49
|
+
# @option config [String] :token Bot token (required)
|
50
|
+
# @option config [String] :token_type Token type
|
51
|
+
# @option config [String] :language Language
|
52
|
+
def initialize(config = {})
|
53
|
+
raise ArgumentError, "missing token" unless config[:token]
|
54
|
+
config[:token_type] ||= "Bot"
|
55
|
+
config[:language] ||= "zh-cn"
|
56
|
+
|
57
|
+
@asset = Asset.new(config)
|
58
|
+
@badge = Badge.new(config)
|
59
|
+
@blacklist = Blacklist.new(config)
|
60
|
+
@channel = Channel.new(config)
|
61
|
+
@channel_role = ChannelRole.new(config)
|
62
|
+
@channel_user = ChannelUser.new(config)
|
63
|
+
@direct_message = DirectMessage.new(config)
|
64
|
+
@game = Game.new(config)
|
65
|
+
@gateway = Gateway.new(config)
|
66
|
+
@guild = Guild.new(config)
|
67
|
+
@guild_emoji = GuildEmoji.new(config)
|
68
|
+
@guild_mute = GuildMute.new(config)
|
69
|
+
@guild_role = GuildRole.new(config)
|
70
|
+
@intimacy = Intimacy.new(config)
|
71
|
+
@invite = Invite.new(config)
|
72
|
+
@message = Message.new(config)
|
73
|
+
@user = User.new(config)
|
74
|
+
@user_chat = UserChat.new(config)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 用户私聊消息相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/direct-message
|
9
|
+
class DirectMessage < Base
|
10
|
+
# 获取私信聊天消息列表
|
11
|
+
# @note 此接口非标准分页,需要根据参考消息来查询相邻分页的消息
|
12
|
+
# @param [Hash] options 可选参数
|
13
|
+
# @option options [String] :target_id 用户 ID,后端会自动创建会话。有此参数之后可不传 chat_code 参数
|
14
|
+
# @option options [String] :chat_code 会话 Code。chat_code 与 target_id 必须传一个
|
15
|
+
# @option options [String] :msg_id 消息 ID,不传则查询最新消息
|
16
|
+
# @option options [String] :flag 查询模式,有三种模式可以选择 before、around、after。不传则默认查询最新的消息
|
17
|
+
# @option options [Integer] :page 页数
|
18
|
+
# @option options [Integer] :page_size 当前分页消息数量,默认 50
|
19
|
+
# @return [KHL::HTTP::Response]
|
20
|
+
def list(options = {})
|
21
|
+
get(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# 发送私信聊天消息
|
25
|
+
# @param [String] content 消息内容
|
26
|
+
# @param [Hash] options 可选参数
|
27
|
+
# @option options [Integer] :type 消息类型,不传默认为 1,代表文本类型。9 代表 kmarkdown 消息,10 代表卡片消息
|
28
|
+
# @option options [String] :target_id 用户 ID,后端会自动创建会话。有此参数之后可不传 chat_code 参数
|
29
|
+
# @option options [String] :chat_code 会话 Code。chat_code 与 target_id 必须传一个
|
30
|
+
# @option options [String] :quote 回复某条消息的 msg_id
|
31
|
+
# @option options [String] :nonce 随机字符串,服务端不做处理, 原样返回
|
32
|
+
# @return [KHL::HTTP::Response]
|
33
|
+
def create(content, options = {})
|
34
|
+
post(options.merge(content: content))
|
35
|
+
end
|
36
|
+
|
37
|
+
# 更新私信聊天消息
|
38
|
+
# @note 目前支持消息 type 为 9、10 的修改,即 KMarkdown 和 CardMessage
|
39
|
+
# @param [String] content 消息内容
|
40
|
+
# @param [Hash] options 可选参数
|
41
|
+
# @option options [String] :msg_id 消息 ID
|
42
|
+
# @option options [String] :quote 回复某条消息的 msg_id。如果为空,则代表删除回复,不传则无影响
|
43
|
+
# @return [KHL::HTTP::Response]
|
44
|
+
def update(content, options = {})
|
45
|
+
post(options.merge(content: content))
|
46
|
+
end
|
47
|
+
|
48
|
+
# 删除私信聊天消息
|
49
|
+
# @note 只能删除自己的消息
|
50
|
+
# @param [Hash] options 可选参数
|
51
|
+
# @option options [String] :msg_id 消息 ID
|
52
|
+
# @return [KHL::HTTP::Response]
|
53
|
+
def delete(options = {})
|
54
|
+
post(options)
|
55
|
+
end
|
56
|
+
|
57
|
+
# 获取频道消息某回应的用户列表
|
58
|
+
# @param [String] msg_id 消息 ID
|
59
|
+
# @param [Hash] options 可选参数
|
60
|
+
# @option options [String] :emoji Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode
|
61
|
+
# @return [KHL::HTTP::Response]
|
62
|
+
def reaction_list(msg_id, options = {})
|
63
|
+
get(options.merge(msg_id: msg_id))
|
64
|
+
end
|
65
|
+
|
66
|
+
# 给某个消息添加回应
|
67
|
+
# @param [String] msg_id 消息 ID
|
68
|
+
# @param [String] emoji Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode
|
69
|
+
# @return [KHL::HTTP::Response]
|
70
|
+
def add_reaction(msg_id, emoji)
|
71
|
+
post(msg_id: msg_id, emoji: emoji)
|
72
|
+
end
|
73
|
+
|
74
|
+
# 删除消息的某个回应
|
75
|
+
# @param [String] msg_id 消息 ID
|
76
|
+
# @param [String] emoji Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode
|
77
|
+
# @param [Hash] options 可选参数
|
78
|
+
# @option options [String] :user_id 用户 ID,如果不填则为自己的 ID。删除别人的回应需要有管理频道消息的权限
|
79
|
+
# @return [KHL::HTTP::Response]
|
80
|
+
def delete_reaction(msg_id, emoji, options = {})
|
81
|
+
post(options.merge(msg_id: msg_id, emoji: emoji))
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 用户动态相关接口-游戏/进程/音乐
|
8
|
+
# https://developer.kaiheila.cn/doc/http/game
|
9
|
+
class Game < Base
|
10
|
+
# 游戏列表
|
11
|
+
# @return [KHL::HTTP::Response]
|
12
|
+
def list
|
13
|
+
get(action: nil)
|
14
|
+
end
|
15
|
+
|
16
|
+
# 添加游戏
|
17
|
+
# @note 本接口有数据插入频率限制,单日最大可创建 5 个游戏数据
|
18
|
+
# @param [String] name 名称
|
19
|
+
# @param [Hash] options 可选参数
|
20
|
+
# @option options [String] :process_name 进程名
|
21
|
+
# @option options [String] :icon 图标
|
22
|
+
# @return [KHL::HTTP::Response]
|
23
|
+
def create(name, options = {})
|
24
|
+
post(options.merge(name: name))
|
25
|
+
end
|
26
|
+
|
27
|
+
# 更新游戏
|
28
|
+
# @param [Integer] id ID
|
29
|
+
# @param [Hash] options 可选参数
|
30
|
+
# @option options [String] :name 名称
|
31
|
+
# @option options [String] :icon 图标
|
32
|
+
# @return [KHL::HTTP::Response]
|
33
|
+
def update(id, options = {})
|
34
|
+
post(options.merge(id: id))
|
35
|
+
end
|
36
|
+
|
37
|
+
# 删除游戏
|
38
|
+
# @param [Integer] id ID
|
39
|
+
# @return [KHL::HTTP::Response]
|
40
|
+
def delete(id)
|
41
|
+
post(id: id)
|
42
|
+
end
|
43
|
+
|
44
|
+
# 添加游戏记录-开始玩
|
45
|
+
# @param [Integer] id 游戏 ID
|
46
|
+
# @param [Integer] data_type 请求数据类型,固定传 1(游戏)
|
47
|
+
# @return [KHL::HTTP::Response]
|
48
|
+
def activity(id, data_type)
|
49
|
+
post(id: id, data_type: data_type)
|
50
|
+
end
|
51
|
+
|
52
|
+
# 删除游戏记录-结束玩
|
53
|
+
# @return [KHL::HTTP::Response]
|
54
|
+
def delete_activity
|
55
|
+
post
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module KHL
|
6
|
+
module HTTP
|
7
|
+
# 网关相关接口
|
8
|
+
# https://developer.kaiheila.cn/doc/http/gateway
|
9
|
+
class Gateway < Base
|
10
|
+
# 获取网关连接地址
|
11
|
+
# @param [Hash] options 可选参数
|
12
|
+
# @option options [Integer] :compress 下发数据是否压缩,默认为 1,代表压缩
|
13
|
+
# @return [KHL::HTTP::Response]
|
14
|
+
def index(options = {})
|
15
|
+
get(options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|