lita-onewheel-aqi 1.2.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13823ee556bbd908e18efa0011f9d44e90c383e6
4
- data.tar.gz: e21fcd064eb874cda6684ee11135cf808525af38
3
+ metadata.gz: 0b1e16da0378b4492653b530898b80e4213d242e
4
+ data.tar.gz: bcaf8cfbdcc28de7dbdb47d4f4c8b45c35d43ba9
5
5
  SHA512:
6
- metadata.gz: 66f020d2df9500bbe13e528ff6ab7985416a81a8c28068934a591fa14d1f8e40c70ffb6626bd7236ad55946bf8f00dd6891d8a17a96095a204cf661ef40d5276
7
- data.tar.gz: 7dabe75aa72ab43f7848e365fbee2bc37069935073919d30657f19cde9fcd692dd1d3c05abee65c76795bae1453d7856aa6f887efdcf3fa69febf5a47ae1fb7a
6
+ metadata.gz: 113c8c581db65ce671dfe0b24f039b8f62a4d1ad5fcf1beabc16a0f06b0ab75599f7a774f0c885d02b9ff4590757cf4f366ddfbd8e4107aa85a2757dc1848a82
7
+ data.tar.gz: 3eedcc7a4d0ab8f4e42b39f801e88e558cc113735abb3a56012875907c6e4d1395fe008d40bd12667aa22d97206f724edd7b2b3a34fe85b3934276b17b318d1c
@@ -6,7 +6,7 @@ module Lita
6
6
  class OnewheelAqi < Handler
7
7
  config :api_key
8
8
  config :distance
9
- config :colors, default: true
9
+ config :mode, default: :irc
10
10
 
11
11
  route /^aqi\s+(.*)$/i,
12
12
  :get_aqi,
@@ -54,6 +54,24 @@ module Lita
54
54
  301..500 => :pink }
55
55
  end
56
56
 
57
+ def aqi_range_labels
58
+ { 0..50 => 'Good',
59
+ 51..100 => 'Moderate',
60
+ 101..150 => 'Unhealthy for Sensitive Groups',
61
+ 151..200 => 'Unhealthy for All',
62
+ 201..300 => 'Very Unhealthy',
63
+ 301..500 => 'Hazardous' }
64
+ end
65
+
66
+ def aqi_slack_emoji
67
+ { 0..50 => ':deciduous_tree:',
68
+ 51..100 => ':warning:',
69
+ 101..150 => ':large_orange_diamond:',
70
+ 151..200 => ':no_entry_sign:',
71
+ 201..300 => ':radioactive_sign:',
72
+ 301..500 => ':no_entry_sign: :radioactive_sign: :no_entry_sign:' }
73
+ end
74
+
57
75
  def get_location(response)
58
76
  location = if response.matches[0].to_s.casecmp('aqi').zero?
59
77
  ''
@@ -83,8 +101,16 @@ module Lita
83
101
  loc = get_location(response)
84
102
  aqi = get_observed_aqi(loc)
85
103
 
104
+ banner_str = "(#{aqi['data']['city']['url']})"
105
+
86
106
  reply = "AQI for #{loc[:name]}, "
87
107
 
108
+ if config.mode == :irc
109
+ reply += color_str_with_value(range_str: aqi_range_labels, range_value: aqi['data']['iaqi']['pm25']['v'].to_s)
110
+ banner_str = "\x03#{colors[:grey]}#{banner_str}\x03"
111
+ end
112
+
113
+
88
114
  if aqi['data']['iaqi']['pm10']
89
115
  reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
90
116
  end
@@ -92,9 +118,6 @@ module Lita
92
118
  reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
93
119
  end
94
120
 
95
- banner_str = "(#{aqi['data']['city']['url']})"
96
- banner_str = "\x03#{colors[:grey]}#{banner_str}\x03" if config.colors
97
-
98
121
  reply += banner_str
99
122
 
100
123
  response.reply reply
@@ -107,7 +130,10 @@ module Lita
107
130
  reply = "AQI for #{loc[:name]}, "
108
131
 
109
132
  banner_str = "(#{aqi['data']['city']['url']})"
110
- banner_str = "\x03#{colors[:grey]}#{banner_str}\x03" if config.colors
133
+
134
+ if config.mode == :irc
135
+ banner_str = "\x03#{colors[:grey]}#{banner_str}\x03"
136
+ end
111
137
 
112
138
  if aqi['data']['iaqi']['co']
113
139
  reply += 'co: ' + aqi['data']['iaqi']['co']['v'].to_s + ' '
@@ -132,10 +158,14 @@ module Lita
132
158
  response.reply reply
133
159
  end
134
160
 
135
- def color_str(str)
136
- if config.colors
161
+ def color_str(str, value = nil)
162
+ if config.mode == :irc
163
+ if value.nil?
164
+ value = str.to_i
165
+ end
166
+
137
167
  aqi_range_colors.keys.each do |color_key|
138
- if color_key.cover? str.to_i # Super secred cover sauce
168
+ if color_key.cover? value # Super secred cover sauce
139
169
  color = colors[aqi_range_colors[color_key]]
140
170
  str = "\x03#{color}#{str}\x03"
141
171
  end
@@ -145,6 +175,22 @@ module Lita
145
175
  str
146
176
  end
147
177
 
178
+ def color_str_with_value(range_str:, range_value:)
179
+ str = nil
180
+ aqi_range_colors.keys.each do |color_key|
181
+ if color_key.cover? range_value.to_i # Super secred cover sauce
182
+ color = colors[aqi_range_colors[color_key]]
183
+ if config.mode == :irc
184
+ str = "\x03#{color}#{range_str[color_key]}\x03 "
185
+ elsif config.mode == :slack
186
+ str = "#{range_str[color_key]} "
187
+ end
188
+ end
189
+ end
190
+
191
+ str
192
+ end
193
+
148
194
  def extract_pmtwofive(aqi)
149
195
  Lita.logger.debug "extract_pmtwofive with #{aqi}"
150
196
  pm25 = ''
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-aqi'
3
- spec.version = '1.2.0'
3
+ spec.version = '2.0.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'AQI data retrieval bot'
@@ -31,11 +31,11 @@ describe Lita::Handlers::OnewheelAqi, lita_handler: true do
31
31
 
32
32
  it 'queries the aqi' do
33
33
  send_command 'aqi'
34
- expect(replies.last).to include("AQI for Portland, OR, USA, pm10: \u00030340\u0003 pm25: \u00030876\u0003 \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
34
+ expect(replies.last).to include("AQI for Portland, OR, USA, \u000308Moderate\u0003 pm10: \u00030340\u0003 pm25: \u00030876\u0003 \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
35
35
  end
36
36
 
37
37
  it 'queries the aqideets' do
38
38
  send_command 'aqideets'
39
- expect(replies.last).to eq("AQI for Portland, OR, USA, humidity: 11% pressure: 1014mb pm10: \u00030340\u0003 pm25: \u00030876\u0003 temp: 34.65C \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
39
+ expect(replies.last).to eq("AQI for Portland, OR, USA, \u00030Moderate\u0003 humidity: 11% pressure: 1014mb pm10: \u00030340\u0003 pm25: \u00030876\u0003 temp: 34.65C \u000314(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)\u0003")
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-aqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita