Class: CQHttp::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/Bot/Bot.rb

Overview

消息处理,ws连接

Example:

CQHttp::Bot.connect host: host, port: port {|bot| ... }

Defined Under Namespace

Classes: Sender, Target, WebSocket

Class Method Summary collapse

Class Method Details

.connect(host:, port:) {|client| ... } ⇒ WebSocket

新建连接

Parameters:

  • host (String)
  • port (Number)

Yields:

  • (client)

Returns:


53
54
55
56
57
58
59
60
61
# File 'lib/Bot/Bot.rb', line 53

def self.connect(host:, port:)
  url = URI::WS.build(host: host, port: port)
  Api.setUrl()
  Utils.log '正在连接到 ' << url.to_s
  client = ::CQHttp::Bot::WebSocket.new(url)
  yield client if block_given?
  client.connect
  client
end