lita-vkontakte 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.rubocop.yml +9 -0
- data/.simplecov +10 -0
- data/.travis.yml +12 -0
- data/.yardopts +5 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +18 -0
- data/LICENSE +22 -0
- data/README.md +8 -0
- data/Rakefile +31 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/lib/lita-vkontakte.rb +7 -0
- data/lib/lita/adapters/vkontakte.rb +113 -0
- data/lita-vkontakte.gemspec +30 -0
- data/locales/en.yml +4 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c03ff4c1902ad82b997c83ac70689a7040c9b991
|
4
|
+
data.tar.gz: 8d68cda6cff50defab4e5c4a45bf4ab281ea7d26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 197854a326fdba15f7abe3c1ea8a8e39f2dc70c3c18f579eefefff75408f880cd177208673e9da6ee655a9d5865bb1a97af9c7f6b2762aa4857f020a12981146
|
7
|
+
data.tar.gz: be37cf8dccbfdcf08cb7f3eb2078ecf47ebdd45f7e94a0f2fc140c62a01ea1e86b3e07a34bc203671635e182e4d1e92e1c9dfc6d87eeb1279945e78c495d4dc7
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
/Gemfile.lock
|
31
|
+
/.ruby-version
|
32
|
+
/.ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.simplecov
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [v0.1.0](https://github.com/braiden-vasco/lita-vkontakte/tree/v0.1.0) (2015-06-17)
|
4
|
+
|
5
|
+
**Merged pull requests:**
|
6
|
+
|
7
|
+
- Add changelog [\#11](https://github.com/braiden-vasco/lita-vkontakte/pull/11) ([braiden-vasco](https://github.com/braiden-vasco))
|
8
|
+
|
9
|
+
- Basic implementation [\#10](https://github.com/braiden-vasco/lita-vkontakte/pull/10) ([braiden-vasco](https://github.com/braiden-vasco))
|
10
|
+
|
11
|
+
- Initialize Lita adapter [\#9](https://github.com/braiden-vasco/lita-vkontakte/pull/9) ([braiden-vasco](https://github.com/braiden-vasco))
|
12
|
+
|
13
|
+
- Use YARD [\#8](https://github.com/braiden-vasco/lita-vkontakte/pull/8) ([braiden-vasco](https://github.com/braiden-vasco))
|
14
|
+
|
15
|
+
- Use Pry as a console [\#7](https://github.com/braiden-vasco/lita-vkontakte/pull/7) ([braiden-vasco](https://github.com/braiden-vasco))
|
16
|
+
|
17
|
+
- Configure Coveralls [\#6](https://github.com/braiden-vasco/lita-vkontakte/pull/6) ([braiden-vasco](https://github.com/braiden-vasco))
|
18
|
+
|
19
|
+
- Configure Travis CI [\#5](https://github.com/braiden-vasco/lita-vkontakte/pull/5) ([braiden-vasco](https://github.com/braiden-vasco))
|
20
|
+
|
21
|
+
- Add README [\#4](https://github.com/braiden-vasco/lita-vkontakte/pull/4) ([braiden-vasco](https://github.com/braiden-vasco))
|
22
|
+
|
23
|
+
- Configure testing [\#3](https://github.com/braiden-vasco/lita-vkontakte/pull/3) ([braiden-vasco](https://github.com/braiden-vasco))
|
24
|
+
|
25
|
+
- Configure linting [\#2](https://github.com/braiden-vasco/lita-vkontakte/pull/2) ([braiden-vasco](https://github.com/braiden-vasco))
|
26
|
+
|
27
|
+
- Initialize gem [\#1](https://github.com/braiden-vasco/lita-vkontakte/pull/1) ([braiden-vasco](https://github.com/braiden-vasco))
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in lita-vkontakte.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'github_changelog_generator', '~> 1.6.1'
|
7
|
+
|
8
|
+
gem 'yard', '~> 0.8.7.6', require: false
|
9
|
+
gem 'redcarpet', require: false
|
10
|
+
|
11
|
+
gem 'pry', '~> 0.10.1', require: false
|
12
|
+
|
13
|
+
gem 'rubocop', '~> 0.31.0', require: false
|
14
|
+
|
15
|
+
gem 'rspec', '~> 3.3.0'
|
16
|
+
|
17
|
+
gem 'simplecov', '~> 0.10.0', require: false
|
18
|
+
gem 'coveralls', require: false
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Braiden Vasco
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Lita::Adapters::Vkontakte
|
2
|
+
=========================
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/lita-vkontakte.svg)](http://badge.fury.io/rb/lita-vkontakte)
|
5
|
+
[![Build Status](https://travis-ci.org/braiden-vasco/lita-vkontakte.svg)](https://travis-ci.org/braiden-vasco/lita-vkontakte)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/braiden-vasco/lita-vkontakte/badge.svg)](https://coveralls.io/r/braiden-vasco/lita-vkontakte)
|
7
|
+
|
8
|
+
VKontakte adapter for the Lita chat bot
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gemspec = Gem::Specification.load('lita-vkontakte.gemspec')
|
4
|
+
|
5
|
+
github_user, github_project =
|
6
|
+
gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]
|
7
|
+
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
|
10
|
+
task default: [:spec, :lint]
|
11
|
+
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
RSpec::Core::RakeTask.new
|
14
|
+
|
15
|
+
task lint: [:rubocop]
|
16
|
+
|
17
|
+
require 'rubocop/rake_task'
|
18
|
+
RuboCop::RakeTask.new
|
19
|
+
|
20
|
+
require 'yard'
|
21
|
+
YARD::Rake::YardocTask.new
|
22
|
+
|
23
|
+
desc 'Generate changelog'
|
24
|
+
task :changelog, [:token] do |_t, args|
|
25
|
+
cmd = 'github_changelog_generator'
|
26
|
+
cmd << " -u #{github_user}"
|
27
|
+
cmd << " -p #{github_project}"
|
28
|
+
cmd << " -t #{args[:token]}" if args[:token]
|
29
|
+
|
30
|
+
sh cmd
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'lita/vkontakte'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'lita'
|
2
|
+
require 'vkontakte_api'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
##
|
6
|
+
# Lita module.
|
7
|
+
#
|
8
|
+
module Lita
|
9
|
+
##
|
10
|
+
# Lita adapters module.
|
11
|
+
#
|
12
|
+
module Adapters
|
13
|
+
##
|
14
|
+
# VKontakte adapter for the Lita chat bot.
|
15
|
+
#
|
16
|
+
class Vkontakte < Adapter
|
17
|
+
API_VERSION = '5.34'
|
18
|
+
|
19
|
+
REDIRECT_URI = 'https:/oauth.vk.com/blank.html'
|
20
|
+
|
21
|
+
config :client_id, type: String, required: true
|
22
|
+
config :client_secret, type: String, required: true
|
23
|
+
config :access_token, type: String, required: true
|
24
|
+
|
25
|
+
def initialize(robot)
|
26
|
+
super
|
27
|
+
|
28
|
+
VkontakteApi.configure do |vk|
|
29
|
+
vk.app_id = config.client_id
|
30
|
+
vk.app_secret = config.client_secret
|
31
|
+
vk.redirect_uri = REDIRECT_URI
|
32
|
+
vk.api_version = API_VERSION
|
33
|
+
end
|
34
|
+
|
35
|
+
@vk = VkontakteApi::Client.new(config.access_token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
39
|
+
robot.trigger(:connected)
|
40
|
+
|
41
|
+
loop do
|
42
|
+
session = @vk.messages.get_long_poll_server
|
43
|
+
url = 'http://' + session.delete(:server)
|
44
|
+
params = session.merge(act: 'a_check', wait: 25, mode: 2)
|
45
|
+
params.ts = @ts if @ts
|
46
|
+
|
47
|
+
response = nil
|
48
|
+
|
49
|
+
get_response = lambda do
|
50
|
+
response = VkontakteApi::API.connection.get(url, params).body
|
51
|
+
end
|
52
|
+
|
53
|
+
while get_response.call
|
54
|
+
break if response.failed?
|
55
|
+
params.ts = @ts = response.ts
|
56
|
+
|
57
|
+
response.updates.each(&method(:update))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
ensure
|
62
|
+
robot.trigger(:disconnected)
|
63
|
+
end
|
64
|
+
|
65
|
+
def send_messages(target, messages)
|
66
|
+
messages.reject(&:empty?).each do |message|
|
67
|
+
send_message(target, message)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
HANDLERS = {
|
74
|
+
4 => :get_message,
|
75
|
+
}
|
76
|
+
|
77
|
+
def update(a)
|
78
|
+
code = a[0]
|
79
|
+
data = a[1..-1]
|
80
|
+
|
81
|
+
method(HANDLERS[code]).call(*data) if HANDLERS[code]
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_message(_msg_id, flags, # rubocop:disable Metrics/ParameterLists
|
85
|
+
from_id, _timestamp, subject, text, _attachments)
|
86
|
+
is_private = subject.start_with?(' ')
|
87
|
+
is_own = flags & 2 != 0
|
88
|
+
|
89
|
+
user = User.new(from_id)
|
90
|
+
source = Source.new(user: user, room: subject)
|
91
|
+
message = Message.new(robot, text, source)
|
92
|
+
|
93
|
+
return if is_own
|
94
|
+
|
95
|
+
message.command! if is_private
|
96
|
+
robot.receive(message)
|
97
|
+
end
|
98
|
+
|
99
|
+
def send_message(target, message) # rubocop:disable Metrics/AbcSize
|
100
|
+
is_private = target.room.start_with?(' ')
|
101
|
+
|
102
|
+
@vk.messages.send({
|
103
|
+
message: message,
|
104
|
+
guid: SecureRandom.random_number(2**31),
|
105
|
+
user_id: (target.user.id.to_i if is_private),
|
106
|
+
chat_id: (target.user.id.to_i - 2_000_000_000 unless is_private),
|
107
|
+
}.reject { |_, v| v.nil? })
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Lita.register_adapter(:vkontakte, Vkontakte)
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'lita-vkontakte'
|
5
|
+
spec.version = '0.1.0'
|
6
|
+
spec.authors = ['Braiden Vasco']
|
7
|
+
spec.email = ['braiden-vasco@mailtor.net']
|
8
|
+
|
9
|
+
spec.summary = 'VKontakte adapter for the Lita chat bot'
|
10
|
+
spec.description = 'VKontakte adapter for the Lita chat bot.'
|
11
|
+
spec.homepage = 'https://github.com/braiden-vasco/lita-vkontakte'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.respond_to?(:metadata) and
|
15
|
+
spec.metadata['lita_plugin_type'] = 'adapter'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'lita', '>= 4.4'
|
29
|
+
spec.add_runtime_dependency 'vkontakte_api', '1.4.3'
|
30
|
+
end
|
data/locales/en.yml
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-vkontakte
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Braiden Vasco
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: lita
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vkontakte_api
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.4.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.4.3
|
69
|
+
description: VKontakte adapter for the Lita chat bot.
|
70
|
+
email:
|
71
|
+
- braiden-vasco@mailtor.net
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .rubocop.yml
|
79
|
+
- .simplecov
|
80
|
+
- .travis.yml
|
81
|
+
- .yardopts
|
82
|
+
- CHANGELOG.md
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/lita-vkontakte.rb
|
90
|
+
- lib/lita/adapters/vkontakte.rb
|
91
|
+
- lita-vkontakte.gemspec
|
92
|
+
- locales/en.yml
|
93
|
+
homepage: https://github.com/braiden-vasco/lita-vkontakte
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
lita_plugin_type: adapter
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: VKontakte adapter for the Lita chat bot
|
118
|
+
test_files: []
|
119
|
+
has_rdoc:
|