onebot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ require "json"
2
+
3
+ module Onebot
4
+ class Client
5
+ module ApiHelper
6
+ attr_accessor :func_list
7
+ METHODS_LIST_FILE = File.expand_path("../api.json", __FILE__)
8
+
9
+ class << self
10
+ def methods_list(file = METHODS_LIST_FILE)
11
+ @func_list = JSON.parse(File.read(file))
12
+ end
13
+
14
+ def get_default(str)
15
+ str.sub!(/^`(.+)`$/, '\1')
16
+ return str.to_i if str =~ /^[+-]?\d+$/
17
+ return true if str == "true"
18
+ return false if str == "false"
19
+
20
+ m = str.match(/^\s*(\d+)\s*\*\s*(\d+)\s*/)
21
+ return m[1].to_i * m[2].to_i if m
22
+
23
+ str
24
+ end
25
+
26
+ def parse_param(input)
27
+ return nil unless input
28
+ output = ""
29
+
30
+ params = input.map do |param, extra|
31
+ default = case extra["default"]
32
+ when "空" then ""
33
+ when "-" then nil
34
+ when nil then nil
35
+ else get_default extra["default"]
36
+ end
37
+
38
+ if default.nil?
39
+ next param
40
+ end
41
+
42
+ {"#{param}": default}
43
+ end
44
+
45
+ params.each do |param|
46
+ output << if param.instance_of?(Hash)
47
+ if param.values[0].instance_of?(String)
48
+ "#{param.keys[0]}: '#{param.values[0]}'"
49
+ else
50
+ "#{param.keys[0]}: #{param.values[0]}"
51
+ end
52
+ else
53
+ "#{param}:nil"
54
+ end
55
+ output << ","
56
+ end
57
+ output.delete_suffix!(",")
58
+ output.to_s
59
+ end
60
+
61
+ # Defines method with underscored name to post to specific endpoint:
62
+ #
63
+ # define_method :send_private_msg
64
+ def define_helpers(list)
65
+ list.each do |method_name, method_info|
66
+ # puts "define #{method_name}"
67
+ params = parse_param(method_info["params"])
68
+ if method_name[0] == "."
69
+ class_eval %(
70
+ private def #{method_name[1..]} (params = { #{params} })
71
+ request("#{method_name}", params)
72
+ end
73
+ ), __FILE__, __LINE__ - 4
74
+ else
75
+ class_eval %(
76
+ def #{method_name} (params = { #{params} })
77
+ request("#{method_name}", params)
78
+ end
79
+ ), __FILE__, __LINE__ - 4
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ methods_list
86
+ define_helpers(@func_list)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Onebot
4
+ VERSION = "0.1.0"
5
+ end
data/onebot.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/onebot/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "onebot"
7
+ spec.version = Onebot::VERSION
8
+ spec.authors = ["Jiting"]
9
+ spec.email = ["jiting@jtcat.com"]
10
+
11
+ spec.summary = "Library for building QQ Bot with go-cqhttp version onebot protocol"
12
+ spec.homepage = "https://github.com/jitingcn/onebot-rb"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/jitingcn/onebot-rb"
18
+ spec.metadata["changelog_uri"] = "https://github.com/jitingcn/onebot-rb/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+ # spec.add_development_dependency "nokogiri"
32
+ spec.add_dependency "excon"
33
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onebot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jiting
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - jiting@jtcat.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/main.yml"
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/fetch-methods
44
+ - bin/setup
45
+ - lib/onebot.rb
46
+ - lib/onebot/client.rb
47
+ - lib/onebot/client/api.json
48
+ - lib/onebot/client/api_helper.rb
49
+ - lib/onebot/version.rb
50
+ - onebot.gemspec
51
+ homepage: https://github.com/jitingcn/onebot-rb
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/jitingcn/onebot-rb
56
+ source_code_uri: https://github.com/jitingcn/onebot-rb
57
+ changelog_uri: https://github.com/jitingcn/onebot-rb/CHANGELOG.md
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.3.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.1.4
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Library for building QQ Bot with go-cqhttp version onebot protocol
77
+ test_files: []