Class: KHL::HTTP::DirectMessage

Inherits:
Base
  • Object
show all
Defined in:
lib/khl/http/direct_message.rb

Overview

用户私聊消息相关接口 developer.kaiheila.cn/doc/http/direct-message

Constant Summary

Constants inherited from Base

Base::API_VERSION, Base::BASE_URL, Base::END_POINT

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #post, #post_file

Constructor Details

This class inherits a constructor from KHL::HTTP::Base

Instance Method Details

#add_reaction(msg_id, emoji) ⇒ KHL::HTTP::Response

给某个消息添加回应

Parameters:

  • msg_id (String)

    消息 ID

  • emoji (String)

    Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

Returns:



70
71
72
# File 'lib/khl/http/direct_message.rb', line 70

def add_reaction(msg_id, emoji)
  post(msg_id: msg_id, emoji: emoji)
end

#create(content, options = {}) ⇒ KHL::HTTP::Response

发送私信聊天消息

Parameters:

  • content (String)

    消息内容

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :type (Integer)

    消息类型,不传默认为 1,代表文本类型。9 代表 kmarkdown 消息,10 代表卡片消息

  • :target_id (String)

    用户 ID,后端会自动创建会话。有此参数之后可不传 chat_code 参数

  • :chat_code (String)

    会话 Code。chat_code 与 target_id 必须传一个

  • :quote (String)

    回复某条消息的 msg_id

  • :nonce (String)

    随机字符串,服务端不做处理, 原样返回

Returns:



33
34
35
# File 'lib/khl/http/direct_message.rb', line 33

def create(content, options = {})
  post(options.merge(content: content))
end

#delete(options = {}) ⇒ KHL::HTTP::Response

Note:

只能删除自己的消息

删除私信聊天消息

Parameters:

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :msg_id (String)

    消息 ID

Returns:



53
54
55
# File 'lib/khl/http/direct_message.rb', line 53

def delete(options = {})
  post(options)
end

#delete_reaction(msg_id, emoji, options = {}) ⇒ KHL::HTTP::Response

删除消息的某个回应

Parameters:

  • msg_id (String)

    消息 ID

  • emoji (String)

    Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :user_id (String)

    用户 ID,如果不填则为自己的 ID。删除别人的回应需要有管理频道消息的权限

Returns:



80
81
82
# File 'lib/khl/http/direct_message.rb', line 80

def delete_reaction(msg_id, emoji, options = {})
  post(options.merge(msg_id: msg_id, emoji: emoji))
end

#list(options = {}) ⇒ KHL::HTTP::Response

Note:

此接口非标准分页,需要根据参考消息来查询相邻分页的消息

获取私信聊天消息列表

Parameters:

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :target_id (String)

    用户 ID,后端会自动创建会话。有此参数之后可不传 chat_code 参数

  • :chat_code (String)

    会话 Code。chat_code 与 target_id 必须传一个

  • :msg_id (String)

    消息 ID,不传则查询最新消息

  • :flag (String)

    查询模式,有三种模式可以选择 before、around、after。不传则默认查询最新的消息

  • :page (Integer)

    页数

  • :page_size (Integer)

    当前分页消息数量,默认 50

Returns:



20
21
22
# File 'lib/khl/http/direct_message.rb', line 20

def list(options = {})
  get(options)
end

#reaction_list(msg_id, options = {}) ⇒ KHL::HTTP::Response

获取频道消息某回应的用户列表

Parameters:

  • msg_id (String)

    消息 ID

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :emoji (String)

    Emoji ID,可以为 GuildEmoji 或者 Emoji,注意:在 GET 中,应该进行 urlencode

Returns:



62
63
64
# File 'lib/khl/http/direct_message.rb', line 62

def reaction_list(msg_id, options = {})
  get(options.merge(msg_id: msg_id))
end

#update(content, options = {}) ⇒ KHL::HTTP::Response

Note:

目前支持消息 type 为 9、10 的修改,即 KMarkdown 和 CardMessage

更新私信聊天消息

Parameters:

  • content (String)

    消息内容

  • options (Hash) (defaults to: {})

    可选参数

Options Hash (options):

  • :msg_id (String)

    消息 ID

  • :quote (String)

    回复某条消息的 msg_id。如果为空,则代表删除回复,不传则无影响

Returns:



44
45
46
# File 'lib/khl/http/direct_message.rb', line 44

def update(content, options = {})
  post(options.merge(content: content))
end