ruby-cqhttp 0.1.2 → 0.1.3

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: 925802d93d0690ccc22b020a3236b52c837b3d0961d55a9962cd9bb4f6d55b69
4
- data.tar.gz: ac87d2efe8fc65a2f8a3b6c5216306b69c7c59b25c68c3f1c9067b4b2138c87a
3
+ metadata.gz: f4ded7c0bb8d8255401a9d13b5c98eafdba3324f7221bf6ef4e1c0bf7646ba8e
4
+ data.tar.gz: 2cc88a1e903da48f2b74859f3f7bc8a7c5cc2292d70061f219d528c1b90ead2e
5
5
  SHA512:
6
- metadata.gz: c1e82a77d99140324a348d12d5aac54a5dffa137c577ba9260773607849dfa596934cd79a86ad6f98d35f1ec4ad8b4020eac8049e1bf2b1a38908804d517fc07
7
- data.tar.gz: 483be6c942157ed36fe9f206e2a6b14265dd563a6441e5effc36e9ffa9d18d03dbc3060932c17d2f5f7a34d2ca36936c4677619d9db2fb2395517b3330da2454
6
+ metadata.gz: 8e2d94cbf60ef8697ac9a8fef81a46051939f2daac915ddb4b8b6d31193ef4cd87acfb27686c4762680e0ffbfe53653d4e9ccec2a304fbac9f8b5c604073a795
7
+ data.tar.gz: 5925ec6144d391cded1963e7790907dece0a8c945e269ce0c19c2a8f5e930395e98443c607a871690db8fef6306d4e6ad4722566fb70e79b13631597cb70f5e2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Zh_Jk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # ruby-cqhttp
2
2
 
