bender-bot 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/bender/bot.rb +98 -48
  4. data/lib/bender/main.rb +5 -0
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c904bf4fffeb3fb524f8bc858333f55b68c392bd
4
- data.tar.gz: 6d4922056ee46b059df24443f58e6c0854b205d4
3
+ metadata.gz: 8f6f1ca66046526eee7288deb9ea283f59587a76
4
+ data.tar.gz: b7e9e5364f81483b33dd28f00146f261d0a2baf3
5
5
  SHA512:
6
- metadata.gz: c2bd478c276ae7f8fd8fc4b5043bc573099b231e29d0f5bb5c19ac022ebdcb8ff5479cd7fa50c224ae5047d684b0f2114c68fa590f72ddedc19d132b0f2a3d21
7
- data.tar.gz: 4e1eec1961147d432177b5eb5ee291fa32c0c4269b77f849fae920ebadcdddaef1e5d9db524867a322c4787381da18e8a696dd882002fefe0c1feb28cd22c665
6
+ metadata.gz: 94ab57468d52086d5602f01e60ef857d0c79a572e332d3090e395f7c39da331e25abed459a6608c913e245c0cfe53d3e3fbf454c9183946342737181fe53a502
7
+ data.tar.gz: e138fb69f727b8e64eeb42928e1edb7bec532c314443a8d6dfb43737419ef78b7e4c82c882abc0959b51f9dab50b4fd50a9a50ae8ca98a91888805ac9066490b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -3,6 +3,7 @@ require 'date'
3
3
  require 'time'
4
4
 
5
5
  require 'robut'
6
+ require 'hipchat'
6
7
  require 'robut/storage/yaml_store'
7
8
  require 'fuzzystringmatch'
8
9
  require 'queryparams'
@@ -13,6 +14,9 @@ Bot = Robut # alias
13
14
 
14
15
  module Bot
15
16
  def self.run! options
17
+ hipchat = HipChat::Client.new(options.hipchat_token)
18
+ BenderBot.class_variable_set :@@hipchat, hipchat
19
+ BenderBot.class_variable_set :@@rooms, hipchat.rooms
16
20
  BenderBot.class_variable_set :@@options, options
17
21
  Bot::Plugin.plugins = [ BenderBot ]
18
22
  conn = Bot::Connection.new
@@ -55,35 +59,65 @@ class BenderBot
55
59
  }
56
60
 
57
61
 
58
- def handle time, sender, message
62
+ QUOTES = [
63
+ 'Bite my shiny metal ass!',
64
+ 'This is the worst kind of discrimination there is: the kind against me!',
65
+ 'I guess if you want children beaten, you have to do it yourself.',
66
+ "Hahahahaha! Oh wait you're serious. Let me laugh even harder.",
67
+ "You know what cheers me up? Other people's misfortune.",
68
+ 'Anything less than immortality is a complete waste of time.',
69
+ "Blackmail is such an ugly word. I prefer extortion. The 'x' makes it sound cool.",
70
+ 'Have you tried turning off the TV, sitting down with your children, and hitting them?',
71
+ "You're a pimple on society’s ass and you'll never amount to anything!",
72
+ 'Shut up baby, I know it!',
73
+ "I'm so embarrassed. I wish everyone else was dead!",
74
+ "Afterlife? If I thought I had to live another life, I'd kill myself right now!",
75
+ "I'm back baby!",
76
+ "LET'S GO ALREADYYYYYY!"
77
+ ]
78
+
79
+
80
+ def reply_html message, color=:yellow
81
+ @@hipchat[@room_name].send(nick, message, color: color)
82
+ end
83
+
84
+
85
+ def handle room, sender, message
86
+ @room_name = @@rooms.select { |r| r.xmpp_jid == room }.first.name
87
+ @room = room
88
+ @sender = sender
89
+ @message = message
90
+
59
91
  severity_field = SHOW_FIELDS.key 'Severity'
60
92
  severities = Hash.new { |h,k| h[k] = [] }
61
93
 
62
- case message
63
94
 
95
+ case message
64
96
 
65
- when /^\s*\?opts\s*$/
66
- reply options.inspect
97
+ when /^\s*\/bender\s*$/
98
+ reply_html QUOTES.sample(1).first, :red
67
99
 
68
- when /^\s*\?whoami\s*$/
100
+ when /^\s*\/whoami\s*$/
69
101
  u = user_where name: sender
70
- reply '%s: %s (%s)' % [ u[:nick], u[:name], u[:email] ]
102
+ m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
103
+ reply_html m, :purple
71
104
 
