lita-substitution 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.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/.simplecov +8 -0
- data/.travis.yml +21 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +8 -0
- data/Rakefile +29 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/lita-substitution.rb +15 -0
- data/lib/lita/extensions/substitution.rb +24 -0
- data/lib/lita/handlers/substitution.rb +109 -0
- data/lita-substitution.gemspec +36 -0
- data/locales/en.yml +4 -0
- data/templates/.gitkeep +0 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b829589eaf7fa00723960191133db5819b812ea8
|
4
|
+
data.tar.gz: e190a09e0256fe230ffd6822938050f027508240
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1afe3cd369dd80b4732a6a64c74b7549744b2be35b9575add12c0b73bfab16468e670acc8161c7d157ae94a256d94347701a8210cd26af9f7f701d895baf4e3
|
7
|
+
data.tar.gz: cf4e9406b6f2b806aaecfdc54a24caa6742b411a44178e445d6a8883d6e9a08da55b22f4510da2b4eaed2138adc09e032ada1eb901ff4ac42bb4258bc6accac8
|
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
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- jruby-9.0.0.0
|
8
|
+
- rbx-2
|
9
|
+
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: jruby-9.0.0.0
|
13
|
+
- rvm: rbx-2
|
14
|
+
|
15
|
+
script: bundle exec rake
|
16
|
+
|
17
|
+
before_install:
|
18
|
+
- gem update --system
|
19
|
+
|
20
|
+
services:
|
21
|
+
- redis-server
|
data/Gemfile
ADDED
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::Handlers::Substitution
|
2
|
+
============================
|
3
|
+
|
4
|
+
[](http://badge.fury.io/rb/lita-substitution)
|
5
|
+
[](https://travis-ci.org/braiden-vasco/lita-substitution)
|
6
|
+
[](https://coveralls.io/r/braiden-vasco/lita-substitution)
|
7
|
+
|
8
|
+
Shell-like command substitution for the Lita chat bot.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gemspec = Gem::Specification.load('lita-substitution.gemspec')
|
4
|
+
|
5
|
+
github_user, github_project =
|
6
|
+
gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]
|
7
|
+
|
8
|
+
require 'bundler/gem_tasks'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
|
11
|
+
task default: [:spec, :lint]
|
12
|
+
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new
|
15
|
+
|
16
|
+
task lint: [:rubocop]
|
17
|
+
|
18
|
+
require 'rubocop/rake_task'
|
19
|
+
RuboCop::RakeTask.new
|
20
|
+
|
21
|
+
desc 'Generate changelog'
|
22
|
+
task :changelog, [:token] do |_t, args|
|
23
|
+
cmd = 'github_changelog_generator'
|
24
|
+
cmd << " -u #{github_user}"
|
25
|
+
cmd << " -p #{github_project}"
|
26
|
+
cmd << " -t #{args[:token]}" if args[:token]
|
27
|
+
|
28
|
+
sh cmd
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'lita/substitution'
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# rubocop:disable Style/FileName
|
2
|
+
|
3
|
+
require 'lita'
|
4
|
+
|
5
|
+
Lita.load_locales Dir[File.expand_path(
|
6
|
+
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
7
|
+
)]
|
8
|
+
|
9
|
+
require 'lita/handlers/substitution'
|
10
|
+
require 'lita/extensions/substitution'
|
11
|
+
|
12
|
+
Lita::Handlers::Substitution.template_root File.expand_path(
|
13
|
+
File.join('..', '..', 'templates'),
|
14
|
+
__FILE__
|
15
|
+
)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
##
|
2
|
+
# Lita module.
|
3
|
+
#
|
4
|
+
module Lita
|
5
|
+
##
|
6
|
+
# Lita extensions module.
|
7
|
+
#
|
8
|
+
module Extensions
|
9
|
+
##
|
10
|
+
# Shell-like command substitution for the Lita chat bot.
|
11
|
+
#
|
12
|
+
class Substitution
|
13
|
+
def self.call(payload)
|
14
|
+
message = payload[:message]
|
15
|
+
route = payload[:route]
|
16
|
+
|
17
|
+
!(message.body =~ Lita::Handlers::Substitution::REGEXP) ||
|
18
|
+
route.extensions[:substitution]
|
19
|
+
end
|
20
|
+
|
21
|
+
Lita.register_hook(:validate_route, self)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
##
|
2
|
+
# Lita module.
|
3
|
+
#
|
4
|
+
module Lita
|
5
|
+
##
|
6
|
+
# Lita handlers module.
|
7
|
+
#
|
8
|
+
module Handlers
|
9
|
+
##
|
10
|
+
# Shell-like command substitution for the Lita chat bot.
|
11
|
+
#
|
12
|
+
class Substitution < Handler
|
13
|
+
# TODO
|
14
|
+
# REGEXP = /(^|[^\$])\$\(/
|
15
|
+
REGEXP = /\$\(/
|
16
|
+
|
17
|
+
route(REGEXP, command: true, substitution: true) do |response|
|
18
|
+
message = response.message
|
19
|
+
source = message.source
|
20
|
+
|
21
|
+
command, substitutions = parse(message.body)
|
22
|
+
shift = 0
|
23
|
+
|
24
|
+
substitutions.each do |position, subcommand|
|
25
|
+
channel = Channel.new(robot, subcommand, source)
|
26
|
+
channel.command!
|
27
|
+
|
28
|
+
result = ''
|
29
|
+
delta = 0
|
30
|
+
channel.on_reply do |*strings|
|
31
|
+
s = strings.flatten.join("\n")
|
32
|
+
delta += s.length
|
33
|
+
result << s
|
34
|
+
end
|
35
|
+
|
36
|
+
robot.receive(channel)
|
37
|
+
|
38
|
+
command.insert(shift + position, result)
|
39
|
+
shift += delta
|
40
|
+
end
|
41
|
+
|
42
|
+
channel = Channel.new(robot, command, source)
|
43
|
+
channel.command!
|
44
|
+
|
45
|
+
channel.on_reply do |*strings|
|
46
|
+
response.reply(strings.flatten.join("\n"))
|
47
|
+
end
|
48
|
+
|
49
|
+
robot.receive(channel)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
##
|
55
|
+
# Message which allows subscription to the answers
|
56
|
+
#
|
57
|
+
class Channel < Message
|
58
|
+
def reply(*strings)
|
59
|
+
@on_reply.call(*strings) if @on_reply
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_reply(&block)
|
63
|
+
@on_reply = block
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# rubocop:disable AbcSize, CyclomaticComplexity
|
68
|
+
# rubocop:disable MethodLength, PerceivedComplexity
|
69
|
+
def parse(s)
|
70
|
+
command = ''
|
71
|
+
substs = {}
|
72
|
+
last = nil
|
73
|
+
i = 0
|
74
|
+
deep = 0
|
75
|
+
|
76
|
+
loop do
|
77
|
+
case s[i]
|
78
|
+
when nil then break
|
79
|
+
|
80
|
+
when '$'
|
81
|
+
if s[i + 1] == '('
|
82
|
+
last = substs[command.length] = '' if deep == 0
|
83
|
+
i += 1
|
84
|
+
deep += 1
|
85
|
+
else
|
86
|
+
(deep > 0 ? last : command) << '$'
|
87
|
+
end
|
88
|
+
|
89
|
+
when ')'
|
90
|
+
if deep > 0
|
91
|
+
deep -= 1
|
92
|
+
else
|
93
|
+
command << ')'
|
94
|
+
end
|
95
|
+
|
96
|
+
else
|
97
|
+
(deep > 0 ? last : command) << s[i]
|
98
|
+
end
|
99
|
+
|
100
|
+
i += 1
|
101
|
+
end
|
102
|
+
|
103
|
+
[command, substs]
|
104
|
+
end
|
105
|
+
|
106
|
+
Lita.register_handler(self)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'lita-substitution'
|
5
|
+
spec.version = '0.1.0'
|
6
|
+
spec.authors = ['Braiden Vasco']
|
7
|
+
spec.email = ['braiden-vasco@users.noreply.github.com']
|
8
|
+
|
9
|
+
spec.summary = 'Shell-like command substitution for the Lita chat bot'
|
10
|
+
spec.description = 'Shell-like command substitution for the Lita chat bot.'
|
11
|
+
spec.homepage = 'https://github.com/braiden-vasco/lita-substitution'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
if spec.respond_to?(:metadata)
|
15
|
+
spec.metadata['lita_plugin_type'] = 'handler'
|
16
|
+
else
|
17
|
+
fail 'RubyGems 2.0 or newer is required.'
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 0.31'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
33
|
+
spec.add_development_dependency 'github_changelog_generator', '~> 1.6'
|
34
|
+
|
35
|
+
spec.add_runtime_dependency 'lita', '~> 4.6'
|
36
|
+
end
|
data/locales/en.yml
ADDED
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-substitution
|
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-10-25 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: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.31'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.31'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: github_changelog_generator
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: lita
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.6'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.6'
|
111
|
+
description: Shell-like command substitution for the Lita chat bot.
|
112
|
+
email:
|
113
|
+
- braiden-vasco@users.noreply.github.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".simplecov"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/lita-substitution.rb
|
130
|
+
- lib/lita/extensions/substitution.rb
|
131
|
+
- lib/lita/handlers/substitution.rb
|
132
|
+
- lita-substitution.gemspec
|
133
|
+
- locales/en.yml
|
134
|
+
- templates/.gitkeep
|
135
|
+
homepage: https://github.com/braiden-vasco/lita-substitution
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
lita_plugin_type: handler
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.8
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Shell-like command substitution for the Lita chat bot
|
160
|
+
test_files: []
|