-
Notifications
You must be signed in to change notification settings - Fork 4
/
hops.rb
55 lines (43 loc) · 1.43 KB
/
hops.rb
1
2
3
4
5
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/local/bin/ruby
require 'rubygems'
require 'cinch'
require 'open-uri'
require 'uri'
class Hops
include Cinch::Plugin
@help="!hops"
match /hops (.+)/
def initialize(*args)
super
end
def execute(m,hops)
if (hops != ' ')
params = {
'name' => hops
}
uri = URI.parse("http://www.brewerwall.com/api/v1/hops")
response = Net::HTTP.post_form(uri,params)
results = JSON.load(response.body)
if (results.empty?)
m.reply "Sorry #{m.user.nick}, no hops were found matching \"#{hops}\"."
elsif (results.count == 1)
results.each do |result|
m.reply "#{result["name"]} - Origin: #{result["origin"]}; Alpha Acid: #{result["alpha_min"]}-#{result["alpha_max"]}; Aroma: #{result["aroma"]}; Styles: #{result["styles"]}"
end
elsif (results.count == 2 && results[0]['name'] == results[1]['name'])
results.each do |result|
m.reply "#{result["name"]} - Origin: #{result["origin"]}; Alpha Acid: #{result["alpha_min"]}-#{result["alpha_max"]}; Aroma: #{result["aroma"]}; Styles: #{result["styles"]}"
end
else
hop = Array.new
hops = results.take(10)
hop_count = hops.count
hops.each do |result|
hop.push("#{result["name"]}")
end
m.reply "#{m.user.nick} there are multiple options, here are #{hop_count} to choose from."
m.reply hop.join('; ')
end
end
end
end