72
- when /^\s*\?lookup\s+(.+)\s*$/
105
+ when /^\s*\/lookup\s+(.+)\s*$/
73
106
  u = user_where(name: $1) || user_where(nick: $1)
74
- reply '%s: %s (%s)' % [ u[:nick], u[:name], u[:email] ]
107
+ m = '<b>%{nick}</b>: %{name} (<a href="mailto:%{email}">%{email}</a>)' % u
108
+ reply_html m, :purple
75
109
 
76
110
  # ?inc - This help text
77
111
  when /^\s*\?inc\s*$/
78
- reply [
79
- '?inc - Display this help text',
80
- '/inc - List open incidents',
81
- '/inc [INCIDENT_NUMBER] - Display incident details',
82
- '/inc close [INCIDENT_NUMBER] - Close an incident',
83
- '/inc open [SEVERITY=1,2,3,4,5] [SUMMARY_TEXT] - Open a new incident',
84
- '/inc summary - Summarize incidents from past 24 hours (open or closed)',
85
- '/inc comment [INCIDENT_NUMBER] [COMMENT_TEXT] - Add a comment to an incident'
86
- ].join("\n")
112
+ reply_html [
113
+ '<code>?inc</code> - Display this help text',
114
+ '<code>/inc</code> - List open incidents',
115
+ '<code>/inc <i>INCIDENT_NUMBER</i></code> - Display incident details',
116
+ '<code>/inc close <i>INCIDENT_NUMBER</i></code> - Close an incident',
117
+ '<code>/inc open <i>SEVERITY=1,2,3,4,5</i> <i>SUMMARY_TEXT</i></code> - Open a new incident',
118
+ '<code>/inc summary</code> - Summarize incidents from past 24 hours (open or closed)',
119
+ '<code>/inc comment <i>INCIDENT_NUMBER</i> <i>COMMENT_TEXT</i></code> - Add a comment to an incident'
120
+ ].join('<br />')
87
121
 
88
122
  # /inc - List open incidents
89
123
  when /^\s*\/inc\s*$/
@@ -92,20 +126,21 @@ class BenderBot
92
126
  is = store['incidents'].reverse.map do |i|
93
127
  status = normalize_value i['fields']['status']
94
128
  unless status =~ /done|complete|closed/i
