qqbot 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/.gitignore +15 -15
- data/Gemfile +4 -4
- data/README.md +84 -84
- data/lib/qqbot.rb +46 -46
- data/lib/qqbot/api.rb +314 -314
- data/lib/qqbot/bot.rb +504 -504
- data/lib/qqbot/client.rb +60 -60
- data/lib/qqbot/cookie.rb +28 -28
- data/lib/qqbot/error.rb +4 -4
- data/lib/qqbot/model.rb +57 -57
- data/lib/qqbot/version.rb +3 -3
- data/qqbot.gemspec +33 -33
- metadata +3 -3
data/lib/qqbot/client.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'openssl'
|
3
|
-
|
4
|
-
module QQBot
|
5
|
-
class Client
|
6
|
-
|
7
|
-
@@user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
|
8
|
-
|
9
|
-
def self.origin(uri)
|
10
|
-
"#{uri.scheme}://#{uri.host}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
@cookie = QQBot::Cookie.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def get(uri, referer = '')
|
18
|
-
QQBot::LOGGER.debug { "get #{uri.to_s}" }
|
19
|
-
|
20
|
-
Net::HTTP.start(uri.host, uri.port,
|
21
|
-
use_ssl: uri.scheme == 'https',
|
22
|
-
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
23
|
-
req = Net::HTTP::Get.new(uri)
|
24
|
-
req.initialize_http_header(
|
25
|
-
'User-Agent' => @@user_agent,
|
26
|
-
'Cookie' => @cookie.to_s,
|
27
|
-
'Referer' => referer
|
28
|
-
)
|
29
|
-
res = http.request(req)
|
30
|
-
@cookie.put(res.get_fields('set-cookie'))
|
31
|
-
QQBot::LOGGER.debug { "code: #{res.code}, body: #{res.body}" }
|
32
|
-
return res.code, res.body
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def post(uri, referer = '', form_data = {})
|
37
|
-
QQBot::LOGGER.debug { "post uri: #{uri.to_s} data: #{form_data.to_s}" }
|
38
|
-
Net::HTTP.start(uri.host, uri.port,
|
39
|
-
use_ssl: uri.scheme == 'https',
|
40
|
-
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
41
|
-
req = Net::HTTP::Post.new(uri)
|
42
|
-
req.set_form_data(form_data)
|
43
|
-
req.initialize_http_header(
|
44
|
-
'User-Agent' => @@user_agent,
|
45
|
-
'Cookie' => @cookie.to_s,
|
46
|
-
'Referer' => referer,
|
47
|
-
'Origin' => self.class.origin(uri)
|
48
|
-
)
|
49
|
-
res = http.request(req)
|
50
|
-
@cookie.put(res.get_fields('set-cookie'))
|
51
|
-
QQBot::LOGGER.debug { "response code: #{res.code}, body: #{res.body}" }
|
52
|
-
return res.code, res.body
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def get_cookie(key)
|
57
|
-
@cookie[key]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module QQBot
|
5
|
+
class Client
|
6
|
+
|
7
|
+
@@user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
|
8
|
+
|
9
|
+
def self.origin(uri)
|
10
|
+
"#{uri.scheme}://#{uri.host}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@cookie = QQBot::Cookie.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(uri, referer = '')
|
18
|
+
QQBot::LOGGER.debug { "get #{uri.to_s}" }
|
19
|
+
|
20
|
+
Net::HTTP.start(uri.host, uri.port,
|
21
|
+
use_ssl: uri.scheme == 'https',
|
22
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
23
|
+
req = Net::HTTP::Get.new(uri)
|
24
|
+
req.initialize_http_header(
|
25
|
+
'User-Agent' => @@user_agent,
|
26
|
+
'Cookie' => @cookie.to_s,
|
27
|
+
'Referer' => referer
|
28
|
+
)
|
29
|
+
res = http.request(req)
|
30
|
+
@cookie.put(res.get_fields('set-cookie'))
|
31
|
+
QQBot::LOGGER.debug { "code: #{res.code}, body: #{res.body}" }
|
32
|
+
return res.code, res.body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def post(uri, referer = '', form_data = {})
|
37
|
+
QQBot::LOGGER.debug { "post uri: #{uri.to_s} data: #{form_data.to_s}" }
|
38
|
+
Net::HTTP.start(uri.host, uri.port,
|
39
|
+
use_ssl: uri.scheme == 'https',
|
40
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
41
|
+
req = Net::HTTP::Post.new(uri)
|
42
|
+
req.set_form_data(form_data)
|
43
|
+
req.initialize_http_header(
|
44
|
+
'User-Agent' => @@user_agent,
|
45
|
+
'Cookie' => @cookie.to_s,
|
46
|
+
'Referer' => referer,
|
47
|
+
'Origin' => self.class.origin(uri)
|
48
|
+
)
|
49
|
+
res = http.request(req)
|
50
|
+
@cookie.put(res.get_fields('set-cookie'))
|
51
|
+
QQBot::LOGGER.debug { "response code: #{res.code}, body: #{res.body}" }
|
52
|
+
return res.code, res.body
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_cookie(key)
|
57
|
+
@cookie[key]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/qqbot/cookie.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
module QQBot
|
2
|
-
class Cookie
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@cookies = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def put set_cookie_array
|
9
|
-
return if set_cookie_array.nil?
|
10
|
-
|
11
|
-
set_cookie_array.each do |set_cookie|
|
12
|
-
set_cookie.split('; ').each do |cookie|
|
13
|
-
k, v = cookie.split('=')
|
14
|
-
@cookies[k] = v unless v.nil?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def [] key
|
20
|
-
@cookies[key] || ''
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
@cookies.map{ |k, v| "#{k}=#{v}" }.join('; ')
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module QQBot
|
2
|
+
class Cookie
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@cookies = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def put set_cookie_array
|
9
|
+
return if set_cookie_array.nil?
|
10
|
+
|
11
|
+
set_cookie_array.each do |set_cookie|
|
12
|
+
set_cookie.split('; ').each do |cookie|
|
13
|
+
k, v = cookie.split('=')
|
14
|
+
@cookies[k] = v unless v.nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def [] key
|
20
|
+
@cookies[key] || ''
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
@cookies.map{ |k, v| "#{k}=#{v}" }.join('; ')
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/qqbot/error.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module QQBot
|
2
|
-
class Error < StandardError; end
|
3
|
-
class Error::LoginFailed < Error; end
|
4
|
-
end
|
1
|
+
module QQBot
|
2
|
+
class Error < StandardError; end
|
3
|
+
class Error::LoginFailed < Error; end
|
4
|
+
end
|
data/lib/qqbot/model.rb
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
module QQBot
|
2
|
-
class Group
|
3
|
-
attr_accessor :name, :code, :id, :markname
|
4
|
-
end
|
5
|
-
|
6
|
-
class Friend
|
7
|
-
attr_accessor :nickname, :category_id, :id, :is_vip, :vip_level, :markname
|
8
|
-
end
|
9
|
-
|
10
|
-
class Category
|
11
|
-
attr_accessor :name, :sort, :id, :friends
|
12
|
-
end
|
13
|
-
|
14
|
-
class Discuss
|
15
|
-
attr_accessor :name, :id
|
16
|
-
end
|
17
|
-
|
18
|
-
class Message
|
19
|
-
attr_accessor :type, :from_id, :send_id, :time, :content, :font
|
20
|
-
end
|
21
|
-
|
22
|
-
class Font
|
23
|
-
attr_accessor :color, :name, :size, :style
|
24
|
-
end
|
25
|
-
|
26
|
-
class UserInfo
|
27
|
-
attr_accessor :phone, :occupation, :college, :id, :blood, :slogan, :homepage, :vip_info, :city, :country, :province, :personal, :shengxiao, :nickname, :email, :account, :gender, :mobile, :birthday
|
28
|
-
end
|
29
|
-
|
30
|
-
class Birthday
|
31
|
-
attr_accessor :year, :month, :day
|
32
|
-
end
|
33
|
-
|
34
|
-
class Recent
|
35
|
-
attr_accessor :id, :type
|
36
|
-
end
|
37
|
-
|
38
|
-
class Online
|
39
|
-
attr_accessor :id, :client_type
|
40
|
-
end
|
41
|
-
|
42
|
-
class GroupMember
|
43
|
-
attr_accessor :id, :nickname, :gender, :country, :city, :markname, :is_vip, :vip_level, :client_type, :status
|
44
|
-
end
|
45
|
-
|
46
|
-
class GroupInfo
|
47
|
-
attr_accessor :id, :create_time, :memo, :name, :owner_id, :markname, :members
|
48
|
-
end
|
49
|
-
|
50
|
-
class DiscussInfo
|
51
|
-
attr_accessor :id, :name, :members
|
52
|
-
end
|
53
|
-
|
54
|
-
class DiscussMember
|
55
|
-
attr_accessor :id, :nickname, :client_type, :status
|
56
|
-
end
|
57
|
-
end
|
1
|
+
module QQBot
|
2
|
+
class Group
|
3
|
+
attr_accessor :name, :code, :id, :markname
|
4
|
+
end
|
5
|
+
|
6
|
+
class Friend
|
7
|
+
attr_accessor :nickname, :category_id, :id, :is_vip, :vip_level, :markname
|
8
|
+
end
|
9
|
+
|
10
|
+
class Category
|
11
|
+
attr_accessor :name, :sort, :id, :friends
|
12
|
+
end
|
13
|
+
|
14
|
+
class Discuss
|
15
|
+
attr_accessor :name, :id
|
16
|
+
end
|
17
|
+
|
18
|
+
class Message
|
19
|
+
attr_accessor :type, :from_id, :send_id, :time, :content, :font
|
20
|
+
end
|
21
|
+
|
22
|
+
class Font
|
23
|
+
attr_accessor :color, :name, :size, :style
|
24
|
+
end
|
25
|
+
|
26
|
+
class UserInfo
|
27
|
+
attr_accessor :phone, :occupation, :college, :id, :blood, :slogan, :homepage, :vip_info, :city, :country, :province, :personal, :shengxiao, :nickname, :email, :account, :gender, :mobile, :birthday
|
28
|
+
end
|
29
|
+
|
30
|
+
class Birthday
|
31
|
+
attr_accessor :year, :month, :day
|
32
|
+
end
|
33
|
+
|
34
|
+
class Recent
|
35
|
+
attr_accessor :id, :type
|
36
|
+
end
|
37
|
+
|
38
|
+
class Online
|
39
|
+
attr_accessor :id, :client_type
|
40
|
+
end
|
41
|
+
|
42
|
+
class GroupMember
|
43
|
+
attr_accessor :id, :nickname, :gender, :country, :city, :markname, :is_vip, :vip_level, :client_type, :status
|
44
|
+
end
|
45
|
+
|
46
|
+
class GroupInfo
|
47
|
+
attr_accessor :id, :create_time, :memo, :name, :owner_id, :markname, :members
|
48
|
+
end
|
49
|
+
|
50
|
+
class DiscussInfo
|
51
|
+
attr_accessor :id, :name, :members
|
52
|
+
end
|
53
|
+
|
54
|
+
class DiscussMember
|
55
|
+
attr_accessor :id, :nickname, :client_type, :status
|
56
|
+
end
|
57
|
+
end
|
data/lib/qqbot/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module QQBot
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
1
|
+
module QQBot
|
2
|
+
VERSION = "0.1.6"
|
3
|
+
end
|
data/qqbot.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'qqbot/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "qqbot"
|
8
|
-
spec.version = QQBot::VERSION
|
9
|
-
spec.authors = ["ScienJus"]
|
10
|
-
spec.email = ["i@scienjus.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{a qq robot based on smart qq api.}
|
13
|
-
spec.description = %q{a qq robot based on smart qq api.}
|
14
|
-
spec.homepage = "https://github.com/ScienJus/qqbot"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
if spec.respond_to?(:metadata)
|
20
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qqbot/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qqbot"
|
8
|
+
spec.version = QQBot::VERSION
|
9
|
+
spec.authors = ["ScienJus"]
|
10
|
+
spec.email = ["i@scienjus.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{a qq robot based on smart qq api.}
|
13
|
+
spec.description = %q{a qq robot based on smart qq api.}
|
14
|
+
spec.homepage = "https://github.com/ScienJus/qqbot"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qqbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ScienJus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.4.
|
102
|
+
rubygems_version: 2.4.8
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: a qq robot based on smart qq api.
|