cinch-evalso 0.1.4 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8f1987378c1c54c56c22215f76e4bce7b842b5d
4
- data.tar.gz: 6dcfb8e6307cf1de00adf4b36fbfec3b13168a2b
3
+ metadata.gz: 58d717d34c8cb462c7f0e3b197b3d2480c642e90
4
+ data.tar.gz: fd0f9b472c61a742802e3bb6bebe26c32b0025f9
5
5
  SHA512:
6
- metadata.gz: 4dd3df8d050a910ed728af3890c25a90aa7f4f58ce22459fd9c0398394c62d79adae90a1d584fceb9d3e9a21d6a3cce9c0bfa3da639200a5e415c6ed3b564f25
7
- data.tar.gz: 56d3a123e45a0c05971d4b237784c4bb4b18e3f4f5ddc9867041a1a9a23f93951aa095f3b00463e5212bee722b8309555c8fd8f75d737f45b06726fb98dbdb10
6
+ metadata.gz: f631dfc5750f477a69177fca8d72b336af1d0c1060a55d572e730d5d6dd5f44c773087d68d994db933e2f0f6764fbb69ca84e6a76b631600750b1ae4c1e818a6
7
+ data.tar.gz: eb41cce88b1c93a9323e5cdce982fd7bb882fe0129973cd2493fc46406d2e4bfae91e487b31586e8a939bec9b64cdfb9c225a3e9ed1c5a4f1b56fb1c3a20621b
@@ -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.1.4"
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 "httparty"
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
@@ -1,56 +1,50 @@
1
1
  require 'cinch'
2
- require 'httparty'
2
+ require 'evalso'
3
3
  require 'gist'
4
4
 
5
5
  module Cinch
6
- module Plugins
7
- class EvalSo
8
- include Cinch::Plugin, HTTParty
9
-
10
- base_uri 'eval.so'
11
- format :json
12
-
13
- match /eval ([\S]+) (.+)/, method: :eval
14
- match /langs/, method: :langs
15
-
16
- # Print out a list of languages
17
- # Params:
18
- # +m+:: +Cinch::Message+ object
19
- def langs(m)
20
- m.reply 'Available languages: ' + self.class.get('/api/languages').keys.join(', ')
21
- end
22
-
23
- # Evaluate code using the eval.so API
24
- # Params:
25
- # +m+:: +Cinch::Message+ object
26
- # +lang+:: The language for code to be evaluated with
27
- # +code+:: The code to be evaluated
28
- def eval(m, lang, code)
29
- options = { :body => {:language => lang, :code => code }.to_json, :headers => { 'Content-Type' => 'application/json' }}
30
- res = self.class.post('/api/evaluate', options)
31
- # Eval.so brought back an error, print it out and return
32
- if res.has_key? 'error'
33
- m.reply 'Error: ' + res['error'], true
34
- return
35
- end
36
-
37
- # Print stderr if stdout is empty
38
- if res['stdout'].empty?
39
- output = res['stderr']
40
- else
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.1.4
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-06-22 00:00:00.000000000 Z
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: httparty
29
+ name: evalso
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - '>='