cinch-evalso 0.1.4 → 0.2
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/cinch-evalso.gemspec +23 -23
- data/lib/cinch/plugins/evalso.rb +43 -49
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58d717d34c8cb462c7f0e3b197b3d2480c642e90
|
4
|
+
data.tar.gz: fd0f9b472c61a742802e3bb6bebe26c32b0025f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f631dfc5750f477a69177fca8d72b336af1d0c1060a55d572e730d5d6dd5f44c773087d68d994db933e2f0f6764fbb69ca84e6a76b631600750b1ae4c1e818a6
|
7
|
+
data.tar.gz: eb41cce88b1c93a9323e5cdce982fd7bb882fe0129973cd2493fc46406d2e4bfae91e487b31586e8a939bec9b64cdfb9c225a3e9ed1c5a4f1b56fb1c3a20621b
|
data/cinch-evalso.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "cinch-evalso"
|
7
|
-
spec.version = "0.
|
8
|
-
spec.authors = ["Serguey Parkhomovsky"]
|
9
|
-
spec.email = ["xindigo@gmail.com"]
|
10
|
-
spec.homepage = "https://github.com/sparkhom/cinch-evalso"
|
11
|
-
spec.description = %q{Cinch plugin to evaluate code with different languages using the eval.so API}
|
12
|
-
spec.summary = %q{Cinch plugin to query the eval.so API}
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files`.split($/)
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = ["lib"]
|
19
|
-
|
20
|
-
spec.add_dependency "cinch"
|
21
|
-
spec.add_dependency "
|
22
|
-
spec.add_dependency "gist"
|
23
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cinch-evalso"
|
7
|
+
spec.version = "0.2"
|
8
|
+
spec.authors = ["Serguey Parkhomovsky", "Nick Markwell"]
|
9
|
+
spec.email = ["xindigo@gmail.com"]
|
10
|
+
spec.homepage = "https://github.com/sparkhom/cinch-evalso"
|
11
|
+
spec.description = %q{Cinch plugin to evaluate code with different languages using the eval.so API}
|
12
|
+
spec.summary = %q{Cinch plugin to query the eval.so API}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "cinch"
|
21
|
+
spec.add_dependency "evalso"
|
22
|
+
spec.add_dependency "gist"
|
23
|
+
end
|
data/lib/cinch/plugins/evalso.rb
CHANGED
@@ -1,56 +1,50 @@
|
|
1
1
|
require 'cinch'
|
2
|
-
require '
|
2
|
+
require 'evalso'
|
3
3
|
require 'gist'
|
4
4
|
|
5
5
|
module Cinch
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
output = res['stdout']
|
42
|
-
end
|
43
|
-
|
44
|
-
output = output.gsub(/\n/,' ')
|
45
|
-
|
46
|
-
# According to RFC 2812, the maximum line length on IRC is 510 characters, minus the carriage return
|
47
|
-
# In order to not spam the channel, if the output is greater than one line, convert it to a gist
|
48
|
-
if output.length > 510
|
49
|
-
m.reply Gist.gist(output, filename: 'result', description: code)['html_url'], true
|
50
|
-
else
|
51
|
-
m.reply output, true
|
52
|
-
end
|
53
|
-
end
|
6
|
+
module Plugins
|
7
|
+
class EvalSo
|
8
|
+
include Cinch::Plugin
|
9
|
+
|
10
|
+
match /eval ([\S]+) (.+)/, method: :eval
|
11
|
+
match /langs/, method: :langs
|
12
|
+
|
13
|
+
# Print out a list of languages
|
14
|
+
# Params:
|
15
|
+
# +m+:: +Cinch::Message+ object
|
16
|
+
def langs(m)
|
17
|
+
m.safe_reply "Available languages: #{Evalso.languages.keys.join(', ')}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Evaluate code using the eval.so API
|
21
|
+
# Params:
|
22
|
+
# +m+:: +Cinch::Message+ object
|
23
|
+
# +lang+:: The language for code to be evaluated with
|
24
|
+
# +code+:: The code to be evaluated
|
25
|
+
def eval(m, lang, code)
|
26
|
+
res = Evalso.run(language: lang, code: code)
|
27
|
+
|
28
|
+
# Default to stdout, fall back to stderr.
|
29
|
+
output = res.stdout
|
30
|
+
output = res.stderr if output.empty?
|
31
|
+
|
32
|
+
output = output.gsub(/\n/,' ')
|
33
|
+
|
34
|
+
# According to RFC 2812, the maximum command length on IRC is 512 characters.
|
35
|
+
# This makes our maximum message length 512 - '\r\n'.length - the header information
|
36
|
+
# In order to not spam the channel, if the output is greater than one line, convert it to a gist
|
37
|
+
maxlength = 510 - (":" + " PRIVMSG " + " :").length - @bot.mask.to_s.length - m.target.name.length
|
38
|
+
maxlength = maxlength - ("#{m.user.name}: ").length if m.target.is_a? Channel
|
39
|
+
if output.length > maxlength
|
40
|
+
output = Gist.gist(output, filename: 'result', description: code)['html_url']
|
54
41
|
end
|
42
|
+
|
43
|
+
m.safe_reply output, true
|
44
|
+
rescue Evalso::HTTPError => e
|
45
|
+
# Eval.so returned an error, pass it on to IRC.
|
46
|
+
m.safe_reply "Error: #{e.message}", true
|
47
|
+
end
|
55
48
|
end
|
49
|
+
end
|
56
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-evalso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serguey Parkhomovsky
|
8
|
+
- Nick Markwell
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: cinch
|
@@ -25,7 +26,7 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: evalso
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - '>='
|