opqr 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 +4 -4
- data/.idea/.gitignore +8 -0
- data/.idea/modules.xml +8 -0
- data/.idea/opqr.iml +56 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile.lock +32 -0
- data/README.md +24 -39
- data/example/main.rb +13 -0
- data/example/plugins/dxx.rb +22 -0
- data/lib/opqr/bot.rb +2 -3
- data/lib/opqr/version.rb +1 -1
- data/lib/opqr/wsserver.rb +31 -16
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5e8b312818a0a13342dd553757d78f2a34e3d8bf3b2174f2b098f11e8f71169
|
4
|
+
data.tar.gz: '092ca822092032a6655d4465fb89c032cc476adb992d362bb50111d8db3490b4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a43a39f4a94c53e3304d018695149ac3beb0f7fee88baf00e53452a1da299f61e104bf0fc93af557ea8318864cf5316b754784bde76e8432096a70ac605544
|
7
|
+
data.tar.gz: ca92e33a7b2c24ac68c00e03956a6868d1094f7295c6dd2a5daa45f771e961b1d2f0d57af2241d6eb1c9790eeef480fac9e0ce61f844186e1b9192297acb95c7
|
data/.idea/.gitignore
ADDED
data/.idea/modules.xml
ADDED
data/.idea/opqr.iml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="jdk" jdkName="ruby-3.2.2-p53" jdkType="RUBY_SDK" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, ruby-3.2.2-p53) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="eventmachine (v1.2.7, ruby-3.2.2-p53) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.17.0, ruby-3.2.2-p53) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-3.2.2-p53) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket (v1.2.9, ruby-3.2.2-p53) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket-eventmachine-base (v1.2.0, ruby-3.2.2-p53) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket-eventmachine-server (v1.0.1, ruby-3.2.2-p53) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket-native (v1.0.0, ruby-3.2.2-p53) [gem]" level="application" />
|
22
|
+
</component>
|
23
|
+
<component name="RakeTasksCache">
|
24
|
+
<option name="myRootTask">
|
25
|
+
<RakeTaskImpl id="rake">
|
26
|
+
<subtasks>
|
27
|
+
<RakeTaskImpl description="Build opqr-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
28
|
+
<RakeTaskImpl id="build">
|
29
|
+
<subtasks>
|
30
|
+
<RakeTaskImpl description="Generate SHA512 checksum if opqr-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
31
|
+
</subtasks>
|
32
|
+
</RakeTaskImpl>
|
33
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
34
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
35
|
+
<RakeTaskImpl description="Build and install opqr-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
36
|
+
<RakeTaskImpl id="install">
|
37
|
+
<subtasks>
|
38
|
+
<RakeTaskImpl description="Build and install opqr-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
39
|
+
</subtasks>
|
40
|
+
</RakeTaskImpl>
|
41
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push opqr-0.1.0.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
42
|
+
<RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
|
43
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
44
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
45
|
+
<RakeTaskImpl id="release">
|
46
|
+
<subtasks>
|
47
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
48
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
49
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
50
|
+
</subtasks>
|
51
|
+
</RakeTaskImpl>
|
52
|
+
</subtasks>
|
53
|
+
</RakeTaskImpl>
|
54
|
+
</option>
|
55
|
+
</component>
|
56
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
opqr (0.1.0)
|
5
|
+
websocket-eventmachine-server (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://gems.ruby-china.com/
|
9
|
+
specs:
|
10
|
+
eventmachine (1.2.7)
|
11
|
+
minitest (5.17.0)
|
12
|
+
rake (13.0.6)
|
13
|
+
websocket (1.2.9)
|
14
|
+
websocket-eventmachine-base (1.2.0)
|
15
|
+
eventmachine (~> 1.0)
|
16
|
+
websocket (~> 1.0)
|
17
|
+
websocket-native (~> 1.0)
|
18
|
+
websocket-eventmachine-server (1.0.1)
|
19
|
+
websocket-eventmachine-base (~> 1.0)
|
20
|
+
websocket-native (1.0.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
x64-mingw-ucrt
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
minitest (~> 5.0)
|
27
|
+
opqr!
|
28
|
+
rake (~> 13.0)
|
29
|
+
websocket-eventmachine-server (~> 1.0)
|
30
|
+
|
31
|
+
BUNDLED WITH
|
32
|
+
2.4.10
|
data/README.md
CHANGED
@@ -1,39 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
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.
|
26
|
-
|
27
|
-
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).
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/opqr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/opqr/blob/master/CODE_OF_CONDUCT.md).
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
-
|
37
|
-
## Code of Conduct
|
38
|
-
|
39
|
-
Everyone interacting in the Opqr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/opqr/blob/master/CODE_OF_CONDUCT.md).
|
1
|
+
## opqr
|
2
|
+
|
3
|
+
OPQ机器人的Ruby语言SDK
|
4
|
+
|
5
|
+
## 使用说明
|
6
|
+
项目结构
|
7
|
+
```ruby
|
8
|
+
My_Project
|
9
|
+
| |-plugins
|
10
|
+
| |---dxx.rb
|
11
|
+
|---main.rb
|
12
|
+
|
13
|
+
1、main.rb为入口文件
|
14
|
+
2、plugins文件夹存放实现功能的插件
|
15
|
+
3、具体见example文件夹
|
16
|
+
```
|
17
|
+
获取opqr
|
18
|
+
```ruby
|
19
|
+
gem install opqr
|
20
|
+
```
|
21
|
+
运行
|
22
|
+
```ruby
|
23
|
+
ruby main.rb
|
24
|
+
```
|
data/example/main.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'opqr'
|
3
|
+
# 加载插件
|
4
|
+
plugin_dir = File.join(File.dirname(__FILE__), 'plugins')
|
5
|
+
ps = OPQ::PluginLoader.new
|
6
|
+
ps.load_all(plugin_dir)
|
7
|
+
# 必须是个数组
|
8
|
+
# 使用OPQ::QqObj.new创建需要监听消息的对象,加入对象数组ob
|
9
|
+
# 功能请在插件目录添加插件实现
|
10
|
+
ob = []
|
11
|
+
ob << OPQ::QqObj.new(1294222408,ps.plugins)
|
12
|
+
bot = OPQ::Bot.new("127.0.0.1",8086,ob)
|
13
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'opqr'
|
3
|
+
# ctx结构如下
|
4
|
+
# @type
|
5
|
+
# @from_uin
|
6
|
+
# @sender_uin
|
7
|
+
# @text
|
8
|
+
# @msg_type
|
9
|
+
# @raw_json
|
10
|
+
|
11
|
+
class Dxx < OPQ::PluginBase
|
12
|
+
def receive_qq(qq, ctx)
|
13
|
+
p "dxx收到来自好友的消息"
|
14
|
+
OPQ::Api.new.send_text_qq(941094692,"我现在发消息给你",qq)
|
15
|
+
end
|
16
|
+
def receive_group(qq, ctx)
|
17
|
+
p "dxx收到了来自群的消息"
|
18
|
+
if ctx.text == "回我"
|
19
|
+
OPQ::Api.new.send_text_group(435994283,"我收到了你的消息",qq)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/opqr/bot.rb
CHANGED
@@ -5,13 +5,12 @@ require_relative 'api'
|
|
5
5
|
module OPQ
|
6
6
|
class Bot
|
7
7
|
attr_accessor :observer, :ws
|
8
|
-
def initialize(api_url, http_port,
|
8
|
+
def initialize(api_url, http_port, observers)
|
9
9
|
$http_port = http_port
|
10
|
-
$websocket_port = websocket_port
|
11
10
|
$api_url = api_url
|
12
11
|
@observer = Observer.new(observers)
|
13
12
|
puts "[BOT] 正在尝试连接WS,请稍等~"
|
14
|
-
@ws = WsServer.new(
|
13
|
+
@ws = WsServer.new(@observer)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
data/lib/opqr/version.rb
CHANGED
data/lib/opqr/wsserver.rb
CHANGED
@@ -1,30 +1,45 @@
|
|
1
1
|
# encoding=utf-8
|
2
2
|
require 'eventmachine'
|
3
3
|
require 'websocket-eventmachine-server'
|
4
|
+
require 'faye/websocket'
|
4
5
|
module OPQ
|
5
6
|
class WsServer
|
6
|
-
def initialize(
|
7
|
-
@host = host
|
8
|
-
@port = port
|
7
|
+
def initialize(observer)
|
9
8
|
@observer = observer
|
10
9
|
self.start
|
11
10
|
end
|
12
11
|
def start
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
EM.run {
|
13
|
+
ws = Faye::WebSocket::Client.new('ws://'+$api_url+':'+$http_port+'/ws')
|
14
|
+
ws.on :open do |event|
|
15
|
+
puts "[WS] 连接已建立"
|
16
|
+
end
|
17
|
+
|
18
|
+
ws.on :message do |event|
|
19
|
+
puts "[WS] 收到数据-->".force_encoding('UTF-8')+ "#{event.data}".force_encoding('UTF-8')
|
20
|
+
@observer.on_message_received(event.data)
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
ws.on :close do |event|
|
24
|
+
puts "[WS] 连接已断开"
|
25
|
+
ws = nil
|
27
26
|
end
|
27
|
+
}
|
28
|
+
# EM.run do
|
29
|
+
# WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => @port, :mode => :async) do |ws|
|
30
|
+
# ws.onopen do
|
31
|
+
# puts "[WS] 连接已建立"
|
32
|
+
# end
|
33
|
+
# ws.onmessage do |msg, type|
|
34
|
+
# puts "[WS] 收到数据-->".force_encoding('UTF-8')+ "#{msg}".force_encoding('UTF-8')
|
35
|
+
# @observer.on_message_received(msg)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# ws.onclose do
|
39
|
+
# puts "[WS] 连接已断开"
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
28
43
|
end
|
29
44
|
end
|
30
45
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opqr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- intchensc
|
@@ -31,12 +31,19 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".idea/.gitignore"
|
35
|
+
- ".idea/modules.xml"
|
36
|
+
- ".idea/opqr.iml"
|
37
|
+
- ".idea/vcs.xml"
|
34
38
|
- CHANGELOG.md
|
35
39
|
- CODE_OF_CONDUCT.md
|
36
40
|
- Gemfile
|
41
|
+
- Gemfile.lock
|
37
42
|
- LICENSE.txt
|
38
43
|
- README.md
|
39
44
|
- Rakefile
|
45
|
+
- example/main.rb
|
46
|
+
- example/plugins/dxx.rb
|
40
47
|
- lib/opqr.rb
|
41
48
|
- lib/opqr/api.rb
|
42
49
|
- lib/opqr/bot.rb
|