opqr 0.1.2 → 0.1.4

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: 20a52c3e306b1d2b8ad308fcd87036e12286b3c73a07b7318c0eb704c4a8453a
4
- data.tar.gz: 1b8dee574c4ca006bf3319440f34408a171a61681a187f29c534acdf1851b9c8
3
+ metadata.gz: d2801c6161e2440277356456195199bc30ffe411f7b46650afb246d0f0b3ebdf
4
+ data.tar.gz: 657a5c3edbc0efaad67eba72a3c3cc0fe26233f64c792f20b3fd210fa5651ecb
5
5
  SHA512:
6
- metadata.gz: 9fe904cf49d566a43e5a5a8998cb7a2ffef6e4b230de6e1e7236217d2db7be0135250b9843e19da6d6dad457f4d685ec09e504ab1700e346360c00aaa0f248e0
7
- data.tar.gz: 2ecc6e3df3a963a85071a0117251191285ba5d5fa90573a5858cbd704efdfac707fb15f0f744189da714091df5d8bf6d738de22836f7ea75ea38578740b1bee7
6
+ metadata.gz: 19b67cd2247ff4d846decab98079dce9a46cc5e2aa3d0cef855673267b28542d1a5a247520177fa73f43e57e002e0a649c67b2f9b247cb7e502294e40452445b
7
+ data.tar.gz: 775a5018337cf7845fb23d2fe5b2e82ec778f4feb917d90cb64acaa96fba43746fe2d39275904a2ab30f07b70861d9ba0db9e1b150c1fae61b4207124252e6b6
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/opqr.iml" filepath="$PROJECT_DIR$/.idea/opqr.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/opqr.iml ADDED
@@ -0,0 +1,59 @@
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="faye-websocket (v0.11.2, ruby-3.2.2-p53) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.17.0, ruby-3.2.2-p53) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-3.2.2-p53) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="websocket (v1.2.9, ruby-3.2.2-p53) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.5, ruby-3.2.2-p53) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="websocket-eventmachine-base (v1.2.0, ruby-3.2.2-p53) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="websocket-eventmachine-server (v1.0.1, ruby-3.2.2-p53) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, ruby-3.2.2-p53) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="websocket-native (v1.0.0, ruby-3.2.2-p53) [gem]" level="application" />
25
+ </component>
26
+ <component name="RakeTasksCache">
27
+ <option name="myRootTask">
28
+ <RakeTaskImpl id="rake">
29
+ <subtasks>
30
+ <RakeTaskImpl description="Build opqr-0.1.3.gem into the pkg directory" fullCommand="build" id="build" />
31
+ <RakeTaskImpl id="build">
32
+ <subtasks>
33
+ <RakeTaskImpl description="Generate SHA512 checksum if opqr-0.1.3.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
34
+ </subtasks>
35
+ </RakeTaskImpl>
36
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
37
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
38
+ <RakeTaskImpl description="Build and install opqr-0.1.3.gem into system gems" fullCommand="install" id="install" />
39
+ <RakeTaskImpl id="install">
40
+ <subtasks>
41
+ <RakeTaskImpl description="Build and install opqr-0.1.3.gem into system gems without network access" fullCommand="install:local" id="local" />
42
+ </subtasks>
43
+ </RakeTaskImpl>
44
+ <RakeTaskImpl description="Create tag v0.1.3 and build and push opqr-0.1.3.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
45
+ <RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
46
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
47
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
48
+ <RakeTaskImpl id="release">
49
+ <subtasks>
50
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
51
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
52
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
53
+ </subtasks>
54
+ </RakeTaskImpl>
55
+ </subtasks>
56
+ </RakeTaskImpl>
57
+ </option>
58
+ </component>
59
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/Gemfile CHANGED
@@ -11,3 +11,4 @@ gem "minitest", "~> 5.0"
11
11
 
12
12
  gem 'websocket-eventmachine-server', '~> 1.0'
13
13
 
14
+ gem 'faye-websocket', '~> 0.11.2'
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ opqr (0.1.3)
5
+ faye-websocket (~> 0.11.2)
6
+
7
+ GEM
8
+ remote: https://gems.ruby-china.com/
9
+ specs:
10
+ eventmachine (1.2.7)
11
+ faye-websocket (0.11.2)
12
+ eventmachine (>= 0.12.0)
13
+ websocket-driver (>= 0.5.1)
14
+ minitest (5.17.0)
15
+ rake (13.0.6)
16
+ websocket (1.2.9)
17
+ websocket-driver (0.7.5)
18
+ websocket-extensions (>= 0.1.0)
19
+ websocket-eventmachine-base (1.2.0)
20
+ eventmachine (~> 1.0)
21
+ websocket (~> 1.0)
22
+ websocket-native (~> 1.0)
23
+ websocket-eventmachine-server (1.0.1)
24
+ websocket-eventmachine-base (~> 1.0)
25
+ websocket-extensions (0.1.5)
26
+ websocket-native (1.0.0)
27
+
28
+ PLATFORMS
29
+ x64-mingw-ucrt
30
+
31
+ DEPENDENCIES
32
+ faye-websocket (~> 0.11.2)
33
+ minitest (~> 5.0)
34
+ opqr!
35
+ rake (~> 13.0)
36
+ websocket-eventmachine-server (~> 1.0)
37
+
38
+ BUNDLED WITH
39
+ 2.4.10
data/README.md CHANGED
@@ -1,39 +1,24 @@
1
- # Opqr
2
-
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/opqr`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Development
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, websocket_port, observers)
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(api_url,websocket_port, @observer)
13
+ @ws = WsServer.new(@observer)
15
14
  end
16
15
  end
17
16
  end
data/lib/opqr/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Opqr
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
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(host, port, observer)
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
- EM.run do
14
- WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => @port, :mode => :async) do |ws|
15
- ws.onopen do
16
- puts "[WS] 连接已建立"
17
- end
18
- ws.onmessage do |msg, type|
19
- puts "[WS] 收到数据-->".force_encoding('UTF-8')+ "#{msg}".force_encoding('UTF-8')
20
- @observer.on_message_received(msg)
21
- end
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
- ws.onclose do
24
- puts "[WS] 连接已断开"
25
- end
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
 
data/opqr.gemspec CHANGED
@@ -29,8 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "websocket-eventmachine-server", '~> 1.0'
33
-
32
+ spec.add_dependency 'faye-websocket', '~> 0.11.2'
34
33
  # For more information and examples about making a new gem, check out our
35
34
  # guide at: https://bundler.io/guides/creating_gem.html
36
35
  end
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - intchensc
@@ -11,19 +11,19 @@ cert_chain: []
11
11
  date: 2023-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: websocket-eventmachine-server
14
+ name: faye-websocket
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 0.11.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: 0.11.2
27
27
  description:
28
28
  email:
29
29
  - intchensc@qq.com
@@ -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