Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.1.0 #13

Merged
66 commits merged into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
496b0b2
Edit .gitignore
Jun 16, 2015
ba21c7f
Edit .gitignore
Jun 16, 2015
4a1abd9
Initialize gem
Jun 16, 2015
8068845
Remove file "/LICENSE.txt"
Jun 16, 2015
b93b893
Remove unnecessary files
Jun 16, 2015
3d21e61
Remove gem server metadata
Jun 16, 2015
c671f01
Add gem summary
Jun 16, 2015
c7b1a98
Add gem description
Jun 16, 2015
5ce3b20
Add gem homepage
Jun 16, 2015
3906f2d
Fix gem version
Jun 16, 2015
d4345b3
Merge pull request #1 from braiden-vasco/initialize_gem
Jun 16, 2015
c4a6764
Add default Rake task
Jun 16, 2015
be88496
Add Rake task "lint"
Jun 16, 2015
66fdcbe
Use RuboCop
Jun 16, 2015
98fd95d
Add Rake taskfor RuboCop
Jun 16, 2015
431b677
Run RuboCop auto-correction
Jun 16, 2015
467f870
Correct RuboCop offenses manually
Jun 16, 2015
feac6f6
Merge pull request #2 from braiden-vasco/configure_linting
Jun 17, 2015
e65d06b
use RSpec
Jun 17, 2015
4eff44a
Add Rake task for RSpec
Jun 17, 2015
e269917
Initialize RSpec
Jun 17, 2015
25d4b72
Use SimpleCov
Jun 17, 2015
d257647
Configure SimpleCov
Jun 17, 2015
c2a2b59
Configure specs to use SimpleCov
Jun 17, 2015
d4f0abd
Merge pull request #3 from braiden-vasco/configure_testing
Jun 17, 2015
5a1850c
Add file "/README.md"
Jun 17, 2015
dc7b34b
Merge pull request #4 from braiden-vasco/add_readme
Jun 17, 2015
15911f6
Configure RuboCop
Jun 17, 2015
c017787
Configure Travis CI
Jun 17, 2015
4c0f807
Fix Bundler version (~> 1.7)
Jun 17, 2015
2d4a187
Merge pull request #5 from braiden-vasco/configure_travis_ci
Jun 17, 2015
d5ae597
Use Coveralls
Jun 17, 2015
68d5959
Configure SimpleCov to use Coveralls
Jun 17, 2015
52fffdd
Merge branch 'master' into configure_coveralls
Jun 17, 2015
98f61e1
Merge pull request #6 from braiden-vasco/configure_coveralls
Jun 17, 2015
9e69196
Use Pry
Jun 17, 2015
8432b1f
Configure console to use Pry
Jun 17, 2015
ec8e905
Merge pull request #7 from braiden-vasco/use_pry_as_a_console
Jun 17, 2015
0f84dc5
Use YARD
Jun 17, 2015
bad0944
Configure YARD
Jun 17, 2015
4decc02
Add Rake task for YARD
Jun 17, 2015
fe0ecbd
Add documentation
Jun 17, 2015
2a03b50
Merge pull request #8 from braiden-vasco/use_yard
Jun 17, 2015
f5f66fe
Initialize Lita adapter
Jun 16, 2015
0dbe071
Merge branch 'master' into initialize_lita_adapter
Jun 17, 2015
0c21e27
Merge branch 'initialize_lita_adapter'
Jun 17, 2015
1a0c035
Remove unnecessary code from specs
Jun 17, 2015
8fc7b5b
Fix error
Jun 17, 2015
78ccfbd
Remove constant Lita::Adapters::Vkontakte::VERSION
Jun 17, 2015
a76b8fb
Add documentation
Jun 17, 2015
774d87e
Implement adapter configuration
Jun 17, 2015
568c809
Add runtime dependency "vkontakte_api" (1.4.3)
Jun 17, 2015
fb33ae3
Implement Lita::Adapters::Vkontakte#initialize
Jun 17, 2015
b9a258a
Implement main loop in Lita::Adapters::Vkontakte#run
Jun 17, 2015
fba1358
Trigger events "connected" and "disconnected"
Jun 17, 2015
9125ad7
Implement message receiving
Jun 17, 2015
c9b1181
Configure RuboCop
Jun 17, 2015
fd55221
Implement Lita::Adapters::Vkontakte#send_messages
Jun 17, 2015
8bf4239
Don't execute own messages
Jun 17, 2015
01d67cb
Merge pull request #10 from braiden-vasco/basic_implementation
Jun 17, 2015
367a81e
Use GitHub Changelog Generator
Jun 17, 2015
8383034
Add Rake task for GitHub Changelog Generator
Jun 17, 2015
48c6393
Merge pull request #11 from braiden-vasco/add_changelog
Jun 17, 2015
aa7bd2d
Exclude version pull requests from changelog
Jun 17, 2015
f074885
Add changelog
Jun 17, 2015
52f21a5
Increment version (0.1.0)
Jun 17, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ build/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
/Gemfile.lock
/.ruby-version
/.ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AllCops:
Exclude:
- vendor/**/*