3
+ [![Badge](https://img.shields.io/badge/OneBot-11-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAxQTFRF////29vbr6+vAAAAk1hCcwAAAAR0Uk5T////AEAqqfQAAAKcSURBVHja7NrbctswDATQXfD//zlpO7FlmwAWIOnOtNaTM5JwDMa8E+PNFz7g3waJ24fviyDPgfhz8fHP39cBcBL9KoJbQUxjA2iYqHL3FAnvzhL4GtVNUcoSZe6eSHizBcK5LL7dBr2AUZlev1ARRHCljzRALIEog6H3U6bCIyqIZdAT0eBuJYaGiJaHSjmkYIZd+qSGWAQnIaz2OArVnX6vrItQvbhZJtVGB5qX9wKqCMkb9W7aexfCO/rwQRBzsDIsYx4AOz0nhAtWu7bqkEQBO0Pr+Ftjt5fFCUEbm0Sbgdu8WSgJ5NgH2iu46R/o1UcBXJsFusWF/QUaz3RwJMEgngfaGGdSxJkE/Yg4lOBryBiMwvAhZrVMUUvwqU7F05b5WLaUIN4M4hRocQQRnEedgsn7TZB3UCpRrIJwQfqvGwsg18EnI2uSVNC8t+0QmMXogvbPg/xk+Mnw/6kW/rraUlvqgmFreAA09xW5t0AFlHrQZ3CsgvZm0FbHNKyBmheBKIF2cCA8A600aHPmFtRB1XvMsJAiza7LpPog0UJwccKdzw8rdf8MyN2ePYF896LC5hTzdZqxb6VNXInaupARLDNBWgI8spq4T0Qb5H4vWfPmHo8OyB1ito+AysNNz0oglj1U955sjUN9d41LnrX2D/u7eRwxyOaOpfyevCWbTgDEoilsOnu7zsKhjRCsnD/QzhdkYLBLXjiK4f3UWmcx2M7PO21CKVTH84638NTplt6JIQH0ZwCNuiWAfvuLhdrcOYPVO9eW3A67l7hZtgaY9GZo9AFc6cryjoeFBIWeU+npnk/nLE0OxCHL1eQsc1IciehjpJv5mqCsjeopaH6r15/MrxNnVhu7tmcslay2gO2Z1QfcfX0JMACG41/u0RrI9QAAAABJRU5ErkJggg==)](https://github.com/botuniverse/onebot-11)
3
4
  [![Gem Version](https://badge.fury.io/rb/ruby-cqhttp.svg)](https://badge.fury.io/rb/ruby-cqhttp)
4
- [![yard docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/gems/ruby-cqhttp/)
5
+ [![yard docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://www.rubydoc.info/github/fantasyzhjk/ruby-cqhttp)
5
6
 
6
7
  ![图标](https://raw.githubusercontent.com/fantasyzhjk/ruby-cqhttp/main/icon.png)
7
8
 
@@ -67,4 +68,4 @@ Onebot::Core.connect url: "ws://127.0.0.1:6700", logger: logger do |bot|
67
68
  end
68
69
  ```
69
70
 
70
- **具体使用方法请查看 tests*
71
+ **具体使用方法请查看 examples*
data/lib/Core/Http/API.rb CHANGED
@@ -11,11 +11,11 @@ module Onebot
11
11
 
12
12
  # (初始化) 设置API地址
13
13
  #
14
- # @param apiIp [String]
15
- # @param apiPort [Number]
14
+ # @param host [String]
15
+ # @param port [Number]
16
16
  # @return [URI]
17
- def initialize(apiIp: '127.0.0.1', apiPort: 5700)
18
- @url = URI::HTTP.build(host: apiIp, port: apiPort)
17
+ def initialize(host: '127.0.0.1', port: 5700)
18
+ @url = URI::HTTP.build(host: host, port: port)
19
19
  @logger = Logging::EventLogger.new
20
20
  end
21
21
 
@@ -28,7 +28,6 @@ module Onebot
28
28
  #
29
29
  # @param group_id [Number]
30
30
  # @param group_name [String]
31
- # @param url [URI]
32
31
  # @return [Hash]
33
32
  def setGroupName(group_id, group_name)
34
33
  data = sendReq('set_group_name', { group_id: group_id.to_i, group_name: })
@@ -43,7 +42,6 @@ module Onebot
43
42
  # 获取图片信息
44
43
  #
45
44
  # @param file [String]
46
- # @param url [URI]
47
45
  # @return [Hash]
48
46
  def getImage(file)
49
47
  data = sendReq('get_image', { file: })
@@ -58,7 +56,6 @@ module Onebot
58
56
  # 获取消息
59
57
  #
60
58
  # @param message_id [Number]
61
- # @param url [URI]
62
59
  # @return [Hash]
63
60
  def get_msg(message_id)
64
61
  data = sendReq('get_msg', { message_id: })
@@ -74,7 +71,6 @@ module Onebot
74
71
  #
75
72
  # @param msg [String]
76
73
  # @param user_id [Number]
77
- # @param url [URI]
78
74
  # @return [Hash]
79
75
  def sendPrivateMessage(msg, user_id)
80
76
  data = sendReq('send_private_msg', { user_id:, message: msg })
@@ -91,7 +87,6 @@ module Onebot
91
87
  #
92
88
  # @param msg [String]
93
89
  # @param group_id [Number]
94
- # @param url [URI]
95
90
  # @return [Hash]
96
91
  def sendGroupMessage(msg, group_id)
97
92
  data = sendReq('send_group_msg', { group_id:, message: msg })
@@ -108,7 +103,6 @@ module Onebot
108
103
  #
109
104
  # @param flag [String]
110
105
  # @param reason [String]
111
- # @param url [URI]
112
106
  # @return [Boolean]
113
107
  def acceptFriendRequest(flag, reason = nil)
114
108
  data = sendReq('set_friend_add_request', { flag:, approve: true, remark: reason })
@@ -124,7 +118,6 @@ module Onebot
124
118
  # 拒绝好友邀请
125
119
  #
126
120
  # @param flag [String]
127
- # @param url [URI]
128
121
  # @return [Boolean]
129
122
  def refuseFriendRequest(flag)
130
123
  data = sendReq('set_friend_add_request', { flag:, approve: false })
@@ -141,7 +134,6 @@ module Onebot
141
134
  #
142
135
  # @param flag [String]
143
136
  # @param sub_type [String]
144
- # @param url [URI]
145
137
  # @return [Boolean]
146
138
  def acceptGroupRequest(flag, sub_type)
147
139
  data = sendReq('set_group_add_request', { flag:, sub_type:, approve: true })
@@ -159,7 +151,6 @@ module Onebot
159
151
  # @param flag [String]
160
152
  # @param sub_type [String]
161
153
  # @param reason [String]
162
- # @param url [URI]
163
154
  # @return [Boolean]
164
155
  def refuseGroupRequest(flag, sub_type, reason = nil)
165
156
  data = sendReq('set_group_add_request', { flag:, sub_type:, approve: false, reason: })
@@ -175,7 +166,7 @@ module Onebot
175
166
  private
176
167
 
177
168
  def sendReq(action, params, url = @url)
178
- url.path = action
169
+ url.path = '/' << action
179
170
  JSON.parse(Utils.httpPost(url, params.to_json))
180
171
  end
181
172
  end
@@ -54,15 +54,14 @@ module Onebot
54
54
  #
55
55
  # @param flag [String]
56
56
  # @param reason [String]
57
- # @param url [URI]
58
57
  # @return [Boolean]
59
58
  def acceptFriendRequest(flag, reason = nil)
60
59
  data = sendReq('set_friend_add_request', { flag:, approve: true, remark: reason })
61
60
  if parseRet(data)
62
- @logger.log '已通过好友请求'
61
+ @eventLogger.log '已通过好友请求'
63
62
  true
64
63
  else
65
- @logger.log '请求通过失败', Logger::WARN
64
+ @eventLogger.log '请求通过失败', Logger::WARN
66
65
  false
67
66
  end
68
67
  end
@@ -70,15 +69,14 @@ module Onebot
70
69
  # 拒绝好友邀请
71
70
  #
72
71
  # @param flag [String]
73
- # @param url [URI]
74
72
  # @return [Boolean]
75
73
  def refuseFriendRequest(flag)
76
74
  data = sendReq('set_friend_add_request', { flag:, approve: false })
77
75
  if parseRet(data)
78
- @logger.log '已拒绝好友请求'
76
+ @eventLogger.log '已拒绝好友请求'
79
77
  true
80
78
  else
81
- @logger.log '请求拒绝失败', Logger::WARN
79
+ @eventLogger.log '请求拒绝失败', Logger::WARN
82
80
  false
83
81
  end
84
82
  end
@@ -87,15 +85,14 @@ module Onebot
87
85
  #
88
86
  # @param flag [String]
89
87
  # @param sub_type [String]
90
- # @param url [URI]
91
88
  # @return [Boolean]
92
89
  def acceptGroupRequest(flag, sub_type)
93
90
  data = sendReq('set_group_add_request', { flag:, sub_type:, approve: true })
94
91
  if parseRet(data)
95
- @logger.log '已通过加群请求'
92
+ @eventLogger.log '已通过加群请求'
96
93
  true
97
94
  else
98
- @logger.log '请求通过失败', Logger::WARN
95
+ @eventLogger.log '请求通过失败', Logger::WARN
99
96
  false
100
97
  end
101
98
  end
@@ -105,15 +102,14 @@ module Onebot
105
102
  # @param flag [String]
106
103
  # @param sub_type [String]
107
104
  # @param reason [String]
108
- # @param url [URI]
109
105
  # @return [Boolean]
110
106
  def refuseGroupRequest(flag, sub_type, reason = nil)
111
107
  data = sendReq('set_group_add_request', { flag:, sub_type:, approve: false, reason: })
112
108
  if parseRet(data)
113
- @logger.log '已拒绝加群请求'
109
+ @eventLogger.log '已拒绝加群请求'
114
110
  true
115
111
  else
116
- @logger.log '请求拒绝失败', Logger::WARN
112
+ @eventLogger.log '请求拒绝失败', Logger::WARN
117
113
  false
118
114
  end
119
115
  end
@@ -13,14 +13,14 @@ module Onebot
13
13
  @eventLogger = Logging::EventLogger.new(logger)
14
14
  @ws = Faye::WebSocket.new(env, %w[irc xmpp], options)
15
15
  @api = API.new(@ws, @eventLogger)
16
- @eventLogger.log(['客户端', '连接', @ws.url, @ws.version], ::Logger::INFO, 'Puma')
16
+ @eventLogger.log(['客户端', '连接', @ws.url, @ws.version], ::Logger::INFO, 'Server')
17
17
 
18
18
  @ws.on :message do |event|
19
19
  Thread.new { dataParse(event.data) }
20
20
  end
21
21
 
22
22
  @ws.on :close do |event|
23
- @eventLogger.log(['客户端', '断开', event.code].to_s, ::Logger::INFO, 'Puma')
23
+ @eventLogger.log(['客户端', '断开', event.code].to_s, ::Logger::INFO, 'Server')
24
24
  @ws = nil
25
25
  end
26
26
 
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.2
4
+ version: 0.1.3
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-18 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_emitter
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: solargraph
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rack
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -73,25 +87,78 @@ dependencies:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
- type: :runtime
90
+ type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: puma
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: thin
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.2.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: goliath
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: passenger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 4.0.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 4.0.0
83
153
  description: 一个基于 OneBot 标准的 QQ 机器人框架
84
154
  email: fantasyzhjk@outlook.com
85
155
  executables: []
86
156
  extensions: []
87
- extra_rdoc_files: []
157
+ extra_rdoc_files:
158
+ - README.md
88
159
  files:
89
- - ".bundle/config"
90
- - ".gitignore"
91
- - ".rubocop.yml"
92
- - Gemfile
160
+ - LICENSE
93
161
  - README.md
94
- - icon.png
95
162
  - lib/Core/Core.rb
96
163
  - lib/Core/Http/API.rb
97
164
  - lib/Core/Logging/EventLogger.rb
@@ -102,16 +169,16 @@ files:
102
169
  - lib/Core/WebSocket/Client.rb
103
170
  - lib/Core/WebSocket/Server.rb
104
171
  - lib/onebot-ruby.rb
105
- - ruby-cqhttp.gemspec
106
- - tests/client.rb
107
- - tests/rainbows.conf
108
- - tests/server.rb
109
172
  homepage: https://github.com/fantasyzhjk/ruby-cqhttp/
110
173
  licenses:
111
174
  - MIT
112
175
  metadata: {}
113
176
  post_install_message:
114
- rdoc_options: []
177
+ rdoc_options:
178
+ - "--main"
179
+ - README.md
180
+ - "--markup"
181
+ - markdown
115
182
  require_paths:
116
183
  - lib
117
184
  required_ruby_version: !ruby/object:Gem::Requirement
data/.bundle/config DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_PATH: "vendor/bundle"
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- ruby-cqhttp-*.gem
2
- Gemfile.lock
3
-
4
- # debug files
5
- data/
6
- logs/
7
- vendor/
8
- go-cqhttp*
9
- session.token
10
- device.json
11
- config.yml
12
- .yardoc
data/.rubocop.yml DELETED
@@ -1,27 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 3.2
3
- NewCops: enable
4
- Naming/VariableName:
5
- Enabled: false
6
- Naming/MethodName:
7
- Enabled: false
8
- Naming/FileName:
9
- Enabled: false
10
- Style/AsciiComments:
11
- Enabled: false
12
- Style/FrozenStringLiteralComment:
13
- Enabled: false
14
- Style/Documentation:
15
- Enabled: false
16
- Layout/LineLength:
17
- Enabled: false
18
- Naming/MethodParameterName:
19
- Enabled: false
20
- Metrics/MethodLength:
21
- Enabled: false
22
- Metrics/AbcSize:
23
- Enabled: false
24
- Metrics/ClassLength:
25
- Enabled: false
26
- Metrics/CyclomaticComplexity:
27
- Enabled: false
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- gem 'event_emitter'
8
- gem 'eventmachine', platform: :ruby
9
- gem 'faye-websocket'
10
- gem 'json'
11
- gem 'puma'
12
- gem 'rack'
13
- gem 'solargraph'
data/icon.png DELETED
Binary file
data/ruby-cqhttp.gemspec DELETED
@@ -1,23 +0,0 @@
1
- lib = File.expand_path('lib', __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = 'ruby-cqhttp'
6
- s.version = '0.1.2'
7
- s.summary = '一个基于 OneBot 标准的 QQ 机器人框架'
8
- s.description = '一个基于 OneBot 标准的 QQ 机器人框架'
9
- s.authors = ['fantasyzhjk']
10
- s.email = 'fantasyzhjk@outlook.com'
11
- s.platform = Gem::Platform::RUBY
12
- s.homepage = 'https://github.com/fantasyzhjk/ruby-cqhttp/'
13
- s.license = 'MIT'
14
- s.files = `git ls-files -z`.split("\x0")
15
- s.require_paths = ['lib']
16
- s.required_ruby_version = '>= 2.7.0'
17
-
18
- s.add_runtime_dependency 'event_emitter'
19
- s.add_runtime_dependency 'faye-websocket'
20
- s.add_runtime_dependency 'json'
21
- s.add_runtime_dependency 'logger'
22
- s.add_runtime_dependency 'rack'
23
- end
data/tests/client.rb DELETED
@@ -1,21 +0,0 @@
1
- require '../lib/onebot-ruby'
2
-
3
- logger = Onebot::Logging::Logger.new.setLoggerLevel(Logger::INFO)
4
- api = Onebot::Http::API.new.setLogger(logger)
5
-
6
- Onebot::Core.connect url: 'ws://localhost:7700', logger: logger, options: { headers: { 'Authorization' => 'Bearer xxxxxxxxxxxx' } } do |bot|
7
- bot.on :logged do |_botqq|
8
- logger.log('我开了欸')
9
- end
10
-
11
- bot.on :privateMessage do |data|
12
- bot.sendMessage(session.message, data)
13
- end
14
-
15
- bot.on :notice do |notice_type, data|
16
- if notice_type == 'friend_recall'
17
- req = bot.get_msg(data.message_id)
18
- bot.sendPrivateMessage req.message, req.sender.user_id
19
- end
20
- end
21
- end
data/tests/rainbows.conf DELETED
@@ -1,3 +0,0 @@
1
- Rainbows! do
2
- use :EventMachine
3
- end
data/tests/server.rb DELETED
@@ -1,77 +0,0 @@
1
- require '../lib/onebot-ruby'
2
- require 'faye/websocket'
3
- require 'rack'
4
-
5
- logger = Onebot::Logging::Logger.new.setLoggerLevel(Logger::INFO)
6
- static = Rack::File.new(File.dirname(__FILE__))
7
- options = { ping: 5 }
8
-
9
- App = lambda do |env|
10
- if Faye::WebSocket.websocket?(env)
11
- bot = Onebot::WebSocket::Server.new(env:, logger:, options:)
12
-
13
- bot.on :logged do |_botqq|
14
- logger.log('我开了欸')
15
- end
16
-
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
- end
23
-
24
- bot.rack_response
25
- else
26
- static.call(env)
27
- end
28
- end
29
-
30
- def App.log(message); end
31
-
32
- port = ARGV[0] || 7000
33
- secure = ARGV[1] == 'tls'
34
- engine = ARGV[2] || 'thin'
35
- spec = File.expand_path(__dir__)
36
-
37
- Faye::WebSocket.load_adapter(engine)
38
-
39
- case engine
40
-
41
- when 'goliath'
42
- class WebSocketServer < Goliath::API
43
- def response(env)
44
- App.call(env)
45
- end
46
- end
47
-
48
- when 'puma'
49
- require 'puma/binder'
50
- require 'puma/events'
51
- events = Puma::Events.new($stdout, $stderr)
52
- binder = Puma::Binder.new(events)
53
- binder.parse(["tcp://0.0.0.0:#{port}"], App)
54
- server = Puma::Server.new(App, events)
55
- server.binder = binder
56
- server.run.join
57
-
58
- when 'rainbows'
59
- rackup = Unicorn::Configurator::RACKUP
60
- rackup[:port] = port
61
- rackup[:set_listener] = true
62
- options = rackup[:options]
63
- options[:config_file] = File.expand_path('rainbows.conf', __dir__)
64
- Rainbows::HttpServer.new(App, options).start.join
65
-
66
- when 'thin'
67
- thin = Rack::Handler.get('thin')
68
- thin.run(App, Host: '0.0.0.0', Port: port) do |server|
69
- if secure
70
- server.ssl_options = {
71
- private_key_file: spec + '/server.key',
72
- cert_chain_file: spec + '/server.crt'
73
- }
74
- server.ssl = true
75
- end
76
- end
77
- end