95
- '%s-%s (%s - %s) [%s]: %s' % [
96
- options.jira_project,
97
- i['num'],
129
+ '%s (%s - %s) [%s]: %s' % [
130
+ incident_link(i),
98
131
  short_severity(i['fields'][severity_field]['value']),
99
132
  normalize_value(i['fields']['status']),
100
133
  friendly_date(i['fields']['created']),
101
134
  i['fields']['summary']
102
135
  ]
103
136
  end
104
- end.compact.join("\n")
105
-
106
- is = 'No open incidents at the moment!' if is.empty?
137
+ end.compact.join('<br />')
107
138
 
108
- reply is
139
+ if is.empty?
140
+ reply_html 'No open incidents at the moment!', :green
141
+ else
142
+ reply_html is
143
+ end
109
144
 
110
145
  # /inc summary - Summarize recent incidents
111
146
  when /^\s*\/inc\s+summary\s*$/
@@ -117,9 +152,8 @@ class BenderBot
117
152
  if recent_incident? i
118
153
  status = normalize_value(i['fields']['status'])
119
154
 
120
- repr = '%s-%s (%s) [%s]: %s' % [
121
- options.jira_project,
122
- i['num'],
155
+ repr = '%s (%s) [%s]: %s' % [
156
+ incident_link(i),
123
157
  status,
124
158
  friendly_date(i['fields']['created']),
125
159
  i['fields']['summary']
@@ -146,14 +180,14 @@ class BenderBot
146
180
  end
147
181
 
148
182
  if severities.empty?
149
- reply 'No recent incidents! Woohoo!'
183
+ reply_html 'No recent incidents! Woohoo!', :green
150
184
 
151
185
  else
152
186
  is = severities.keys.sort.map do |sev|
153
- "%s:\n%s" % [ sev, severities[sev].join("\n") ]
154
- end.join("\n\n")
187
+ "%s:<br />%s" % [ sev, severities[sev].join("<br />") ]
188
+ end.join("<br /><br />")
155
189
 
156
- reply(summary.join("\n") + "\n\n" + is)
190
+ reply_html(summary.join("<br />") + "<br /><br />" + is)
157
191
  end
158
192
 
159
193
 
@@ -162,7 +196,7 @@ class BenderBot
162
196
  incident = select_incident $1
163
197
 
164
198
  if incident.nil?
165
- reply 'Sorry, no such incident!'
199
+ reply_html 'Sorry, no such incident!', :red
166
200
  else
167
201
  fields = SHOW_FIELDS.keys - %w[ summary ]
168
202
 
@@ -175,11 +209,10 @@ class BenderBot
175
209
  end
176
210
  end.compact
177
211
 
178
- reply "%s\n%s: %s\n%s" % [
179
- (options.jira_site + '/browse/' + incident['key']),
180
- incident['key'],
212
+ reply_html "%s - %s<br />%s" % [
213
+ incident_link(incident),
181
214
  incident['fields']['summary'],
182
- i.join("\n")
215
+ i.join("<br />")
183
216
  ]
184
217
  end
185
218
 
@@ -187,9 +220,9 @@ class BenderBot
187
220
  when /^\s*\/inc\s+close\s+(\d+)\s*$/
188
221
  incident = select_incident $1
189
222
  if incident
190
- reply close_incident(incident)
223
+ reply_html close_incident(incident), :green
191
224
  else
192
- reply 'Sorry, no such incident!'
225
+ reply_html 'Sorry, no such incident!', :red
193
226
  end
194
227
 
195
228
  # /inc open SEVERITY SUMMARY - File a new incident
@@ -207,7 +240,7 @@ class BenderBot
207
240
  }
208
241
  }
209
242
 
210
- reply file_incident(data)
243
+ reply_html *file_incident(data)
211
244
 
212
245
 
213
246
  # /inc comment [INCIDENT_NUMBER] [COMMENT_TEXT]
@@ -216,7 +249,11 @@ class BenderBot
216
249
  comment = $2
217
250
  user = user_where name: sender
218
251
 
219
- reply comment_on_incident(incident, comment, user)
252
+ if incident
253
+ reply_html *comment_on_incident(incident, comment, user)
254
+ else
255
+ reply_html 'Sorry, no such incident!', :red
256
+ end
220
257
  end
221
258
 
222
259
  return true
@@ -289,9 +326,9 @@ private
289
326
  issue = JSON.parse(resp.body)
290
327
 
291
328
  if issue.has_key? 'key'
292
- options.jira_site + '/browse/' + issue['key']
329
+ [ 'Filed ' + incident_link(issue), :green ]
293
330
  else
294
- "Sorry, I couldn't file that!"
331
+ [ "Sorry, I couldn't file that!", :red ]
295
332
  end
296
333
  end
297
334
 
@@ -319,12 +356,12 @@ private
319
356
  status = normalize_value incident['fields']['status']
320
357
 
321
358
  if status =~ CLOSE_STATE
322
- 'Closed: ' + options.jira_site + '/browse/' + incident['key']
359
+ 'Closed ' + incident_link(incident)
323
360
  else
324
361
  [
325
362
  'Failed to close automatically, you might try yourself',
326
363
  (options.jira_site + '/browse/' + incident['key'])
327
- ].join("\n")
364
+ ].join("<br />")
328
365
  end
329
366
  end
330
367
 
@@ -342,12 +379,12 @@ private
342
379
 
343
380
  case http.request(req)
344
381
  when Net::HTTPCreated
345
- 'Added: ' + options.jira_site + '/browse/' + incident['key']
382
+ [ 'Added comment to ' + incident_link(incident), :green ]
346
383
  else
347
384
  [
348
- 'Sorry, I had trouble adding your comment',
349
- (options.jira_site + '/browse/' + incident['key'])
350
- ].join("\n")
385
+ 'Sorry, I had trouble adding your comment on' + incident_link(incident),
386
+ :red
387
+ ]
351
388
  end
352
389
  end
353
390
 
@@ -397,4 +434,17 @@ private
397
434
  s.split(' - ', 2).first
398
435
  end
399
436
 
437
+
438
+ def incident_url incident
439
+ options.jira_site + '/browse/' + incident['key']
440
+ end
441
+
442
+ def incident_link incident
443
+ '<a href="%s">%s-%s</a>' % [
444
+ incident_url(incident),
445
+ options.jira_project,
446
+ incident['num']
447
+ ]
448
+ end
449
+
400
450
  end
@@ -42,6 +42,11 @@ module Bender
42
42
  aliases: %w[ -e ],
43
43
  desc: 'Set Sinatra environment',
44
44
  default: 'development'
45
+ option :hipchat_token, \
46
+ type: :string,
47
+ aliases: %w[ -t ],
48
+ desc: 'Set HipChat v1 API token',
49
+ required: true
45
50
  option :jid, \
46
51
  type: :string,
47
52
  aliases: %w[ -j ],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bender-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.2
61
+ version: 0.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.5.2
68
+ version: 0.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hipchat
71
71
  requirement: !ruby/object:Gem::Requirement