Style/AndOr:
Enabled: false

Style/TrailingComma:
Enabled: false
10 changes: 10 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter,
]

SimpleCov.start do
add_filter '/spec/'
end
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: ruby

rvm:
- 2.0.0

script: bundle exec rake

before_install:
- gem update --system

services:
- redis-server
5 changes: 5 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--protected
--private
--markup markdown
-
LICENSE
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Change Log

## [v0.1.0](https://github.com/braiden-vasco/lita-vkontakte/tree/v0.1.0) (2015-06-17)

**Merged pull requests:**

- Add changelog [\#11](https://github.com/braiden-vasco/lita-vkontakte/pull/11) ([braiden-vasco](https://github.com/braiden-vasco))

- Basic implementation [\#10](https://github.com/braiden-vasco/lita-vkontakte/pull/10) ([braiden-vasco](https://github.com/braiden-vasco))

- Initialize Lita adapter [\#9](https://github.com/braiden-vasco/lita-vkontakte/pull/9) ([braiden-vasco](https://github.com/braiden-vasco))

- Use YARD [\#8](https://github.com/braiden-vasco/lita-vkontakte/pull/8) ([braiden-vasco](https://github.com/braiden-vasco))

- Use Pry as a console [\#7](https://github.com/braiden-vasco/lita-vkontakte/pull/7) ([braiden-vasco](https://github.com/braiden-vasco))

- Configure Coveralls [\#6](https://github.com/braiden-vasco/lita-vkontakte/pull/6) ([braiden-vasco](https://github.com/braiden-vasco))

- Configure Travis CI [\#5](https://github.com/braiden-vasco/lita-vkontakte/pull/5) ([braiden-vasco](https://github.com/braiden-vasco))

- Add README [\#4](https://github.com/braiden-vasco/lita-vkontakte/pull/4) ([braiden-vasco](https://github.com/braiden-vasco))

- Configure testing [\#3](https://github.com/braiden-vasco/lita-vkontakte/pull/3) ([braiden-vasco](https://github.com/braiden-vasco))

- Configure linting [\#2](https://github.com/braiden-vasco/lita-vkontakte/pull/2) ([braiden-vasco](https://github.com/braiden-vasco))

- Initialize gem [\#1](https://github.com/braiden-vasco/lita-vkontakte/pull/1) ([braiden-vasco](https://github.com/braiden-vasco))



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
18 changes: 18 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in lita-vkontakte.gemspec
gemspec

gem 'github_changelog_generator', '~> 1.6.1'

gem 'yard', '~> 0.8.7.6', require: false
gem 'redcarpet', require: false

gem 'pry', '~> 0.10.1', require: false

gem 'rubocop', '~> 0.31.0', require: false

gem 'rspec', '~> 3.3.0'

gem 'simplecov', '~> 0.10.0', require: false
gem 'coveralls', require: false
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Lita::Adapters::Vkontakte
=========================

[![Gem Version](https://badge.fury.io/rb/lita-vkontakte.svg)](http://badge.fury.io/rb/lita-vkontakte)
[![Build Status](https://travis-ci.org/braiden-vasco/lita-vkontakte.svg)](https://travis-ci.org/braiden-vasco/lita-vkontakte)
[![Coverage Status](https://coveralls.io/repos/braiden-vasco/lita-vkontakte/badge.svg)](https://coveralls.io/r/braiden-vasco/lita-vkontakte)

VKontakte adapter for the Lita chat bot
32 changes: 32 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rubygems'

gemspec = Gem::Specification.load('lita-vkontakte.gemspec')

github_user, github_project =
gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]

require 'bundler/gem_tasks'

task default: [:spec, :lint]

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

task lint: [:rubocop]

require 'rubocop/rake_task'
RuboCop::RakeTask.new

require 'yard'
YARD::Rake::YardocTask.new

desc 'Generate changelog'
task :changelog, [:token] do |_t, args|
cmd = 'github_changelog_generator'
cmd << " -u #{github_user}"
cmd << " -p #{github_project}"
cmd << " -t #{args[:token]}" if args[:token]
cmd << ' --exclude-tags version'

sh cmd
end
10 changes: 10 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'lita/vkontakte'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require 'pry'
Pry.start
7 changes: 7 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

bundle install

# Do any other automated setup that you need to do here
7 changes: 7 additions & 0 deletions lib/lita-vkontakte.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# rubocop:disable Style/FileName

require 'lita'

Lita.load_locales(Dir[File.expand_path('../../locales/*.yml', __FILE__)])

require 'lita/adapters/vkontakte'
113 changes: 113 additions & 0 deletions lib/lita/adapters/vkontakte.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
require 'lita'
require 'vkontakte_api'
require 'securerandom'

##
# Lita module.
#
module Lita
##
# Lita adapters module.
#
module Adapters
##
# VKontakte adapter for the Lita chat bot.
#
class Vkontakte < Adapter
API_VERSION = '5.34'

REDIRECT_URI = 'https:/oauth.vk.com/blank.html'

config :client_id, type: String, required: true
config :client_secret, type: String, required: true
config :access_token, type: String, required: true

def initialize(robot)
super

VkontakteApi.configure do |vk|
vk.app_id = config.client_id
vk.app_secret = config.client_secret
vk.redirect_uri = REDIRECT_URI
vk.api_version = API_VERSION
end

@vk = VkontakteApi::Client.new(config.access_token)
end

def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
robot.trigger(:connected)

loop do
session = @vk.messages.get_long_poll_server
url = 'http://' + session.delete(:server)
params = session.merge(act: 'a_check', wait: 25, mode: 2)
params.ts = @ts if @ts

response = nil

get_response = lambda do
response = VkontakteApi::API.connection.get(url, params).body
end

while get_response.call
break if response.failed?
params.ts = @ts = response.ts

response.updates.each(&method(:update))
end
end

ensure
robot.trigger(:disconnected)
end

def send_messages(target, messages)
messages.reject(&:empty?).each do |message|
send_message(target, message)
end
end

protected

HANDLERS = {
4 => :get_message,
}

def update(a)
code = a[0]
data = a[1..-1]

method(HANDLERS[code]).call(*data) if HANDLERS[code]
end

def get_message(_msg_id, flags, # rubocop:disable Metrics/ParameterLists
from_id, _timestamp, subject, text, _attachments)
is_private = subject.start_with?(' ')
is_own = flags & 2 != 0

user = User.new(from_id)
source = Source.new(user: user, room: subject)
message = Message.new(robot, text, source)

return if is_own

message.command! if is_private
robot.receive(message)
end

def send_message(target, message) # rubocop:disable Metrics/AbcSize
is_private = target.room.start_with?(' ')

@vk.messages.send({
message: message,
guid: SecureRandom.random_number(2**31),
user_id: (target.user.id.to_i if is_private),
chat_id: (target.user.id.to_i - 2_000_000_000 unless is_private),
}.reject { |_, v| v.nil? })
end
end

Lita.register_adapter(:vkontakte, Vkontakte)
end
end
30 changes: 30 additions & 0 deletions lita-vkontakte.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# coding: utf-8

Gem::Specification.new do |spec|
spec.name = 'lita-vkontakte'
spec.version = '0.1.0'
spec.authors = ['Braiden Vasco']
spec.email = ['braiden-vasco@mailtor.net']

spec.summary = 'VKontakte adapter for the Lita chat bot'
spec.description = 'VKontakte adapter for the Lita chat bot.'
spec.homepage = 'https://github.com/braiden-vasco/lita-vkontakte'
spec.license = 'MIT'

spec.respond_to?(:metadata) and
spec.metadata['lita_plugin_type'] = 'adapter'

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end

spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'

spec.add_runtime_dependency 'lita', '>= 4.4'
spec.add_runtime_dependency 'vkontakte_api', '1.4.3'
end
4 changes: 4 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
lita:
adapters:
vkontakte:
2 changes: 2 additions & 0 deletions spec/lita/adapters/vkontakte_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
describe Lita::Adapters::Vkontakte, lita: true do
end